8#ifndef HPP_ALIB_CHARACTERS_CHARACTERS
9#define HPP_ALIB_CHARACTERS_CHARACTERS 1
23namespace alib {
namespace characters {
31template<
typename TChar>
41template<
typename TChar>
51template<
typename TChar>
61template<
typename TChar>
76template<
typename TChar, lang::Case sensitivity,
typename TRhs >
77bool Equal( TChar lhs, TRhs rhs )
82 if constexpr (
sizeof(TLhs) ==
sizeof(TRhs) )
83 return sensitive ? lhs == rhs
86 else if constexpr (
sizeof(TLhs) <
sizeof(TRhs) )
87 return sensitive ?
static_cast<TRhs
>(lhs) == rhs
90 else if constexpr (
sizeof(TLhs) >
sizeof(TRhs) )
91 return sensitive ? lhs ==
static_cast<TLhs
>(rhs)
105template<
typename TChar>
108 return static_cast<integer>( std::char_traits<TChar>::length(cstring) );
122template<
typename TChar>
125 std::char_traits<TChar>::copy( dest, src,
size_t(length) );
139template<
typename TChar>
142 std::char_traits<TChar>::move( dest, src,
size_t(length) );
153template<
typename TChar>
163template<
typename TChar>
181template<
typename TChar>
182const TChar*
Search(
const TChar* haystack,
integer haystackLength, TChar needle )
184 return std::char_traits<TChar>::find( haystack,
size_t(haystackLength), needle );
208template<
typename TChar>
210 const TChar* needles,
integer needlesLength );
223template<
typename TChar>
247template<
typename TChar>
249 const TChar* needles,
integer needlesLength );
263template<
typename TChar>
284template<
typename TChar>
286 const TChar* needles,
integer needlesLength );
306template<
typename TChar>
308 const TChar* needles,
integer needlesLength );
328template<
typename TChar>
330 const TChar* needle,
integer needleLength,
343template<
typename TChar>
346 return ::memcmp( lhs, rhs,
size_t(cmpLength) *
sizeof(TChar) ) == 0;
362template<
typename TChar>
365 return std::char_traits<TChar>::compare( lhs, rhs,
size_t(cmpLength) );
379template<
typename TChar>
390 memset( dest, c,
size_t(length) );
395 return static_cast<nchar>( toupper(c) );
400 return static_cast<nchar>( tolower(c) );
406 nchar* end= src + length;
416 nchar* end= src + length;
427 #if defined (__GLIBCXX__) || defined(__APPLE__) || defined(__ANDROID_NDK__)
428 return ::strncasecmp( lhs, rhs,
size_t(cmpLength) );
429 #elif defined ( _WIN32 )
430 return _strnicmp ( lhs, rhs,
size_t(cmpLength) );
432 #pragma message ( "Unknown Platform in file: " __FILE__ )
438 const nchar* result= std::strpbrk(haystack, needles);
439 return result ? result - haystack
445 return static_cast<integer>( std::strspn(haystack, needles) );
463 return static_cast<wchar>(towupper(
static_cast<wint_t
>(c)));
468 return static_cast<wchar>(towlower(
static_cast<wint_t
>(c)));
474 wchar* end= src + length;
484 wchar* end= src + length;
493#if ALIB_CHARACTERS_NATIVE_WCHAR
496 wmemset( dest, c,
size_t(length) );
501 #if defined ( _WIN32 )
502 return _wcsnicmp ( lhs, rhs,
size_t(cmpLength) );
503 #elif defined (__GLIBCXX__) || defined(__APPLE__) || defined(__ANDROID_NDK__)
504 return ::wcsncasecmp( lhs, rhs,
size_t(cmpLength) );
506 #pragma message ( "Unknown Platform in file: " __FILE__ )
512 const wchar* result= std::wcspbrk(haystack, needles);
513 return result ? result - haystack
518 return static_cast<integer>( std::wcsspn(haystack, needles) );
544 return static_cast<xchar>(towupper(
static_cast<wint_t
>(c)));
549 return static_cast<xchar>(towlower(
static_cast<wint_t
>(c)));
555 xchar* end= src + length;
565 xchar* end= src + length;
574#if ALIB_CHARACTERS_NATIVE_WCHAR
582 wmemset( dest, c,
size_t(length) );
587 #if defined (__GLIBCXX__) || defined(__APPLE__)
588 return ::wcsncasecmp( lhs, rhs,
size_t(cmpLength) );
589 #elif defined ( _WIN32 )
590 return _wcsnicmp ( lhs, rhs,
size_t(cmpLength) );
592 #pragma message ( "Unknown Platform in file: " __FILE__ )
598 const xchar* result= std::wcspbrk(haystack, needles);
599 return result ? result - haystack
604 return static_cast<integer>( std::wcsspn(haystack, needles) );
646template<
typename TChar=
character,
size_t TLength= 128/
sizeof(TChar)>
650 static constexpr size_t Alignment =
651 std::conditional_t<
sizeof(
void*) == 8, std::integral_constant<size_t ALIB_COMMA 64>,
652 std::integral_constant<size_t ALIB_COMMA 64>>::value;
655 alignas(Alignment) TChar buffer[TLength];
666 constexpr TChar*
Buffer() noexcept {
return buffer; }
670 constexpr const TChar*
Buffer() const noexcept {
return buffer; }
678 constexpr void Fill( TChar fillChar )
noexcept
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
integer IndexOfAnyExcluded(const TChar *haystack, integer haystackLength, const TChar *needles, integer needlesLength)
integer IndexOfAnyIncludedZT(const TChar *haystack, const TChar *needles)
integer IndexOfAnyExcludedZT(const TChar *haystack, const TChar *needles)
integer IndexOfFirstDifference(const TChar *haystack, integer haystackLength, const TChar *needle, integer needleLength, lang::Case sensitivity)
void Reverse(TChar *src, integer length)
integer Length(const TChar *cstring)
integer LastIndexOfAnyInclude(const TChar *haystack, integer startIdx, const TChar *needles, integer needlesLength)
void Move(const TChar *src, integer length, TChar *dest)
const TChar * Search(const TChar *haystack, integer haystackLength, TChar needle)
int Compare(const TChar *lhs, const TChar *rhs, integer cmpLength)
void Copy(const TChar *src, integer length, TChar *dest)
integer IndexOfAnyIncluded(const TChar *haystack, integer haystackLength, const TChar *needles, integer needlesLength)
integer LastIndexOfAnyExclude(const TChar *haystack, integer startIdx, const TChar *needles, integer needlesLength)
void Fill(TChar *dest, integer length, TChar value)
bool Equal(TChar lhs, TRhs rhs)
PLATFORM_SPECIFIC character
int CompareIgnoreCase(const TChar *lhs, const TChar *rhs, integer cmpLength)
Case
Denotes upper and lower case character treatment.
characters::nchar nchar
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
constexpr TChar * Buffer() noexcept
constexpr integer Length() const noexcept
constexpr void Fill(TChar fillChar) noexcept
constexpr AlignedCharArray() noexcept=default
Default constructor. Leaves the characters uninitialized.
constexpr const TChar * Buffer() const noexcept