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/exception.hxx>
4#include <StormByte/expected.hxx>
5#include <StormByte/visibility.h>
6
7#include <algorithm>
8#include <cstddef>
9#include <cmath>
10#include <iomanip>
11#include <locale>
12#include <queue>
13#include <sstream>
14#include <string>
15#include <utility>
16#include <vector>
17
25namespace StormByte::String {
32 enum class STORMBYTE_PUBLIC Format : unsigned short {
33 Raw,
34 HumanReadableNumber,
35 HumanReadableBytes
36 };
37
47 constexpr STORMBYTE_PUBLIC std::string Indent(const int& level) noexcept {
48 return level == 0 ? std::string() : std::string(level, '\t');
49 }
50
59 constexpr STORMBYTE_PUBLIC bool IsNumeric(const std::string& str) noexcept {
60 return !str.empty() && std::all_of(str.begin(), str.end(), ::isdigit);
61 }
62
71 STORMBYTE_PUBLIC std::string ToLower(const std::string& str) noexcept;
72
81 STORMBYTE_PUBLIC std::string ToUpper(const std::string& str) noexcept;
82
93 STORMBYTE_PUBLIC std::queue<std::string> Explode(const std::string& str, const char delimiter);
94
104 STORMBYTE_PUBLIC std::vector<std::string> Split(const std::string& str);
105
116 STORMBYTE_PUBLIC StormByte::Expected<std::pair<int, int>, Exception> SplitFraction(const std::string& fraction);
117
129 STORMBYTE_PUBLIC StormByte::Expected<std::pair<int, int>, Exception> SplitFraction(const std::string& str, const int& denominator);
130
143 template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T> && !std::is_same_v<T, wchar_t>>>
144 STORMBYTE_PUBLIC std::string HumanReadable(const T& number, const Format& format, const std::string& locale = "en_US.UTF-8") noexcept;
145
155 STORMBYTE_PUBLIC std::string UTF8Encode(const std::wstring& ws);
156
166 STORMBYTE_PUBLIC std::wstring UTF8Decode(const std::string& s);
167
176 STORMBYTE_PUBLIC std::string SanitizeNewlines(const std::string& str) noexcept;
177
186 STORMBYTE_PUBLIC std::string FromByteVector(const std::vector<std::byte>& byte_vector) noexcept;
187
196 STORMBYTE_PUBLIC std::vector<std::byte> ToByteVector(const std::string& str) noexcept;
197
206 STORMBYTE_PUBLIC std::string RemoveWhitespace(const std::string& str) noexcept;
207}
std::conditional_t< Type::Reference< T >, 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:33