This is the reference documentation of sub-namespace characters
of the ALib C++ Library, which holds types of library module ALib Characters.
Extensive documentation for this module is provided with ALib Module Characters - Programmer's Manual.
Nested Namespaces: | |
namespace | compatibility |
Type Index: | |
struct | AlignedCharArray |
struct | ArrayTraits |
struct | ZTArrayTraits |
Concepts | |
concept | IsArray |
concept | IsZTArray |
concept | IsImplicitArraySource |
concept | IsExplicitArraySource |
concept | IsMutableArraySource |
concept | IsImplicitArrayCast |
concept | IsExplicitArrayCast |
concept | IsImplicitZTArraySource |
concept | IsExplicitZTArraySource |
concept | IsMutableZTArraySource |
concept | IsImplicitZTArrayCast |
concept | IsExplicitZTArrayCast |
concept | IsCharacter |
Type Definition Index: | |
using | character = PLATFORM_SPECIFIC |
using | complementChar = PLATFORM_SPECIFIC |
template<typename TChar> | |
using | ComplementType |
using | nchar = char |
using | strangeChar = PLATFORM_SPECIFIC |
template<typename T> | |
using | Type |
template<size_t TSizeOf> | |
using | TypeBySize |
using | wchar = PLATFORM_SPECIFIC |
using | xchar = PLATFORM_SPECIFIC |
template<typename T> | |
using | ZTType |
Enumeration Index: | |
enum class | Policy { NONE , Implicit , ExplicitOnly , MutableOnly } |
Function Index: | |
template<typename T> | |
constexpr integer | ArrayLength () |
template<typename TChar> | |
int | Compare (const TChar *lhs, const TChar *rhs, integer cmpLength) |
template<typename TChar> | |
int | CompareIgnoreCase (const TChar *lhs, const TChar *rhs, integer cmpLength) |
template<typename TChar> | |
void | Copy (const TChar *src, integer length, TChar *dest) |
template<typename TChar> | |
bool | Equal (const TChar *lhs, const TChar *rhs, integer cmpLength) |
template<typename TChar, lang::Case sensitivity, typename TRhs> | |
bool | Equal (TChar lhs, TRhs rhs) |
template<typename TChar> | |
void | Fill (TChar *dest, integer length, TChar value) |
template<typename TChar> | |
integer | IndexOfAnyExcluded (const TChar *haystack, integer haystackLength, const TChar *needles, integer needlesLength) |
template<typename TChar> | |
integer | IndexOfAnyExcludedZT (const TChar *haystack, const TChar *needles) |
template<typename TChar> | |
integer | IndexOfAnyIncluded (const TChar *haystack, integer haystackLength, const TChar *needles, integer needlesLength) |
template<typename TChar> | |
integer | IndexOfAnyIncludedZT (const TChar *haystack, const TChar *needles) |
template<typename TChar> | |
integer | IndexOfFirstDifference (const TChar *haystack, integer haystackLength, const TChar *needle, integer needleLength, lang::Case sensitivity) |
template<typename TChar> | |
integer | LastIndexOfAnyExclude (const TChar *haystack, integer startIdx, const TChar *needles, integer needlesLength) |
template<typename TChar> | |
integer | LastIndexOfAnyInclude (const TChar *haystack, integer startIdx, const TChar *needles, integer needlesLength) |
template<typename TChar> | |
integer | Length (const TChar *cstring) |
template<typename TChar> | |
void | Move (const TChar *src, integer length, TChar *dest) |
template<typename TChar> | |
void | Reverse (TChar *src, integer length) |
template<typename TChar> | |
const TChar * | Search (const TChar *haystack, integer haystackLength, TChar needle) |
template<typename TChar> | |
void | ToLower (TChar *src, integer length) |
template<typename TChar> | |
TChar | ToLower (TChar c) |
template<typename TChar> | |
void | ToUpper (TChar *src, integer length) |
template<typename TChar> | |
TChar | ToUpper (TChar c) |
using alib::characters::character = PLATFORM_SPECIFIC |
This type represents a standard ALib character. The width (size) of a character is dependent on the platform and compilation flags.
This is why this type is called a "logical" type. The two other logical character types are complementChar and strangeChar.
Definition at line 91 of file chartypes.inl.
using alib::characters::complementChar = PLATFORM_SPECIFIC |
This type represents a non-standard ALib character. If alib::character is defined to implement a narrow character type, then this type implements a wide character and vice versa. Note, that the width of a wide character is not defined as well. It might be 2
or 4
bytes wide.
This type is called a "logical" type. The two other logical character types are character and strangeChar.
Definition at line 105 of file chartypes.inl.
using alib::characters::ComplementType |
This templated alias type-definition provides the "complement" to the given character type. By that, it is defined to wchar
if type nchar
is given and vice versa.
Note that for type xchar, no complement is defined. For this type (and all other types), this alias evaluates to void
.
TChar | The character type to get the complement for. |
Definition at line 501 of file chartraits.inl.
using alib::characters::nchar = char |
This type represents a narrow character in ALib. This is an alias for built-in C++ type char
.
Definition at line 20 of file chartypes.inl.
using alib::characters::strangeChar = PLATFORM_SPECIFIC |
Besides types alib::character and alib::complementChar, this is the third logical character type defined by ALib.
independent of compiler defaults and optional the compiler-symbols provided, this type always is equivalent to type xchar
Definition at line 115 of file chartypes.inl.
using alib::characters::Type |
Determines the character type of the array that the given template type T represents. In case no a specialization of the type trait ArrayTraits<T, TChar> exists, this evaluates to void
. Otherwise, this alias evaluates to one of nchar, wchar or xchar.
T | The custom type to get the character type for. |
Definition at line 211 of file chartraits.inl.
using alib::characters::TypeBySize |
This templated type alias can be used to determine the corresponding ALib character type from the size of the type. Typically (on common 64-bit platforms), this alias evaluates to: nchar if TSizeOf is given as 0
. Values 2
and 4
evaluate to wchar or xchar depending on the compiler and platform.
As an example, the QT Class Library uses a 2-byte character width, independent of compiler and platform. Therefore, to convert a QT character value to an ALib character value, the destination type is:
using qtChar= alib::characters::TypeBySize<2>;
TSizeOf | The size of the required character type in bytes. |
Definition at line 520 of file chartraits.inl.
using alib::characters::wchar = PLATFORM_SPECIFIC |
This type represents a wide character in ALib. Usually this is an alias for built-in C++ type wchar_t
. As the width of the latter is compiler-specific (the width may vary with different compilers even on the same platform), the compiler-symbol ALIB_CHARACTERS_SIZEOF_WCHAR may be used to manipulate its width.
Definition at line 38 of file chartypes.inl.
using alib::characters::xchar = PLATFORM_SPECIFIC |
This type represents a second wide character type which has a width complementary to that of type wchar: If wchar is 2 bytes wide, then this type aliases char32_t
and if its width is 4 bytes, this type aliases char16_t
.
While together with types alib::nchar and alib::wchar it forms the group of "explicit character types", it is always identical to logical type alib::strangeChar.
Definition at line 51 of file chartypes.inl.
using alib::characters::ZTType |
Determines the character type of the zero-terminated array that the given template type T represents. In case no a specialization of the type trait ZTArrayTraits<T, TChar> exists, this evaluates to void
. Otherwise, this alias evaluates to one of nchar, wchar or xchar.
T | The custom type to get the character type for. |
Definition at line 248 of file chartraits.inl.
|
strong |
Enumeration of possible values for fields Access and Construction of traits-types ArrayTraits and ZTArrayTraits. The elements of this enumeration indicate if and how the data of a "char-array-like type" (which may be non-zero- or zero-terminated) may be accessed and, reversely, how such types may be constructed from character arrays.
This is best explained when looking at class TString of higher-level module ALib Strings. That classes' constructors use this policy to decide if an instance it may be constructed implicitly or explicitly from a third-party type. In the other direction, the type provides cast methods, which let instances of TString implicitly or explicitly convert into third-party types.
Enumerator | |
---|---|
NONE | Data may not be received, respectively the custom type may not be constructed from a (character-array-) type. This value usually indicates that a custom type does not represent a character array at all. Hence, this is the default value exposed by the non-specialized version of type-traits structs ArrayTraits and ZTArrayTraits. |
Implicit | Allows implicit (and explicit) access of the character array data, respectively allows implicit and explicit construction of string-like custom types, from mutable or constant objects. |
ExplicitOnly | Allows explicit access of the character array data respectively allows explicit construction of string-like custom types, from mutable or constant objects. |
MutableOnly | Allows explicit access of the character array data from mutable objects only. |
Definition at line 22 of file chartraits.inl.
|
constexpr |
Returns the length of C++ arrays like std::extent
, but subtracts 1
if the array's element-type satisfies concept IsCharacter. (Thus, this "removes" the zero-termination character.)
T | The type to get the length for. Deduced by the compiler. |
0
for non-array types. Definition at line 547 of file chartraits.inl.
int alib::characters::Compare | ( | const TChar * | lhs, |
const TChar * | rhs, | ||
integer | cmpLength ) |
Compares up to cmpLength characters of two character arrays. Comparison stops if termination character '\0'
is found in one of the arrays.
TChar | One of the six (overlapping) character types. |
lhs | The first array to compare. |
rhs | The second array to compare. |
cmpLength | The number of characters to compare. |
0
if lhs and rhs are equal. Positive value if lhs appears after rhs in lexicographical order. Definition at line 348 of file functions.inl.
int alib::characters::CompareIgnoreCase | ( | const TChar * | lhs, |
const TChar * | rhs, | ||
integer | cmpLength ) |
Compares two character arrays of equal length ignoring letter case.
TChar | One of the six (overlapping) character types. |
lhs | The first array to compare. |
rhs | The second array to compare. |
cmpLength | The number of characters to compare. |
0
if lhs and rhs are equal. Positive value if lhs appears after rhs in lexicographical order. void alib::characters::Copy | ( | const TChar * | src, |
integer | length, | ||
TChar * | dest ) |
Copies the contents of a character array into another, non-overlapping (!) array.
Note: This method is implemented as an inlined, direct direct call to std::char_traits::copy
.
TChar | One of the six (overlapping) character types. |
src | Pointer to the source array. |
length | The length to copy. |
dest | Pointer to the destination array. |
Definition at line 108 of file functions.inl.
bool alib::characters::Equal | ( | const TChar * | lhs, |
const TChar * | rhs, | ||
integer | cmpLength ) |
Searches for a difference in two character arrays of equal length.
TChar | One of the six (overlapping) character types. |
lhs | The first array to compare. |
rhs | The second array to compare. |
cmpLength | The number of characters to compare. |
true
if the string arrays have identical contents, false
otherwise. Definition at line 329 of file functions.inl.
bool alib::characters::Equal | ( | TChar | lhs, |
TRhs | rhs ) |
Compares two characters of arbitrary types.
TChar | One of the six (overlapping) character types. |
sensitivity | Letter case sensitivity of the comparison. |
TRhs | The type of the right hand side letter to compare. |
lhs | The left-hand side character to compare of class template type TChar. |
rhs | The right-hand side character to compare of method template type TCharRhs . |
true
if the given characters are equal, false
otherwise. Definition at line 62 of file functions.inl.
void alib::characters::Fill | ( | TChar * | dest, |
integer | length, | ||
TChar | value ) |
Sets all elements of the given character array to value value.
TChar | One of the six (overlapping) character types. |
dest | Pointer to the destination array. |
length | The length to fill. |
value | The value to fill the array with. |
integer alib::characters::IndexOfAnyExcluded | ( | const TChar * | haystack, |
integer | haystackLength, | ||
const TChar * | needles, | ||
integer | needlesLength ) |
Returns the index of the first character in haystack which is not included in a given set of needles.
This method searches up to a given maximum index. For a search to the end of the zero-terminated string, use the faster method provided with class CString.
TChar | One of the six (overlapping) character types. |
haystack | Pointer to the start of the string. |
haystackLength | The length of the string or the maximum position to search. If -1 is provided, the length is determined using standard library function strlen (which needs haystack to be zero-terminated). |
needles | Pointer to a set of characters to be searched for. |
needlesLength | The length of the string of needles. If -1 is provided, the length is determined using standard library function strlen (which needs needles to be zero-terminated). |
-1
is returned. integer alib::characters::IndexOfAnyExcludedZT | ( | const TChar * | haystack, |
const TChar * | needles ) |
Same as IndexOfAnyExcluded(const TChar*,integer,const TChar*,integer) but works on zero-terminated strings.
TChar | One of the six (overlapping) character types. |
haystack | Pointer to a zero-terminated character array to search in. |
needles | Pointer to a zero-terminated set of characters to search for. |
-1
is returned. integer alib::characters::IndexOfAnyIncluded | ( | const TChar * | haystack, |
integer | haystackLength, | ||
const TChar * | needles, | ||
integer | needlesLength ) |
Returns the index of the first character in haystack which is included in a given set of needles.
This method searches up to a given maximum index. For a search to the end of the zero-terminated string, use faster method provided with class CString.
TChar | One of the six (overlapping) character types. |
haystack | Pointer to the start of the string. |
haystackLength | The length of the string or the maximum position to search. If -1 is provided, the length is determined using standard library function strlen (which needs haystack to be zero-terminated). |
needles | Pointer to a set of characters to be searched for. |
needlesLength | The length of the string of needles. If -1 is provided, the length is determined using standard library function strlen (which needs needles to be zero-terminated). |
-1
is returned. integer alib::characters::IndexOfAnyIncludedZT | ( | const TChar * | haystack, |
const TChar * | needles ) |
Same as IndexOfAnyIncluded(const TChar*,integer,const TChar*,integer) but works on zero-terminated strings.
TChar | One of the six (overlapping) character types. |
haystack | Pointer to a zero-terminated character array to search in. |
needles | Pointer to a zero-terminated set of characters to search for. |
-1
is returned. integer alib::characters::IndexOfFirstDifference | ( | const TChar * | haystack, |
integer | haystackLength, | ||
const TChar * | needle, | ||
integer | needleLength, | ||
lang::Case | sensitivity ) |
Returns the index of the first character which is not equal within two strings. If haystack starts with needle, then the length of needle is returned.
TChar | One of the six (overlapping) character types. |
haystack | Pointer to the start of the string. |
haystackLength | The length of the string or the maximum position to search. If -1 is provided, the length is determined using standard library function strlen (which needs haystack to be zero-terminated). |
needle | Pointer to the start of the string to compare with. |
needleLength | The length of needle. If -1 is provided, the length is determined using standard library function strlen (which needs needles to be zero-terminated). |
sensitivity | Denotes whether the comparison should be made case-sensitive or not. |
integer alib::characters::LastIndexOfAnyExclude | ( | const TChar * | haystack, |
integer | startIdx, | ||
const TChar * | needles, | ||
integer | needlesLength ) |
Returns the index of the last character in haystack which is not included in a given set of needles.
This method searches backwards from the end of the string.
TChar | One of the six (overlapping) character types. |
haystack | Pointer to the start of the string. |
startIdx | The position to start the search from. This must be smaller than the length of the string and greater or equal to zero. |
needles | Pointer to a set of characters to be searched for. |
needlesLength | The length of the string of needles. If -1 is provided, the length is determined using standard library function strlen (which needs needles to be zero-terminated). |
integer alib::characters::LastIndexOfAnyInclude | ( | const TChar * | haystack, |
integer | startIdx, | ||
const TChar * | needles, | ||
integer | needlesLength ) |
Returns the index of the last character in haystack which is included in a given set of needles.
This method searches backwards from the end of the string.
TChar | One of the six (overlapping) character types. |
haystack | Pointer to the start of the string. |
startIdx | The position to start the search from. This must be smaller than the length of the string and greater or equal to zero. |
needles | Pointer to a set of characters to be searched for. |
needlesLength | The length of the string of needles. If -1 is provided, the length is determined using standard library function strlen (which needs needles to be zero-terminated). |
integer alib::characters::Length | ( | const TChar * | cstring | ) |
Returns the length of a zero-terminated "c-style" character array.
Note: This method is implemented as an inlined, direct direct call to std::char_traits::length
.
TChar | One of the six (overlapping) character types. |
cstring | Pointer to a zero-terminated character array. |
Definition at line 91 of file functions.inl.
void alib::characters::Move | ( | const TChar * | src, |
integer | length, | ||
TChar * | dest ) |
Copies the contents of a character array into another, possibly overlapping array.
Note: This method is implemented as an inlined, direct direct call to std::char_traits::move
.
TChar | One of the six (overlapping) character types. |
src | Pointer to the source array. |
length | The length to copy. |
dest | Pointer to the destination array, optionally within source. |
Definition at line 125 of file functions.inl.
void alib::characters::Reverse | ( | TChar * | src, |
integer | length ) |
Reverses the order of the characters.
TChar | One of the six (overlapping) character types. |
src | Pointer to the character array. |
length | The length of the array. |
const TChar * alib::characters::Search | ( | const TChar * | haystack, |
integer | haystackLength, | ||
TChar | needle ) |
Searches the character. Returns a pointer to the location of needle in haystack, respectively nullptr
if not found.
Note: This method is implemented as a direct call to std::memchr
, respectively other character versions of it.
TChar | One of the six (overlapping) character types. |
haystack | Pointer to the start of the string. |
haystackLength | The length of the string or the maximum position to search. |
needle | Character to search. |
nullptr
if not found. Definition at line 167 of file functions.inl.
void alib::characters::ToLower | ( | TChar * | src, |
integer | length ) |
Converts a character sequence to lower case.
TChar | One of the six (overlapping) character types. |
src | Pointer to the character array. |
length | The length of the array. |
TChar alib::characters::ToLower | ( | TChar | c | ) |
Converts a character to lower case.
TChar | One of the six (overlapping) character types. |
c | The character to convert |
void alib::characters::ToUpper | ( | TChar * | src, |
integer | length ) |
Converts a character sequence to upper case.
TChar | One of the six (overlapping) character types. |
src | Pointer to the character array. |
length | The length of the array. |
TChar alib::characters::ToUpper | ( | TChar | c | ) |
Converts a character to upper case.
TChar | One of the six (overlapping) character types. |
c | The character to convert |