Cbeam
|
Contains conversion utilities to transform data between different formats and types. Functions here handle string conversions, encoding manipulations, and the creation of string representations for various C++ types. They help ensure consistent serialization and text output across the library. More...
Classes | |
struct | has_insertion_operator |
The has_insertion_operator trait provides static meta-information about whether a type T has overloaded the operator<< for insertion into an output stream. More... | |
struct | has_insertion_operator< T, std::void_t< decltype(std::declval< std::ostream & >()<< std::declval< T >())> > |
struct | has_key_and_mapped_type |
Type trait to check if a given type supports key_type and mapped_type, similar to std::map. More... | |
struct | has_key_and_mapped_type< T, std::void_t< typename T::key_type, typename T::mapped_type > > |
struct | is_nested_map |
Type trait to check if a given type is a nested map. More... | |
struct | is_nested_map< T, std::void_t< typename T::nested_tables, typename T::table_of_values > > |
Functions | |
std::string | to_string (const container::buffer &b) |
Creates a std::string from the contents of a container::buffer . | |
template<typename T> | |
std::enable_if< has_key_and_mapped_type< T >::value &&!is_nested_map< T >::value, std::string >::type | to_string (const T &table, const int indentation) |
Converts a container supporting key_type and mapped_type to a formatted std::string. | |
template<typename T> | |
std::enable_if< has_key_and_mapped_type< T >::value &&!is_nested_map< T >::value, std::string >::type | to_string (const T &table) |
Converts a container supporting key_type and mapped_type to a formatted std::string. | |
template<typename Key, typename Value> | |
std::string | to_string (const container::nested_map< Key, Value > &map, const int indentation) |
Converts a nested_map to a formatted std::string with specified indentation. | |
template<typename Key, typename Value> | |
std::string | to_string (container::nested_map< Key, Value > &map, const int indentation) |
template<typename Key, typename Value> | |
std::string | to_string (const std::map< Key, container::nested_map< Key, Value > > &nested_maps, const int indentation) |
Converts a std::map of nested_maps to a formatted std::string with specified indentation. | |
template<typename Key, typename Value> | |
std::string | to_string (const std::map< Key, container::nested_map< Key, Value > > &nested_maps) |
Converts a std::map of nested_maps to a formatted std::string. | |
template<typename Key, typename Value> | |
std::string | to_string (const container::nested_map< Key, Value > &map) |
Converts a nested_map to a formatted std::string. | |
template<typename T> | |
std::enable_if< is_nested_map< T >::value, std::string >::type | to_string (const T &table) |
Converts a table to a formatted std::string, provided the table is a nested_map. | |
std::string | indent (int indentation) |
Returns a string consisting of indentation tab characters. | |
std::string | to_lower (std::string s) |
Converts characters A-Z in the given string to lower case and returns the modified string. | |
std::string | escape_string (const std::string &input, const char escape_character, const std::string &characters_to_escape) |
std::string | unescape_string (const std::string &input, char escape_character, const std::string &characters_to_unescape) |
template<typename T> | |
T | from_string (const std::string &str) |
Converts a given std::string to a specified type. | |
template<> | |
std::wstring | from_string< std::wstring > (const std::string &str) |
Converts the given std::string to std::wstring using UTF-8 to UTF-16 encoding. | |
template<typename T> | |
std::enable_if< has_insertion_operator< T >::value, std::string >::type | to_string (const T &value) |
Converts the value to a string, using the C-locale (i.e., '.' as a decimal separator). | |
template<typename T> | |
std::string | to_string (T *const &val) |
Converts a pointer to a string in hex syntax with a leading "0x". | |
std::string | to_string (const std::wstring &str) |
Converts the given std::wstring to std::string using UTF-16 to UTF-8 encoding. | |
template<typename T> | |
std::string | to_string (std::chrono::time_point< T > time) |
template<typename T> | |
std::wstring | to_wstring (T value) |
Converts any value that can be handled by to_string(...) into a std::wstring. | |
std::string | to_string (const container::xpod::type &val) |
Converts an xpod::type variant to a std::string . | |
TEST (ToLowerTest, HandlesUmlautsAndAccents) | |
TEST (FromStringTest, ConvertToInt) | |
TEST (FromStringTest, ConvertToDouble) | |
TEST (FromStringTest, ConvertToBool) | |
TEST (FromStringTest, ConvertToVoidPointer) | |
TEST (FromStringTest, ConvertToWString_ValidUTF8) | |
TEST (FromStringTest, ConvertToWString_InvalidUTF8) | |
TEST (FromStringTest, ConvertToWString_EmptyString) | |
TEST (FromStringTest, ConvertToWString_SpecialCharacters) | |
TEST (ToStringTest, ConvertIntToString) | |
TEST (ToStringTest, ConvertNegativeIntToString) | |
TEST (ToStringTest, ConvertDoubleToString) | |
TEST (ToStringTest, ConvertBooleanToString) | |
TEST (ToStringTest, ConvertPointerToString) | |
TEST (ToStringTest, ConvertCharToString) | |
TEST (ToStringWStringTest, ConvertValidUTF16ToString) | |
TEST (ToStringWStringTest, ConvertSpecialCharacters) | |
TEST (ToStringWStringTest, ConvertEmptyWString) | |
TEST (ToStringWStringTest, ConvertInvalidUTF16) | |
TEST (TimePointToStringTest, ConvertTimePointToString) | |
TEST (ToWStringTest, ConvertIntToWString) | |
TEST (ToWStringTest, ConvertDoubleToWString) | |
TEST (ToWStringTest, ConvertBoolToWString) | |
TEST (ConvertMap, Basic) | |
TEST (ConvertNestedMap, Basic) | |
Contains conversion utilities to transform data between different formats and types. Functions here handle string conversions, encoding manipulations, and the creation of string representations for various C++ types. They help ensure consistent serialization and text output across the library.
|
inline |
T cbeam::convert::from_string | ( | const std::string & | str | ) |
Converts a given std::string to a specified type.
This function template facilitates the conversion of a std::string to a variety of types, including fundamental types (like int, float, double) and pointer types (e.g., void*).
For floating point types such as float and double, a period ('.') is used as the decimal separator, independent of the current locale setting. For void* type, the string is interpreted as a hexadecimal number with an optional leading "0x". This function leverages std::istringstream for conversion, imbuing it with the "C" locale to ensure consistent parsing behavior across different locales.
T | The target type for the conversion. The type must support extraction via std::istringstream. |
str | The string to be converted. |
|
inline |
Converts the given std::string to std::wstring using UTF-8 to UTF-16 encoding.
This function utilizes std::wstring_convert with std::codecvt_utf8_utf16 to perform the conversion from string to wide string. It attempts the conversion and returns the resultant wide string if successful. In case of a range error (due to invalid UTF-8 input), it falls back to an element-wise conversion.
str | The string to be converted. |
|
inline |
Returns a string consisting of indentation
tab characters.
indentation | The number of tabs to generate. |
std::string
composed of indentation
tab characters. cbeam::convert::TEST | ( | ConvertMap | , |
Basic | ) |
cbeam::convert::TEST | ( | ConvertNestedMap | , |
Basic | ) |
cbeam::convert::TEST | ( | FromStringTest | , |
ConvertToBool | ) |
cbeam::convert::TEST | ( | FromStringTest | , |
ConvertToDouble | ) |
cbeam::convert::TEST | ( | FromStringTest | , |
ConvertToInt | ) |
cbeam::convert::TEST | ( | FromStringTest | , |
ConvertToVoidPointer | ) |
cbeam::convert::TEST | ( | FromStringTest | , |
ConvertToWString_EmptyString | ) |
cbeam::convert::TEST | ( | FromStringTest | , |
ConvertToWString_InvalidUTF8 | ) |
cbeam::convert::TEST | ( | FromStringTest | , |
ConvertToWString_SpecialCharacters | ) |
cbeam::convert::TEST | ( | FromStringTest | , |
ConvertToWString_ValidUTF8 | ) |
cbeam::convert::TEST | ( | TimePointToStringTest | , |
ConvertTimePointToString | ) |
cbeam::convert::TEST | ( | ToLowerTest | , |
HandlesUmlautsAndAccents | ) |
cbeam::convert::TEST | ( | ToStringTest | , |
ConvertBooleanToString | ) |
cbeam::convert::TEST | ( | ToStringTest | , |
ConvertCharToString | ) |
cbeam::convert::TEST | ( | ToStringTest | , |
ConvertDoubleToString | ) |
cbeam::convert::TEST | ( | ToStringTest | , |
ConvertIntToString | ) |
cbeam::convert::TEST | ( | ToStringTest | , |
ConvertNegativeIntToString | ) |
cbeam::convert::TEST | ( | ToStringTest | , |
ConvertPointerToString | ) |
cbeam::convert::TEST | ( | ToStringWStringTest | , |
ConvertEmptyWString | ) |
cbeam::convert::TEST | ( | ToStringWStringTest | , |
ConvertInvalidUTF16 | ) |
cbeam::convert::TEST | ( | ToStringWStringTest | , |
ConvertSpecialCharacters | ) |
cbeam::convert::TEST | ( | ToStringWStringTest | , |
ConvertValidUTF16ToString | ) |
cbeam::convert::TEST | ( | ToWStringTest | , |
ConvertBoolToWString | ) |
cbeam::convert::TEST | ( | ToWStringTest | , |
ConvertDoubleToWString | ) |
cbeam::convert::TEST | ( | ToWStringTest | , |
ConvertIntToWString | ) |
|
inline |
Converts characters A-Z in the given string to lower case and returns the modified string.
This function is compatible with UTF-8-encoded strings (because the byte representations of A-Z only occur in ASCII range, which is unaffected by multi-byte sequences).
s | The string to be transformed to lower case. |
|
inline |
Creates a std::string
from the contents of a container::buffer
.
b | A reference to a container::buffer . |
std::string
with the same size and contents as the provided buffer.
|
inline |
Converts a nested_map to a formatted std::string.
This overload takes a const reference to a nested_map. It converts both the direct key-value pairs and the sub-tables of nested_maps into a formatted string.
Key | The type of the keys in the nested_map. |
Value | The type of the values in the nested_map. |
map | The nested_map to be converted. |
|
inline |
Converts a nested_map to a formatted std::string with specified indentation.
This overload takes a const reference to a nested_map and an indentation level. It converts both the direct key-value pairs and the sub-tables of nested_maps into a formatted string.
Key | The type of the keys in the nested_map. |
Value | The type of the values in the nested_map. |
map | The nested_map to be converted. |
indentation | The indentation level for formatting the output. |
|
inline |
Converts an xpod::type
variant to a std::string
.
Depending on the variant's active index, this function:
convert::to_string(...)
static_cast<std::string>
on the memory::pointerval | The xpod::type variant to convert. |
|
inline |
Converts a std::map of nested_maps to a formatted std::string.
This function template converts a std::map where each value is a nested_map. It formats each key-value pair of the outer map and recursively calls to_string on each nested_map, increasing the indentation level with each recursive call for clarity and readability.
Key | The type of the keys in the outer std::map. |
Value | The type of the nested_maps in the outer std::map. |
nested_maps | The std::map of nested_maps to be converted. |
|
inline |
Converts a std::map of nested_maps to a formatted std::string with specified indentation.
This function template converts a std::map where each value is a nested_map. It formats each key-value pair of the outer map and recursively calls to_string on each nested_map, increasing the indentation level with each recursive call for clarity and readability.
Key | The type of the keys in the outer std::map. |
Value | The type of the nested_maps in the outer std::map. |
nested_maps | The std::map of nested_maps to be converted. |
indentation | The initial indentation level for formatting the output. |
|
inline |
Converts the given std::wstring to std::string using UTF-16 to UTF-8 encoding.
This function utilizes std::wstring_convert with std::codecvt_utf8_utf16 to perform the conversion from wide string to string. It attempts the conversion and returns the resultant string if successful. In case of a range error (due to invalid UTF-16 input), it falls back to an element-wise conversion.
str | The wide string to be converted. |
|
inline |
Converts a container supporting key_type and mapped_type to a formatted std::string.
This function template converts a container, which supports key_type and mapped_type (like std::map), to a formatted std::string. It excludes containers of type cbeam::container::nested_map. The conversion relies on the existence of to_string methods for key_type and mapped_type. Each key-value pair is converted to a string and concatenated.
T | The container type. |
table | The container to be converted. |
|
inline |
Converts a table to a formatted std::string, provided the table is a nested_map.
This template function converts a table to a formatted std::string, but only if the table type is identified as a nested_map using the is_nested_map trait. It leverages the specific to_string overload for nested_map types to perform the conversion.
T | The table type, expected to be a nested_map. |
table | The table to be converted. |
|
inline |
Converts a container supporting key_type and mapped_type to a formatted std::string.
This function template converts a container, which supports key_type and mapped_type (like std::map), to a formatted std::string. It excludes containers of type cbeam::container::nested_map. The conversion relies on the existence of to_string methods for key_type and mapped_type. Each key-value pair is converted to a string and concatenated, with indentation provided to align with surrounding context.
T | The container type. |
table | The container to be converted. |
indentation | The indentation level for formatting the output. |
|
inline |
Converts the value to a string, using the C-locale (i.e., '.' as a decimal separator).
T | The type of the value, which must be valid for insertion into a std::ostream. |
value | The value to be converted. |
|
inline |
|
inline |
|
inline |
Converts a pointer to a string in hex syntax with a leading "0x".
T | The pointed-to type. |
val | A pointer to an object of type T. |
std::wstring cbeam::convert::to_wstring | ( | T | value | ) |
Converts any value that can be handled by to_string(...)
into a std::wstring.
Internally calls convert::to_string(value)
and then from_string<std::wstring>(...)
.
T | The type of the value to convert. |
value | The value to convert to std::wstring. |
|
inline |