Overview / Foundation

string

In-house ASCII and wide strings with small-string optimization (up to 64 characters), plus comparison and formatting functions.

Always compiled: part of the core build.Include #include <ethereal/cpp/string/string_inc.hpp>C layer

string_inc.hpp

#include <ethereal/cpp/string/string_inc.hpp>

ascii.hpp

#include <ethereal/cpp/string/ascii.hpp>
class

CAString

Ethereal::String#

Internal Ascii string class.

class CAString final

It is not guaranteed to be thread-safe. Synchronization is the responsibility of its caller. It must not be inherited directly by any structure, class or object.

alias

size_type

#
using size_type = std::size_t;

Base variable type for size calculations, size_t for better performance in x64 builds.

const

SSO_MaxSize

#
static constexpr size_type SSO_MaxSize = 64;

Maximum size of the SSO (Small String Optimization) string.

constructor

CAString

#
CAString() noexcept;

Default constructor.

constructor

CAString

#
CAString( const char * Str ) noexcept;

'Direct initialization' constructor.

constructor

CAString

#
CAString( const CAString & other ) noexcept;

'Copy by reference' constructor.

constructor

CAString

#
CAString( CAString && other ) noexcept;

Move constructor.

constructor

CAString

#
CAString( const std::string & Str ) noexcept;

'Direct initialization' constructor for the std::string format.

constructor

CAString

#
CAString( std::string && Str ) noexcept;

'Move' constructor for the std::string format.

operator

operator=

#
CAString & operator=( const char * other );

Raw copy assignment operator.

operator

operator=

#
CAString & operator=( const CAString & other );

Copy assignment operator.

operator

operator=

#
CAString & operator=( CAString && other ) noexcept;

Move assignment operator.

operator

operator[]

#
char operator[]( size_type idx ) const;

Const subscript operator.

operator

operator+

#
[[nodiscard]] CAString operator+( const CAString & other ) const;

Concatenation operator. Returns a new string and leaves this one unchanged. Use operator+= to append.

operator

operator+

#
[[nodiscard]] CAString operator+( const char * other ) const;

Concatenation operator (Raw). Returns a new string and leaves this one unchanged.

operator

operator+=

#
CAString & operator+=( const CAString & other );

Appends another string to this one.

operator

operator+=

#
CAString & operator+=( const char * other );

Appends a character array to this string (Raw).

operator

operator<=>

#
auto operator<=>( const CAString & other ) const;

Three-way comparison operator (spaceship).

operator

operator==

#
bool operator==( const CAString & other ) const;

Equality operator.

operator

operatorstd::string_view

#
operator std::string_view() const;

Conversion operator for operations with std::string_view.

function

Reserve

#
void Reserve( const size_type NewCapacity );

Reserves space in the allocated memory to receive a new string.

NewCapacity
Total capacity needed for the new string (buffer size).
function

Shrink_to_fit

#
void Shrink_to_fit( void );

Reduces the current capacity and reallocates the string into a smaller memory buffer. Only what is needed to store the current string.

function

Clear

#
void Clear( void );

Clears the data and releases the memory of the current string.

function

C_Str

#
const char * C_Str( void ) const noexcept;

Gets the pointer to the string in C format (C Style).

function

Length

#
size_type Length( void ) const noexcept;

Gets the length of the string.

function

Capacity

#
size_type Capacity( void ) const noexcept;

Gets the capacity of the allocated character buffer.

function

BufferLength

#
size_type BufferLength( void ) const noexcept;

Gets the size of the allocated character buffer.

struct

std

#
C++
template<>
struct std::formatter< Ethereal::String::CAString > : std::formatter< std::string_view >
{
    template<typename FormatContext>
    auto format( const Ethereal::String::CAString & str, FormatContext & ctx ) const
    {
        return std::formatter< std::string_view >::format( str.C_Str(), ctx );
    }
};

io.hpp

#include <ethereal/cpp/string/io.hpp>
function

IsStringNullTerminated

