ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
CharArray< TChar > Struct Template Reference

Description:

template<typename TChar>
struct alib::characters::CharArray< TChar >

This utility struct provides static methods working with character arrays of different underlying type.
The struct is similar to type traits struct std::char_traits of the C++ standard library and for methods that are existing there already, just inline forwarding methods are defined here.

Definition at line 52 of file chararray.hpp.

#include <chararray.hpp>

Public Static Method Index:

static int Compare (const TChar *lhs, const TChar *rhs, integer cmpLength)
 
static int CompareIgnoreCase (const TChar *lhs, const TChar *rhs, integer cmpLength)
 
static void Copy (const TChar *src, integer length, TChar *dest)
 
static ALIB_WARNINGS_RESTORE bool Equal (const TChar *lhs, const TChar *rhs, integer cmpLength)
 
template<lang::Case sensitivity, typename TRhs >
static bool Equal (TChar lhs, TRhs rhs)
 
static void Fill (TChar *dest, integer length, TChar value)
 
static integer IndexOfAnyExcluded (const TChar *haystack, integer haystackLength, const TChar *needles, integer needlesLength)
 
static integer IndexOfAnyExcludedZT (const TChar *haystack, const TChar *needles)
 
static ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE integer IndexOfAnyIncluded (const TChar *haystack, integer haystackLength, const TChar *needles, integer needlesLength)
 
static integer IndexOfAnyIncludedZT (const TChar *haystack, const TChar *needles)
 
static integer IndexOfFirstDifference (const TChar *haystack, integer haystackLength, const TChar *needle, integer needleLength, lang::Case sensitivity)
 
static integer LastIndexOfAnyExclude (const TChar *haystack, integer startIdx, const TChar *needles, integer needlesLength)
 
static integer LastIndexOfAnyInclude (const TChar *haystack, integer startIdx, const TChar *needles, integer needlesLength)
 
static integer Length (const TChar *cstring)
 
static void Move (const TChar *src, integer length, TChar *dest)
 
static ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE void Reverse (TChar *src, integer length)
 
static ALIB_WARNINGS_RESTORE const TChar * Search (const TChar *haystack, integer haystackLength, TChar needle)
 
static void ToLower (TChar *src, integer length)
 
static TChar ToLower (TChar c)
 
static void ToUpper (TChar *src, integer length)
 
static TChar ToUpper (TChar c)
 

Method Details:

◆ Compare()

template<typename TChar >
static int Compare ( const TChar * lhs,
const TChar * rhs,
integer cmpLength )
inlinestatic

Compares up to cmpLength characters of two character arrays. Comparison stops if termination character '\0' is found in one of the arrays.

Parameters
lhsThe first array to compare.
rhsThe second array to compare.
cmpLengthThe number of characters to compare.
Returns
Negative value if lhs appears before rhs in lexicographical order. 0 if lhs and rhs are equal. Positive value if lhs appears after rhs in lexicographical order.

Definition at line 380 of file chararray.hpp.

◆ CompareIgnoreCase()

template<typename TChar >
static int CompareIgnoreCase ( const TChar * lhs,
const TChar * rhs,
integer cmpLength )
static

Compares two character arrays of equal length ignoring letter case.

Parameters
lhsThe first array to compare.
rhsThe second array to compare.
cmpLengthThe number of characters to compare.
Returns
Negative value if lhs appears before rhs in lexicographical order. 0 if lhs and rhs are equal. Positive value if lhs appears after rhs in lexicographical order.

◆ Copy()

template<typename TChar >
static void Copy ( const TChar * src,
integer length,
TChar * dest )
inlinestatic

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.

Parameters
srcPointer to the source array.
lengthThe length to copy.
destPointer to the destination array.

Definition at line 112 of file chararray.hpp.

◆ Equal() [1/2]

template<typename TChar >
static ALIB_WARNINGS_RESTORE bool Equal ( const TChar * lhs,
const TChar * rhs,
integer cmpLength )
inlinestatic

Searches for a difference in two character arrays of equal length.

Parameters
lhsThe first array to compare.
rhsThe second array to compare.
cmpLengthThe number of characters to compare.
Returns
true if the string arrays have identical contents, false otherwise.

Definition at line 361 of file chararray.hpp.

◆ Equal() [2/2]

template<typename TChar >
template<lang::Case sensitivity, typename TRhs >
static bool Equal ( TChar lhs,
TRhs rhs )
inlinestatic

Compares two characters of arbitrary types.

Template Parameters
sensitivityLetter case sensitivity of the comparison.
TRhsThe type of the right hand side letter to compare.
Parameters
lhsThe left-hand side character to compare of class template type TChar .
rhsThe right-hand side character to compare of method template type TCharRhs .
Returns
true if the given characters are equal, false otherwise.

Definition at line 67 of file chararray.hpp.

Here is the call graph for this function:

◆ Fill()

template<typename TChar >
static void Fill ( TChar * dest,
integer length,
TChar value )
static

Sets all elements of the given character array to value value .

Parameters
destPointer to the destination array.
lengthThe length to fill.
valueThe value to fill the array with.

◆ IndexOfAnyExcluded()

template<typename TChar >
static integer IndexOfAnyExcluded ( const TChar * haystack,
integer haystackLength,
const TChar * needles,
integer needlesLength )
static

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 faster method provided with class CString .

Parameters
haystackPointer to the start of the string.
haystackLengthThe length of the string or the maximum position to search. If -1 is provided, the length is determined using % C function strlen (which needs haystack to be zero terminated).
needlesPointer to a set of characters to be searched for.
needlesLengthThe length of the string of needles. If -1 is provided, the length is determined using % C function strlen (which needs needles to be zero terminated).
Returns
The index of the first character that is not included in needles . If all characters of haystack are included in needles , -1 is returned.

