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/buffer/simple.hxx>
4
5#include <algorithm>
6#include <cstdint>
7#include <cmath>
8#include <iomanip>
9#include <locale>
10#include <queue>
11#include <sstream>
12#include <string>
13#include <utility>
14#include <vector>
15
23namespace StormByte::String {
30 enum class STORMBYTE_PUBLIC Format : unsigned short {
31 Raw,
32 HumanReadableNumber,
33 HumanReadableBytes
34 };
35
45 constexpr STORMBYTE_PUBLIC std::string Indent(const int& level) noexcept {
46 return level == 0 ? std::string() : std::string(level, '\t');
47 }
48
57 constexpr STORMBYTE_PUBLIC bool IsNumeric(const std::string& str) noexcept {
58 return !str.empty() && std::all_of(str.begin(), str.end(), ::isdigit);
59 }
60
69 STORMBYTE_PUBLIC std::string ToLower(const std::string& str) noexcept;
70
79 STORMBYTE_PUBLIC std::string ToUpper(const std::string& str) noexcept;
80
91 STORMBYTE_PUBLIC std::queue<std::string> Explode(const std::string& str, const char delimiter);
92
102 STORMBYTE_PUBLIC std::vector<std::string> Split(const std::string& str);
103
114 STORMBYTE_PUBLIC StormByte::Expected<std::pair<int, int>, Exception> SplitFraction(const std::string& fraction);
115
127 STORMBYTE_PUBLIC StormByte::Expected<std::pair<int, int>, Exception> SplitFraction(const std::string& str, const int& denominator);
128
141 template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T> && !std::is_same_v<T, wchar_t>>>
142 STORMBYTE_PUBLIC std::string HumanReadable(const T& number, const Format& format, const std::string& locale = "en_US.UTF-8") noexcept;
143
153 STORMBYTE_PUBLIC std::string UTF8Encode(const std::wstring& ws);
154
164 STORMBYTE_PUBLIC std::wstring UTF8Decode(const std::string& s);
165
174 STORMBYTE_PUBLIC std::string SanitizeNewlines(const std::string& str) noexcept;
175
184 STORMBYTE_PUBLIC std::string FromBuffer(const Buffer::Simple& buffer) noexcept;
185
194 STORMBYTE_PUBLIC std::string FromBuffer(const Buffer::Data& data) noexcept;
195
204 STORMBYTE_PUBLIC std::string FromBuffer(const std::span<const std::byte>& span) noexcept;
205}
The class to serialize and deserialize data.
Definition serializable.hxx:25
Namespace for buffer-related components in the StormByte library.