Ethereal::String#
bool IsStringNullTerminated( const char * Str, const std::size_t Length );

Checks whether the given string is null terminated ('\0').

Str
Pointer to the string to check.
Length
Expected length of the string.
true if the string is null terminated within the given length. false otherwise.
function

IsStringEqual

Ethereal::String#
bool IsStringEqual( const char * Str1, const char * Str2, const bool bConsiderCase = true );

Compares two strings for equality.

Str1
Pointer to the first string.
Str2
Pointer to the second string.
bConsiderCase
Case sensitivity (default: true).
true if the strings are equal under the case criterion. false otherwise.
The comparison is faster when it is case sensitive.
function

IsStringEqual

Ethereal::String#
bool IsStringEqual( const char * Str1, const char * Str2, const std::size_t Str2Length, const bool bConsiderCase = true );

Compares two strings up to a maximum length given for the second string.

Str1
Pointer to the first string.
Str2
Pointer to the second string.
Str2Length
Maximum number of characters compared in the second string.
bConsiderCase
Case sensitivity (default: true).
true if the strings are equal up to the given length under the case criterion. false otherwise.
The comparison is faster when it is case sensitive.
function

IsStringWithinValidLength

Ethereal::String#
bool IsStringWithinValidLength( const char * Str, const std::size_t StrMaxLength );

Checks whether the string has a valid length, that is, does not exceed the given maximum size.

Str
Pointer to the string to check.
StrMaxLength
Maximum size allowed for the string.
true if the string length is less than or equal to the maximum size allowed. false if it exceeds it.
function

FormatStringInPlace

Ethereal::String#
template<typename... Args> void FormatStringInPlace( std::string & StrInOut, Args &&... args )

Formats the ascii string with the given arguments.

Args
Types of the variadic formatting arguments.
StrInOut
String to format, passed by reference and changed in place.
args
Arguments that fill the placeholders in the string.
The string must already contain the "{}" placeholders for the formatting.
The formatting follows the order of the arguments passed.
function

FormatStringInPlace

Ethereal::String#
template<typename... Args> void FormatStringInPlace( CAString & StrInOut, Args &&... args )

Formats the ascii string with the given arguments.

Args
Types of the variadic formatting arguments.
StrInOut
CAString to format, passed by reference and changed in place.
args
Arguments that fill the placeholders in the string.
The string must already contain the "{}" placeholders for the formatting.
The formatting follows the order of the arguments passed.
function

FormatStringInPlace

Ethereal::String#
template<typename... Args> void FormatStringInPlace( std::wstring & StrInOut, Args &&... args )

Formats the wide string with the given arguments.

Args
Types of the variadic formatting arguments.
StrInOut
String to format, passed by reference and changed in place.
args
Arguments that fill the placeholders in the string.
The string must already contain the "{}" placeholders for the formatting.
The formatting follows the order of the arguments passed.
function

FormatStringInPlace

Ethereal::String#
template<typename... Args> void FormatStringInPlace( CWString & StrInOut, Args &&... args )

Formats the wide string with the given arguments.

Args
Types of the variadic formatting arguments.
StrInOut
CWString to format, passed by reference and changed in place.
args
Arguments that fill the placeholders in the string.
The string must already contain the "{}" placeholders for the formatting.
The formatting follows the order of the arguments passed.
function

FormatXorAString

Ethereal::String#
template<class... Args> std::string FormatXorAString( const char * inOut_str, Args &&... args )

Formats the format string at run time (compatible with ETL_XORSTR).

inOut_str
String to format, can be ETL_XORSTR("...").
args
Arguments that fill the placeholders in the string.
std::string with the formatted result.
The format string is interpreted at run time through std::vformat. Do not store pointers returned by ETL_XORSTR. Use them only directly in the call to this function.
function

FormatXorWString

Ethereal::String#
template<class... Args> std::wstring FormatXorWString( const wchar_t * inOut_wstr, Args &&... args )

Formats the wide format string at run time (compatible with ETL_XORSTR_WIDE).