◆ IndexOfAnyExcludedZT()

template<typename TChar >
static integer IndexOfAnyExcludedZT ( const TChar * haystack,
const TChar * needles )
static

Same as IndexOfAnyExcluded(const TChar*,integer,const TChar*,integer) but works on zero-terminated strings.

Parameters
haystackPointer to zero-terminated character array to search in.
needlesPointer to zero-terminated set of characters to search for.
Returns
The index of the first character that is not included in needles . If all characters of haystack are included in needles , -1 is returned.

◆ IndexOfAnyIncluded()

template<typename TChar >
static ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE integer IndexOfAnyIncluded ( const TChar * haystack,
integer haystackLength,
const TChar * needles,
integer needlesLength )
static

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 .

Parameters
haystackPointer to the start of the string.
haystackLengthThe length of the string or the maximum position to search. If -1 is provided, the length is determined using % C function strlen (which needs haystack to be zero terminated).
needlesPointer to a set of characters to be searched for.
needlesLengthThe length of the string of needles. If -1 is provided, the length is determined using % C function strlen (which needs needles to be zero terminated).
Returns
The index of the first character found that is included in needles . If no character of haystack is included in needles , -1 is returned.

◆ IndexOfAnyIncludedZT()

template<typename TChar >
static integer IndexOfAnyIncludedZT ( const TChar * haystack,
const TChar * needles )
static

Same as IndexOfAnyIncluded(const TChar*,integer,const TChar*,integer) but works on zero-terminated strings.

Parameters
haystackPointer to zero-terminated character array to search in.
needlesPointer to zero-terminated set of characters to search for.
Returns
The index of the first character found that is included in needles . If no character of haystack is included in needles , -1 is returned.

◆ IndexOfFirstDifference()

template<typename TChar >
static integer IndexOfFirstDifference ( const TChar * haystack,
integer haystackLength,
const TChar * needle,
integer needleLength,
lang::Case sensitivity )
static

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.

Parameters
haystackPointer to the start of the string.
haystackLengthThe length of the string or the maximum position to search. If -1 is provided, the length is determined using % C function strlen (which needs haystack to be zero terminated).
needlePointer to the start of the string to compare with.
needleLengthThe length of needle . If -1 is provided, the length is determined using % C function strlen (which needs needles to be zero terminated).
sensitivityDenotes whether the comparison should be made case sensitive or not.
Returns
The index of the first character found which is not equal in given strings.

◆ LastIndexOfAnyExclude()

template<typename TChar >
static integer LastIndexOfAnyExclude ( const TChar * haystack,
integer startIdx,
const TChar * needles,
integer needlesLength )
static

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.

Parameters
haystackPointer to the start of the string.
startIdxThe position to start the search from. This must be smaller than the length of the string and greater or equal to zero.
needlesPointer to a set of characters to be searched for.
needlesLengthThe length of the string of needles. If -1 is provided, the length is determined using % C function strlen (which needs needles to be zero terminated).
Returns
The index of the first character found which is included in the given set of characters. If nothing is found, -1 is returned.

◆ LastIndexOfAnyInclude()

template<typename TChar >
static integer LastIndexOfAnyInclude ( const TChar * haystack,
integer startIdx,
const TChar * needles,
integer needlesLength )
static

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.

Parameters
haystackPointer to the start of the string.
startIdxThe position to start the search from. This must be smaller than the length of the string and greater or equal to zero.
needlesPointer to a set of characters to be searched for.
needlesLengthThe length of the string of needles. If -1 is provided, the length is determined using % C function strlen (which needs needles to be zero terminated).
Returns
The index of the first character found which is included in the given set of characters. If nothing is found, -1 is returned.

◆ Length()

template<typename TChar >
static integer Length ( const TChar * cstring)
inlinestatic

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.

Parameters
cstringPointer to zero-terminated character array.
Returns
The length of the string.

Definition at line 96 of file chararray.hpp.

◆ Move()

template<typename TChar >
static void Move ( const TChar * src,
integer length,
TChar * dest )
inlinestatic

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.

Parameters
srcPointer to the source array.
lengthThe length to copy.
destPointer to the destination array, optionally within source.

Definition at line 128 of file chararray.hpp.

◆ Reverse()

template<typename TChar >
static ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE void Reverse ( TChar * src,
integer length )
static

Reverses the order of the characters.

Parameters
srcPointer to the character array.
lengthThe length of the array.

◆ Search()

template<typename TChar >
static ALIB_WARNINGS_RESTORE const TChar * Search ( const TChar * haystack,
integer haystackLength,
TChar needle )
inlinestatic

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.

Parameters
haystackPointer to the start of the string.
haystackLengthThe length of the string or the maximum position to search.
needleCharacter to search.
Returns
The pointer to the first occurrence of needle respectively nullptr if not found.

Definition at line 205 of file chararray.hpp.

◆ ToLower() [1/2]

template<typename TChar >
static void ToLower ( TChar * src,
integer length )
static

Converts a character sequence to lower case.

Parameters
srcPointer to the character array.
lengthThe length of the array.

◆ ToLower() [2/2]

template<typename TChar >
static TChar ToLower ( TChar c)
static

Converts a character to lower case.

Parameters
cThe character to convert
Returns
The lower case version of the given character.

◆ ToUpper() [1/2]

template<typename TChar >
static void ToUpper ( TChar * src,
integer length )
static

Converts a character sequence to upper case.

Parameters
srcPointer to the character array.
lengthThe length of the array.

◆ ToUpper() [2/2]

template<typename TChar >
static TChar ToUpper ( TChar c)
static

Converts a character to upper case.

Parameters
cThe character to convert
Returns
The upper case version of the given character.

The documentation for this struct was generated from the following file: