xentara-utils v1.1
Xentara utilities library
|
String utilities. More...
Namespaces | |
namespace | deprecated |
namespace | unicode |
Classes | |
class | BasicFixedString |
A string with a fixed size. More... | |
class | BasicStaticString |
A string that uses a statically allocated buffer for the data. More... | |
class | Converter |
A convert that allows conversion from one string type to another. More... | |
struct | IsNoopConversion |
Determines if a conversion between two string types is a NOOP. More... | |
struct | UninitializedTag |
Type used to select the constructor of BasicFixedString that leaves characters uninitialized. More... | |
class | view |
This is a wrapper class that supplies missing operator + () for string views. More... | |
Concepts | |
concept | CharacterType |
A concept for character data. | |
Typedefs | |
template<std::size_t kSize> | |
using | FixedString = BasicFixedString< char, kSize > |
A statically allocated string containing elements of type char More... | |
template<std::size_t kSize> | |
using | FixedWString = BasicFixedString< wchar_t, kSize > |
A statically allocated string containing elements of type wchar_t More... | |
template<std::size_t kSize> | |
using | FixedU8String = BasicFixedString< char8_t, kSize > |
A statically allocated string containing elements of type char8_t More... | |
template<std::size_t kSize> | |
using | FixedU16String = BasicFixedString< char16_t, kSize > |
A statically allocated string containing elements of type char16_t More... | |
template<std::size_t kSize> | |
using | FixedU32String = BasicFixedString< char32_t, kSize > |
A statically allocated string containing elements of type char32_t More... | |
template<std::size_t kCapacity> | |
using | StaticString = BasicStaticString< char, kCapacity > |
A statically allocated string containing elements of type char More... | |
template<std::size_t kCapacity> | |
using | StaticWString = BasicStaticString< wchar_t, kCapacity > |
A statically allocated string containing elements of type wchar_t More... | |
template<std::size_t kCapacity> | |
using | StaticU8String = BasicStaticString< char8_t, kCapacity > |
A statically allocated string containing elements of type char8_t More... | |
template<std::size_t kCapacity> | |
using | StaticU16String = BasicStaticString< char16_t, kCapacity > |
A statically allocated string containing elements of type char16_t More... | |
template<std::size_t kCapacity> | |
using | StaticU32String = BasicStaticString< char32_t, kCapacity > |
A statically allocated string containing elements of type char32_t More... | |
Functions | |
template<typename... Fragments> | |
auto | cat (const Fragments &... fragments) -> std::string |
Concatenates a number of fragments to a string in local encoding. More... | |
template<tools::StringViewable String, tools::CharType OutputCharT> | |
Converter (String &&, std::in_place_type_t< OutputCharT >) -> Converter< OutputCharT, typename tools::StringViewableViewType< String >::const_iterator, typename tools::StringViewableViewType< String >::const_iterator > | |
template<std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel, tools::CharType OutputCharT> | |
Converter (InputIterator, InputSentinel, std::in_place_type_t< OutputCharT >) -> Converter< OutputCharT, InputIterator, InputSentinel > | |
template<tools::CharType OutputChar, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel, std::output_iterator< OutputChar > OutputIterator, std::sentinel_for< OutputIterator > OutputSentinel = std::unreachable_sentinel_t> requires tools::CharType<std::iter_value_t<InputIterator>> | |
auto | convert (InputIterator begin, InputSentinel end, OutputIterator output, OutputSentinel outputEnd=std::unreachable_sentinel) -> OutputIterator |
Converts a character sequence from one type to another. More... | |
template<tools::CharType OutputChar, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel> requires tools::CharType<std::iter_value_t<InputIterator>> | |
auto | convert (InputIterator begin, InputSentinel end) -> std::basic_string< OutputChar > |
Converts a character sequence from one type to another. More... | |
template<tools::CharType OutputChar, typename CharTraits , std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel> requires tools::CharType<std::iter_value_t<InputIterator>> | |
auto | convert (InputIterator begin, InputSentinel end) -> std::basic_string< OutputChar, CharTraits > |
Converts a character sequence from one type to another. More... | |
template<tools::CharType OutputChar, typename CharTraits , tools::Allocator< OutputChar > Allocator, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel> requires tools::CharType<std::iter_value_t<InputIterator>> | |
auto | convert (InputIterator begin, InputSentinel end, const Allocator &allocator=Allocator()) -> std::basic_string< OutputChar, CharTraits, Allocator > |
Converts a character sequence from one type to another. More... | |
template<tools::CharType OutputChar, tools::StringViewable String> | |
auto | convert (String &&string) -> std::basic_string< OutputChar > |
Converts a string from one type to another. More... | |
template<tools::CharType OutputChar, typename CharTraits , tools::StringViewable String> | |
auto | convert (String &&string) -> std::basic_string< OutputChar, CharTraits > |
Converts a string from one type to another. More... | |
template<tools::CharType OutputChar, typename CharTraits , tools::Allocator< OutputChar > Allocator, tools::StringViewable String> | |
auto | convert (String &&string, const Allocator &allocator=Allocator()) -> std::basic_string< OutputChar, CharTraits, Allocator > |
Converts a string from one type to another. More... | |
template<tools::CharType OutputChar, tools::StringViewable String> | |
auto | convertOrView (const String &string) -> std::conditional_t< kIsNoopConversion< tools::StringViewableCharType< String >, OutputChar >, std::basic_string_view< OutputChar >, std::basic_string< OutputChar > > |
Converts a string from one type to another, returning a view if no conversion is necessary. More... | |
template<tools::CharType OutputChar, typename CharTraits , tools::StringViewable String> | |
auto | convertOrView (const String &string) -> std::conditional_t< kIsNoopConversion< tools::StringViewableCharType< String >, OutputChar >, std::basic_string_view< OutputChar, CharTraits >, std::basic_string< OutputChar, CharTraits > > |
Converts a string from one type to another, returning a view if no conversion is necessary. More... | |
template<tools::CharType OutputChar, typename CharTraits , tools::Allocator< OutputChar > Allocator, tools::StringViewable String> | |
auto | convertOrView (const String &string, const Allocator &allocator=Allocator()) -> std::conditional_t< kIsNoopConversion< tools::StringViewableCharType< String >, OutputChar >, std::basic_string_view< OutputChar, CharTraits >, std::basic_string< OutputChar, CharTraits, Allocator > > |
Converts a string from one type to another, returning a view if no conversion is necessary. More... | |
template<tools::CharType OutputChar, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel> requires tools::CharType<std::iter_value_t<InputIterator>> | |
auto | convertedSize (InputIterator begin, InputSentinel end) -> std::size_t |
Gets the size of a converted character sequence. More... | |
template<tools::CharType OutputChar, tools::StringViewable String> | |
auto | convertedSize (const String &string) -> std::size_t |
Gets the size of a converted string of type char More... | |
template<typename Char , typename Traits > | |
constexpr auto | fromStringView (const std::basic_string_view< Char, Traits > &view) -> std::basic_string< Char, Traits > |
Creates a string from a string view. More... | |
template<CharacterType Character> | |
constexpr auto | strlen (const Character *string) -> std::size_t |
Calculate the length of a string. More... | |
constexpr auto | strlen (std::nullptr_t) -> std::size_t |
Overload for xentara::utils::core::strlen() for literal null pointers. More... | |
Variables | |
constexpr UninitializedTag | kUninitialized |
A marker used to select constructor of BasicFixedString that leaves characters uninitialized. More... | |
String utilities.
This namespace contains string utilities.
using xentara::utils::string::FixedString = typedef BasicFixedString<char, kSize> |
A statically allocated string containing elements of type char
kSize | The capacity of the string |
using xentara::utils::string::FixedU16String = typedef BasicFixedString<char16_t, kSize> |
A statically allocated string containing elements of type char16_t
kSize | The capacity of the string |
using xentara::utils::string::FixedU32String = typedef BasicFixedString<char32_t, kSize> |
A statically allocated string containing elements of type char32_t
kSize | The capacity of the string |
using xentara::utils::string::FixedU8String = typedef BasicFixedString<char8_t, kSize> |
A statically allocated string containing elements of type char8_t
kSize | The capacity of the string |
using xentara::utils::string::FixedWString = typedef BasicFixedString<wchar_t, kSize> |
A statically allocated string containing elements of type wchar_t
kSize | The capacity of the string |
using xentara::utils::string::StaticString = typedef BasicStaticString<char, kCapacity> |
A statically allocated string containing elements of type char
kCapacity | The capacity of the string |
using xentara::utils::string::StaticU16String = typedef BasicStaticString<char16_t, kCapacity> |
A statically allocated string containing elements of type char16_t
kCapacity | The capacity of the string |
using xentara::utils::string::StaticU32String = typedef BasicStaticString<char32_t, kCapacity> |
A statically allocated string containing elements of type char32_t
kCapacity | The capacity of the string |
using xentara::utils::string::StaticU8String = typedef BasicStaticString<char8_t, kCapacity> |
A statically allocated string containing elements of type char8_t
kCapacity | The capacity of the string |
using xentara::utils::string::StaticWString = typedef BasicStaticString<wchar_t, kCapacity> |
A statically allocated string containing elements of type wchar_t
kCapacity | The capacity of the string |
auto xentara::utils::string::cat | ( | const Fragments &... | fragments | ) | -> std::string |
Concatenates a number of fragments to a string in local encoding.
The fragments can be anything convertible to std::string_view, std::wstring_view, std::u8string_view, std::u16string_view, or std::u32string_view, as well as any number, character, or boolean value. Also supported are std::chrono::system_clock::time_point, and std::filesystem::path.
Please note that the type char will be interpreted as a character, not a number.
There are two was to support concatenation using cat.
1. Using xentara_cat_string
In order to use this approach, you must provide one of the following:
The function must return any other value that is supported by cat.
2. Using xentara_cat_size and xentara_cat_append
In order to use this approach, you must provide one of the following:
The function must append a text representation of the given object to the given string.
To enable cat to pre-allocate the storage, you must also provide one of the following:
The function must return the number of characters that will be appended when calling xentara_cat_append.
fragments | The fragments |
auto xentara::utils::string::convert | ( | InputIterator | begin, |
InputSentinel | end | ||
) | -> std::basic_string<OutputChar> |
Converts a character sequence from one type to another.
This function converts a character sequence from one Unicode encoding to another. Illegal code points (high and low surrogates, and code points higher than U+10FFFF) and non-decodable input values are replaced by the replacement character.
OutputChar | The character type to use for the returned string |
begin | The beginning of the input sequence |
end | The end of the input sequence |
auto xentara::utils::string::convert | ( | InputIterator | begin, |
InputSentinel | end | ||
) | -> std::basic_string<OutputChar, CharTraits> |
Converts a character sequence from one type to another.
This function converts a character sequence from one Unicode encoding to another. Illegal code points (high and low surrogates, and code points higher than U+10FFFF) and non-decodable input values are replaced by the replacement character.
OutputChar | The character type to use for the returned string |
CharTraits | The character traits to be used for the returned string |
begin | The beginning of the input sequence |
end | The end of the input sequence |
auto xentara::utils::string::convert | ( | InputIterator | begin, |
InputSentinel | end, | ||
const Allocator & | allocator = Allocator() |
||
) | -> std::basic_string<OutputChar, CharTraits, Allocator> |
Converts a character sequence from one type to another.
This function converts a character sequence from one Unicode encoding to another. Illegal code points (high and low surrogates, and code points higher than U+10FFFF) and non-decodable input values are replaced by the replacement character.
OutputChar | The character type to use for the returned string |
CharTraits | The character traits to be used for the returned string |
Allocator | The allocator type to be used for the returned string |
begin | The beginning of the input sequence |
end | The end of the input sequence |
allocator | The allocator to be used for the returned string |
auto xentara::utils::string::convert | ( | InputIterator | begin, |
InputSentinel | end, | ||
OutputIterator | output, | ||
OutputSentinel | outputEnd = std::unreachable_sentinel |
||
) | -> OutputIterator |
Converts a character sequence from one type to another.
This function converts a string from one Unicode encoding to another. Illegal code points (high and low surrogates, and code points higher than U+10FFFF) and non-decodable input values are replaced by the replacement character.
If the converted string does not fit into the output sequence, then it is silently truncated. If you need to know whether the sequence was truncated or not, you must use a Converter object instead of this function.
begin | The beginning of the input sequence |
end | The end of the input sequence |
output | An output iterator for the output sequence |
outputEnd | A sentinel to mark the end of the output sequence |
auto xentara::utils::string::convert | ( | String && | string | ) | -> std::basic_string<OutputChar> |
Converts a string from one type to another.
This function converts a character sequence from one Unicode encoding to another. Illegal code points (high and low surrogates, and code points higher than U+10FFFF) and non-decodable input values are replaced by the replacement character.
OutputChar | The character type to use for the returned string |
string | The string to convert |
auto xentara::utils::string::convert | ( | String && | string | ) | -> std::basic_string<OutputChar, CharTraits> |
Converts a string from one type to another.
This function converts a character sequence from one Unicode encoding to another. Illegal code points (high and low surrogates, and code points higher than U+10FFFF) and non-decodable input values are replaced by the replacement character.
OutputChar | The character type to use for the returned string |
CharTraits | The character traits to be used for the returned string |
string | The string to convert |
auto xentara::utils::string::convert | ( | String && | string, |
const Allocator & | allocator = Allocator() |
||
) | -> std::basic_string<OutputChar, CharTraits, Allocator> |
Converts a string from one type to another.
This function converts a character sequence from one Unicode encoding to another. Illegal code points (high and low surrogates, and code points higher than U+10FFFF) and non-decodable input values are replaced by the replacement character.
OutputChar | The character type to use for the returned string |
CharTraits | The character traits to be used for the returned string |
Allocator | The allocator type to be used for the returned string |
string | The string to convert |
allocator | The allocator to be used for the returned string |
auto xentara::utils::string::convertedSize | ( | const String & | string | ) | -> std::size_t |
Gets the size of a converted string of type char
This function determines how much space will be needed to convert a string using convert().
string | The string to convert |
auto xentara::utils::string::convertedSize | ( | InputIterator | begin, |
InputSentinel | end | ||
) | -> std::size_t |
Gets the size of a converted character sequence.
This function determines how much space will be needed to convert a character sequence using convert().
begin | The beginning of the input sequence |
end | The end of the input sequence |
xentara::utils::string::Converter | ( | InputIterator | , |
InputSentinel | , | ||
std::in_place_type_t< OutputCharT > | |||
) | -> Converter< OutputCharT, InputIterator, InputSentinel > |
xentara::utils::string::Converter | ( | String && | , |
std::in_place_type_t< OutputCharT > | |||
) | -> Converter< OutputCharT, typename tools::StringViewableViewType< String >::const_iterator, typename tools::StringViewableViewType< String >::const_iterator > |
auto xentara::utils::string::convertOrView | ( | const String & | string | ) | -> std::conditional_t< kIsNoopConversion<tools::StringViewableCharType<String>, OutputChar>, std::basic_string_view<OutputChar>, std::basic_string<OutputChar>> |
Converts a string from one type to another, returning a view if no conversion is necessary.
This function converts a character sequence from one Unicode encoding to another. Illegal code points (high and low surrogates, and code points higher than U+10FFFF) and non-decodable input values are replaced by the replacement character.
In contrast to convert(), this function will only return a string, if a conversion needs to be done. If the encoding of the input type and the output type are the same, an std::basic_string_view referencing the data of the input string will be returned instead. This allows you to efficiently use this function in templates, where you want to avoid copying the data if possible.
OutputChar | The character type to use for the returned string |
string | The string to convert |
auto xentara::utils::string::convertOrView | ( | const String & | string | ) | -> std::conditional_t< kIsNoopConversion<tools::StringViewableCharType<String>, OutputChar>, std::basic_string_view<OutputChar, CharTraits>, std::basic_string<OutputChar, CharTraits>> |
Converts a string from one type to another, returning a view if no conversion is necessary.
This function converts a character sequence from one Unicode encoding to another. Illegal code points (high and low surrogates, and code points higher than U+10FFFF) and non-decodable input values are replaced by the replacement character.
In contrast to convert(), this function will only return a string, if a conversion needs to be done. If the encoding of the input type and the output type are the same, an std::basic_string_view referencing the data of the input string will be returned instead. This allows you to efficiently use this function in templates, where you want to avoid copying the data if possible.
OutputChar | The character type to use for the returned string |
CharTraits | The character traits to be used for the returned string |
string | The string to convert |
auto xentara::utils::string::convertOrView | ( | const String & | string, |
const Allocator & | allocator = Allocator() |
||
) | -> std::conditional_t< kIsNoopConversion<tools::StringViewableCharType<String>, OutputChar>, std::basic_string_view<OutputChar, CharTraits>, std::basic_string<OutputChar, CharTraits, Allocator>> |
Converts a string from one type to another, returning a view if no conversion is necessary.
This function converts a character sequence from one Unicode encoding to another. Illegal code points (high and low surrogates, and code points higher than U+10FFFF) and non-decodable input values are replaced by the replacement character.
In contrast to convert(), this function will only return a string, if a conversion needs to be done. If the encoding of the input type and the output type are the same, an std::basic_string_view referencing the data of the input string will be returned instead. This allows you to efficiently use this function in templates, where you want to avoid copying the data if possible.
OutputChar | The character type to use for the returned string |
CharTraits | The character traits to be used for the returned string |
Allocator | The allocator type to be used for the returned string |
string | The string to convert |
allocator | The allocator to be used for the returned string |
|
constexpr |
Creates a string from a string view.
|
constexpr |
Calculate the length of a string.
Calculates the number of characters in a string. The behaviour is undefined if string is not nullptr or a null terminated character array.
This function has a number of differences compared to std::strlen:
string | The string. Must be either a null terminated string, or nullptr. |
|
constexpr |
Overload for xentara::utils::core::strlen() for literal null pointers.
|
constexpr |
A marker used to select constructor of BasicFixedString that leaves characters uninitialized.