StormByte C++ Library 1.2.0
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
Enumerations | Functions
StormByte::String Namespace Reference

String helpers (case, split, UTF-8, human-readable numbers). More...

Enumerations

enum class  Format : unsigned short { Raw , HumanReadableNumber , HumanReadableBytes }
 How HumanReadable prints a number. More...
 

Functions

constexpr std::string Indent (const int &level) noexcept
 level tab characters, or empty when level == 0.
 
constexpr bool IsNumeric (std::string_view str) noexcept
 true when every character is a decimal digit (std::isdigit).
 
std::string ToLower (std::string_view str) noexcept
 Lowercase copy of str.
 
std::string ToUpper (std::string_view str) noexcept
 Uppercase copy of str.
 
std::queue< std::string > Explode (std::string_view str, const char delimiter)
 Splits on delimiter into a queue (empty tokens kept).
 
std::vector< std::string > Split (std::string_view str)
 Splits on ASCII whitespace into a vector.
 
template<typename T , typename = std::enable_if_t<std::is_arithmetic_v<T> && !std::is_same_v<T, wchar_t>>>
std::string HumanReadable (const T &number, const Format &format, const std::string &locale="en_US.UTF-8") noexcept
 Formats an arithmetic value (not wchar_t).
 
std::string UTF8Encode (std::wstring_view ws)
 Wide text to UTF-8.
 
std::wstring UTF8Decode (std::string_view s)
 UTF-8 text to wide string.
 
std::string SanitizeNewlines (std::string_view str) noexcept
 Normalizes \r\n to \n.
 
std::string FromByteVector (const std::vector< std::byte > &byte_vector) noexcept
 Interprets bytes as char and builds a string.
 
std::vector< std::byte > ToByteVector (std::string_view str) noexcept
 Copies text bytes into a vector<std::byte>.
 
std::string RemoveWhitespace (std::string_view str) noexcept
 Strips every whitespace character.
 
bool IsInteger (std::string_view str) noexcept
 true when str parses as an integer (optional leading +/-).
 

Detailed Description

String helpers (case, split, UTF-8, human-readable numbers).

Read-only inputs are std::string_view / std::wstring_view. std::string, std::wstring and string literals convert to those views.

Enumeration Type Documentation

◆ Format

enum class StormByte::String::Format : unsigned short
strong

How HumanReadable prints a number.

Enumerator
Raw 

Unscaled decimal.

HumanReadableNumber 

Grouped / locale number.

HumanReadableBytes 

Byte units (KiB, MiB, …).

Function Documentation

◆ Explode()

std::queue< std::string > StormByte::String::Explode ( std::string_view  str,
const char  delimiter 
)

Splits on delimiter into a queue (empty tokens kept).

Parameters
strInput text.
delimiterSeparator.

◆ FromByteVector()

std::string StormByte::String::FromByteVector ( const std::vector< std::byte > &  byte_vector)
noexcept

Interprets bytes as char and builds a string.

Parameters
byte_vectorInput bytes.

◆ HumanReadable()

template<typename T , typename = std::enable_if_t<std::is_arithmetic_v<T> && !std::is_same_v<T, wchar_t>>>
std::string StormByte::String::HumanReadable ( const T &  number,
const Format format,
const std::string &  locale = "en_US.UTF-8" 
)
noexcept

Formats an arithmetic value (not wchar_t).

Template Parameters
TArithmetic type.
Parameters
numberValue.
formatRaw, HumanReadableNumber or HumanReadableBytes.
localeLocale name, default "en_US.UTF-8".

◆ Indent()

constexpr std::string StormByte::String::Indent ( const int &  level)
constexprnoexcept

level tab characters, or empty when level == 0.

Parameters
levelIndentation depth.

◆ IsInteger()

bool StormByte::String::IsInteger ( std::string_view  str)
noexcept

true when str parses as an integer (optional leading +/-).

Parameters
strInput text.

◆ IsNumeric()

constexpr bool StormByte::String::IsNumeric ( std::string_view  str)
constexprnoexcept

true when every character is a decimal digit (std::isdigit).

Parameters
strText to test.
Note
Empty text is not numeric.

◆ RemoveWhitespace()

std::string StormByte::String::RemoveWhitespace ( std::string_view  str)
noexcept

Strips every whitespace character.

Parameters
strInput text.

◆ SanitizeNewlines()

std::string StormByte::String::SanitizeNewlines ( std::string_view  str)
noexcept

Normalizes \r\n to \n.

Lone \r is kept.

Parameters
strInput text.

◆ Split()

std::vector< std::string > StormByte::String::Split ( std::string_view  str)

Splits on ASCII whitespace into a vector.

Parameters
strInput text.

◆ ToByteVector()

std::vector< std::byte > StormByte::String::ToByteVector ( std::string_view  str)
noexcept

Copies text bytes into a vector<std::byte>.

Parameters
strInput text.

◆ ToLower()

std::string StormByte::String::ToLower ( std::string_view  str)
noexcept

Lowercase copy of str.

Parameters
strInput text.
Returns
New string; input is not modified.

◆ ToUpper()

std::string StormByte::String::ToUpper ( std::string_view  str)
noexcept

Uppercase copy of str.

Parameters
strInput text.
Returns
New string; input is not modified.

◆ UTF8Decode()

std::wstring StormByte::String::UTF8Decode ( std::string_view  s)

UTF-8 text to wide string.

Parameters
sUTF-8 input.
Exceptions
StormByte::UTF8ErrorOn invalid Unicode input.

◆ UTF8Encode()

std::string StormByte::String::UTF8Encode ( std::wstring_view  ws)

Wide text to UTF-8.

Parameters
wsWide input.
Exceptions
StormByte::UTF8ErrorOn invalid Unicode input.