inOut_wstr
Wide string to format, can be ETL_XORSTR_WIDE("...").
args
Arguments that fill the placeholders in the string.
std::wstring with the formatted result.
The format string is interpreted at run time through std::vformat. Do not store pointers returned by ETL_XORSTR_WIDE. Use them only directly in the call to this function.

wide.hpp

#include <ethereal/cpp/string/wide.hpp>
class

CWString

Ethereal::String#

Internal Wide string class.

class CWString final

It is not guaranteed to be thread-safe. Synchronization is the responsibility of its caller. It must not be inherited directly by any structure, class or object.

alias

size_type

#
using size_type = std::size_t;

Base variable type for size calculations, size_t for better performance in x64 builds.

const

SSO_MaxSize

#
static constexpr size_type SSO_MaxSize = 64;

Maximum size of the SSO (Small String Optimization) string.

constructor

CWString

#
CWString() noexcept;

Default constructor.

constructor

CWString

#
CWString( const wchar_t * wStr ) noexcept;

'Direct initialization' constructor.

constructor

CWString

#
CWString( const CWString & other ) noexcept;

'Copy by reference' constructor.

constructor

CWString

#
CWString( CWString && other ) noexcept;

Move constructor.

constructor

CWString

#
CWString( const std::wstring & wStr ) noexcept;

'Direct initialization' constructor for the std::wstring format.

constructor

CWString

#
CWString( std::wstring && wStr ) noexcept;

'Move' constructor for the std::wstring format.

operator

operator=

#
CWString & operator=( const wchar_t * other );

Raw copy assignment operator.

operator

operator=

#
CWString & operator=( const CWString & other );

Copy assignment operator.

operator

operator=

#
CWString & operator=( CWString && other ) noexcept;

Move assignment operator.

operator

operator[]

#
wchar_t operator[]( size_type idx ) const;

Const subscript operator.

operator

operator+

#
[[nodiscard]] CWString operator+( const CWString & other ) const;

Concatenation operator. Returns a new string and leaves this one unchanged. Use operator+= to append.

operator

operator+

#
[[nodiscard]] CWString operator+( const wchar_t * other ) const;

Concatenation operator (Raw). Returns a new string and leaves this one unchanged.

operator

operator+=

#
CWString & operator+=( const CWString & other );

Appends another string to this one.

operator

operator+=

#
CWString & operator+=( const wchar_t * other );

Appends a character array to this string (Raw).

operator

operator<=>

#
auto operator<=>( const CWString & other ) const noexcept;

Three-way comparison operator (spaceship).

operator

operator==

#
bool operator==( const CWString & other ) const noexcept;

Equality operator.

operator

operatorstd::wstring_view

#
operator std::wstring_view() const noexcept;

Conversion operator for operations with std::wstring_view.

function

Reserve

#
void Reserve( const size_type NewCapacity );

Reserves space in the allocated memory to receive a new string.

NewCapacity
Total capacity needed for the new string (buffer size).
function

Shrink_to_fit

#
void Shrink_to_fit( void );

Reduces the current capacity and reallocates the string into a smaller memory buffer. Only what is needed to store the current string.

function

Clear

#
void Clear( void );

Clears the data and releases the memory of the current string.

function

C_Str

#
const wchar_t * C_Str( void ) const noexcept;

Gets the pointer to the wide string in C format (C Style).

function

Length

#
size_type Length( void ) const noexcept;

Gets the length of the string.

function

Capacity

#
size_type Capacity( void ) const noexcept;

Gets the capacity of the allocated character buffer.

function

BufferLength

#
size_type BufferLength( void ) const noexcept;

Gets the size of the allocated character buffer.

struct

std

#
C++
template<>
struct std::formatter< Ethereal::String::CWString, wchar_t > : std::formatter< std::wstring_view, wchar_t >
{
    template<typename FormatContext>
    auto format( const Ethereal::String::CWString & str, FormatContext & ctx ) const
    {
        return std::formatter< std::wstring_view, wchar_t >::format( str.C_Str(), ctx );
    }
};