StormByte C++ Library 0.0.9999
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
Loading...
Searching...
No Matches
string.hxx
1#pragma once
2
3#include <StormByte/expected.hxx>
4#include <StormByte/exception.hxx>
5
6#include <algorithm>
7#include <cstdint>
8#include <cmath>
9#include <iomanip>
10#include <locale>
11#include <queue>
12#include <sstream>
13#include <string>
14#include <utility>
15#include <vector>
16
24namespace StormByte::String {
31 enum class STORMBYTE_PUBLIC Format : unsigned short {
32 Raw,
33 HumanReadableNumber,
34 HumanReadableBytes
35 };
36
42 constexpr STORMBYTE_PUBLIC std::string Indent(const int& level) noexcept {
43 return level == 0 ? std::string() : std::string(level, '\t');
44 }
45
51 constexpr STORMBYTE_PUBLIC bool IsNumeric(const std::string& str) noexcept {
52 return !str.empty() && std::all_of(str.begin(), str.end(), ::isdigit);
53 }
54
60 STORMBYTE_PUBLIC std::string ToLower(const std::string& str) noexcept;
61
67 STORMBYTE_PUBLIC std::string ToUpper(const std::string& str) noexcept;
68
75 STORMBYTE_PUBLIC std::queue<std::string> Explode(const std::string& str, const char delimiter);
76
82 STORMBYTE_PUBLIC std::vector<std::string> Split(const std::string& str);
83
89 STORMBYTE_PUBLIC StormByte::Expected<std::pair<int, int>, Exception> SplitFraction(const std::string& fraction);
90
97 STORMBYTE_PUBLIC StormByte::Expected<std::pair<int, int>, Exception> SplitFraction(const std::string& str, const int& denominator);
98
99 // Main HumanReadable template function
100 template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T> && !std::is_same_v<T, wchar_t>>>
101 STORMBYTE_PUBLIC std::string HumanReadable(const T& number, const Format& format, const std::string& locale = "en_US.UTF-8") noexcept;
102
109 STORMBYTE_PUBLIC std::string UTF8Encode(const std::wstring& ws);
110
117 STORMBYTE_PUBLIC std::wstring UTF8Decode(const std::string& s);
118
124 STORMBYTE_PUBLIC std::string SanitizeNewlines(const std::string& str) noexcept;
125}
std::conditional_t< is_reference< T >::value, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, std::shared_ptr< E > >, std::expected< T, std::shared_ptr< E > > > Expected
Expected type with support for reference types.
Definition expected.hxx:32