8#ifndef HPP_ALIB_CHARACTERS_CHARARRAY
9#define HPP_ALIB_CHARACTERS_CHARARRAY 1
12#if !defined (HPP_ALIB_CHARACTERS_CHARACTERS)
16#if !defined (HPP_ALIB_LANG_COMMONENUMS_DEFS)
20#if !defined (_GLIBCXX_NUMERIC_LIMITS) && !defined(_LIMITS_)
23#if !defined (_GLIBCXX_CSTRING) && !defined(_CSTRING_)
27#if !defined (_GLIBCXX_CCTYPE) && !defined(_CCTYPE_)
31#if !defined (_GLIBCXX_CWCTYPE) && !defined(_CWCTYPE_)
35#if !defined (_GLIBCXX_CWCHAR) && !defined(_CWCHAR_)
39#if !defined (_GLIBCXX_STRING) && !defined(_STRING_)
42namespace alib {
namespace characters {
51template<
typename TChar>
65 template<lang::Case sensitivity,
typename TRhs >
67 bool Equal( TChar lhs, TRhs rhs )
72 if constexpr (
sizeof(TLhs) ==
sizeof(TRhs) )
73 return sensitive ? lhs == rhs
76 else if constexpr (
sizeof(TLhs) <
sizeof(TRhs) )
77 return sensitive ?
static_cast<TRhs
>(lhs) == rhs
80 else if constexpr (
sizeof(TLhs) >
sizeof(TRhs) )
81 return sensitive ? lhs ==
static_cast<TLhs
>(rhs)
98 return static_cast<integer>( std::char_traits<TChar>::length(cstring) );
114 std::char_traits<TChar>::copy( dest, src,
static_cast<size_t>(length) );
130 std::char_traits<TChar>::move( dest, src,
static_cast<size_t>(length) );
205 const TChar*
Search(
const TChar* haystack,
integer haystackLength, TChar needle )
207 return std::char_traits<TChar>::find( haystack,
static_cast<size_t>(haystackLength), needle );
233 const TChar* needles,
integer needlesLength );
270 const TChar* needles,
integer needlesLength );
305 const TChar* needles,
integer needlesLength );
326 const TChar* needles,
integer needlesLength );
347 const TChar* needle,
integer needleLength,
363 return ::memcmp( lhs, rhs,
static_cast<size_t>(cmpLength) *
sizeof(TChar) ) == 0;
382 return std::char_traits<TChar>::compare( lhs, rhs,
static_cast<size_t>(cmpLength) );
408 memset( dest, c,
static_cast<size_t>(length) );
413 return static_cast<nchar>( toupper(c) );
418 return static_cast<nchar>( tolower(c) );
424 nchar* end= src + length;
434 nchar* end= src + length;
445 #if defined (__GLIBCXX__) || defined(__APPLE__) || defined(__ANDROID_NDK__)
446 return ::strncasecmp( lhs, rhs,
static_cast<size_t>(cmpLength) );
447 #elif defined ( _WIN32 )
448 return _strnicmp ( lhs, rhs,
static_cast<size_t>(cmpLength) );
450 #pragma message ( "Unknown Platform in file: " __FILE__ )
456 const nchar* result= std::strpbrk(haystack, needles);
457 return result ? result - haystack
463 return static_cast<integer>( std::strspn(haystack, needles) );
481 return static_cast<wchar>(towupper(
static_cast<wint_t
>(c)));
486 return static_cast<wchar>(towlower(
static_cast<wint_t
>(c)));
492 wchar* end= src + length;
502 wchar* end= src + length;
511#if ALIB_CHARACTERS_NATIVE_WCHAR
514 wmemset( dest, c,
static_cast<size_t>(length) );
519 #if defined ( _WIN32 )
520 return _wcsnicmp ( lhs, rhs,
static_cast<size_t>(cmpLength) );
521 #elif defined (__GLIBCXX__) || defined(__APPLE__) || defined(__ANDROID_NDK__)
522 return ::wcsncasecmp( lhs, rhs,
static_cast<size_t>(cmpLength) );
524 #pragma message ( "Unknown Platform in file: " __FILE__ )
530 const wchar* result= std::wcspbrk(haystack, needles);
531 return result ? result - haystack
536 return static_cast<integer>( std::wcsspn(haystack, needles) );
562 return static_cast<xchar>(towupper(
static_cast<wint_t
>(c)));
567 return static_cast<xchar>(towlower(
static_cast<wint_t
>(c)));
573 xchar* end= src + length;
583 xchar* end= src + length;
592#if ALIB_CHARACTERS_NATIVE_WCHAR
600 wmemset( dest, c,
static_cast<size_t>(length) );
605 #if defined (__GLIBCXX__) || defined(__APPLE__)
606 return ::wcsncasecmp( lhs, rhs,
static_cast<size_t>(cmpLength) );
607 #elif defined ( _WIN32 )
608 return _wcsnicmp ( lhs, rhs,
static_cast<size_t>(cmpLength) );
610 #pragma message ( "Unknown Platform in file: " __FILE__ )
616 const xchar* result= std::wcspbrk(haystack, needles);
617 return result ? result - haystack
622 return static_cast<integer>( std::wcsspn(haystack, needles) );
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
characters::nchar nchar
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
static TChar ToLower(TChar c)
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 ALIB_WARNINGS_RESTORE bool Equal(const TChar *lhs, const TChar *rhs, integer cmpLength)
static integer IndexOfAnyIncludedZT(const TChar *haystack, const TChar *needles)
static void ToUpper(TChar *src, integer length)
static TChar ToUpper(TChar c)
static integer IndexOfAnyExcludedZT(const TChar *haystack, const TChar *needles)
static integer Length(const TChar *cstring)
static ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE void Reverse(TChar *src, integer length)
static int Compare(const TChar *lhs, const TChar *rhs, integer cmpLength)
static void ToLower(TChar *src, integer length)
static void Fill(TChar *dest, integer length, TChar value)
static integer IndexOfAnyExcluded(const TChar *haystack, integer haystackLength, const TChar *needles, integer needlesLength)
static int CompareIgnoreCase(const TChar *lhs, const TChar *rhs, integer cmpLength)
static void Copy(const TChar *src, integer length, TChar *dest)
static integer LastIndexOfAnyInclude(const TChar *haystack, integer startIdx, const TChar *needles, integer needlesLength)
static bool Equal(TChar lhs, TRhs rhs)
static ALIB_WARNINGS_RESTORE const TChar * Search(const TChar *haystack, integer haystackLength, TChar needle)
static void Move(const TChar *src, integer length, TChar *dest)
static ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE integer IndexOfAnyIncluded(const TChar *haystack, integer haystackLength, const TChar *needles, integer needlesLength)