ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
characters.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header file is part of module \alib_characters of the \aliblong.
4///
5/// \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8#ifndef HPP_ALIB_CHARACTERS_CHARACTERS
9#define HPP_ALIB_CHARACTERS_CHARACTERS 1
10#pragma once
11
14#include <limits>
15#include <cstring>
16#include <cctype>
17#include <cwctype>
18#include <cwchar>
19#include <string>
20
21#include "alib/lang/tmp.hpp"
22
23namespace alib { namespace characters {
24//==============================================================================================
25/// Converts a character to upper case.
26///
27/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
28/// @param c The character to convert
29/// @return The upper case version of the given character.
30//==============================================================================================
31template<typename TChar>
32TChar ToUpper( TChar c );
33
34//==============================================================================================
35/// Converts a character sequence to upper case.
36///
37/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
38/// @param src Pointer to the character array.
39/// @param length The length of the array.
40//==============================================================================================
41template<typename TChar>
42void ToUpper( TChar* src, integer length );
43
44//==============================================================================================
45/// Converts a character to lower case.
46///
47/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
48/// @param c The character to convert
49/// @return The lower case version of the given character.
50//==============================================================================================
51template<typename TChar>
52TChar ToLower( TChar c );
53
54//==============================================================================================
55/// Converts a character sequence to lower case.
56///
57/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
58/// @param src Pointer to the character array.
59/// @param length The length of the array.
60//==============================================================================================
61template<typename TChar>
62void ToLower( TChar* src, integer length );
63
64//==============================================================================================
65/// Compares two characters of arbitrary types.
66///
67/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
68/// @tparam sensitivity Letter case sensitivity of the comparison.
69/// @tparam TRhs The type of the right hand side letter to compare.
70/// @param lhs The left-hand side character to compare of class template
71/// type \p{TChar}.
72/// @param rhs The right-hand side character to compare of method template
73/// type \p{TCharRhs} .
74/// @return \c true if the given characters are equal, \c false otherwise.
75//==============================================================================================
76template<typename TChar, lang::Case sensitivity, typename TRhs >
77bool Equal( TChar lhs, TRhs rhs )
78{
79 using TLhs= TChar;
80 bool sensitive= (sensitivity == lang::Case::Sensitive);
81
82 if constexpr ( sizeof(TLhs) == sizeof(TRhs) )
83 return sensitive ? lhs == rhs
84 : ToUpper( lhs) == ToUpper( rhs);
85
86 else if constexpr ( sizeof(TLhs) < sizeof(TRhs) )
87 return sensitive ? static_cast<TRhs>(lhs) == rhs
88 : ToUpper( static_cast<TRhs>(lhs)) == ToUpper( rhs);
89
90 else if constexpr ( sizeof(TLhs) > sizeof(TRhs) )
91 return sensitive ? lhs == static_cast<TLhs>(rhs)
92 : ToUpper( lhs ) == ToUpper(static_cast<TLhs>(rhs));
93}
94
95//==============================================================================================
96/// Returns the length of a zero-terminated "c-style" character array.
97///
98/// Note: This method is implemented as an inlined, direct direct call to
99/// \c std::char_traits::length.
100///
101/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
102/// @param cstring Pointer to a zero-terminated character array.
103/// @return The length of the string.
104//==============================================================================================
105template<typename TChar>
106integer Length( const TChar* cstring )
107{
108 return static_cast<integer>( std::char_traits<TChar>::length(cstring) );
109}
110
111//==============================================================================================
112/// Copies the contents of a character array into another, non-overlapping (!) array.
113///
114/// Note: This method is implemented as an inlined, direct direct call to
115/// \c std::char_traits::copy.
116///
117/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
118/// @param src Pointer to the source array.
119/// @param length The length to copy.
120/// @param dest Pointer to the destination array.
121//==============================================================================================
122template<typename TChar>
123void Copy( const TChar* src, integer length, TChar* dest )
124{
125 std::char_traits<TChar>::copy( dest, src, size_t(length) );
126}
127
128//==============================================================================================
129/// Copies the contents of a character array into another, possibly overlapping array.
130///
131/// Note: This method is implemented as an inlined, direct direct call to
132/// \c std::char_traits::move.
133///
134/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
135/// @param src Pointer to the source array.
136/// @param length The length to copy.
137/// @param dest Pointer to the destination array, optionally within source.
138//==============================================================================================
139template<typename TChar>
140void Move( const TChar* src, integer length, TChar* dest )
141{
142 std::char_traits<TChar>::move( dest, src, size_t(length) );
143}
144
145//==============================================================================================
146/// Sets all elements of the given character array to value \p{value}.
147///
148/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
149/// @param dest Pointer to the destination array.
150/// @param length The length to fill.
151/// @param value The value to fill the array with.
152//==============================================================================================
153template<typename TChar>
154void Fill( TChar* dest, integer length, TChar value );
155
156//==============================================================================================
157/// Reverses the order of the characters.
158///
159/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
160/// @param src Pointer to the character array.
161/// @param length The length of the array.
162//==============================================================================================
163template<typename TChar>
164void Reverse( TChar* src, integer length );
165
166//==============================================================================================
167/// Searches the character. Returns a pointer to the location of \p{needle} in \p{haystack},
168/// respectively \c nullptr if not found.
169///
170/// Note: This method is implemented as a direct call to \c std::memchr, respectively
171/// other character versions of it.
172///
173/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
174/// @param haystack Pointer to the start of the string.
175/// @param haystackLength The length of the string or the maximum position to search.
176/// @param needle Character to search.
177///
178/// @return The pointer to the first occurrence of \p{needle} respectively \c nullptr if
179/// not found.
180//==============================================================================================
181template<typename TChar>
182const TChar* Search( const TChar* haystack, integer haystackLength, TChar needle )
183{
184 return std::char_traits<TChar>::find( haystack, size_t(haystackLength), needle );
185}
186
187//==============================================================================================
188/// Returns the index of the first character in \p{haystack} which is included in a given set
189/// of \p{needles}.
190///
191/// This method searches up to a given maximum index. For a search to the end of the
192/// zero-terminated string, use faster method provided with class
193/// \alib{strings;TCString;CString}.
194///
195/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
196/// @param haystack Pointer to the start of the string.
197/// @param haystackLength The length of the string or the maximum position to search.
198/// If -1 is provided, the length is determined using standard library
199/// function \b strlen (which needs haystack to be zero-terminated).
200/// @param needles Pointer to a set of characters to be searched for.
201/// @param needlesLength The length of the string of needles.
202/// If -1 is provided, the length is determined using standard library
203/// function \b strlen (which needs needles to be zero-terminated).
204///
205/// @return The index of the first character found that is included in \p{needles}.
206/// If no character of haystack is included in \p{needles}, \c -1 is returned.
207//==============================================================================================
208template<typename TChar>
209integer IndexOfAnyIncluded( const TChar* haystack, integer haystackLength,
210 const TChar* needles, integer needlesLength );
211
212//==============================================================================================
213/// Same as #IndexOfAnyIncluded(const TChar*,integer,const TChar*,integer) but works on
214/// zero-terminated strings.
215///
216/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
217/// @param haystack Pointer to a zero-terminated character array to search in.
218/// @param needles Pointer to a zero-terminated set of characters to search for.
219///
220/// @return The index of the first character found that is included in \p{needles}.
221/// If no character of haystack is included in \p{needles}, \c -1 is returned.
222//==============================================================================================
223template<typename TChar>
224integer IndexOfAnyIncludedZT( const TChar* haystack, const TChar* needles );
225
226//==============================================================================================
227/// Returns the index of the first character in \p{haystack} which is not included in a given
228/// set of \p{needles}.
229///
230/// This method searches up to a given maximum index. For a search to the end of the
231/// zero-terminated string, use the faster method provided with class
232/// \alib{strings;TCString;CString}.
233///
234/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
235/// @param haystack Pointer to the start of the string.
236/// @param haystackLength The length of the string or the maximum position to search.
237/// If -1 is provided, the length is determined using standard library
238/// function \b strlen (which needs haystack to be zero-terminated).
239/// @param needles Pointer to a set of characters to be searched for.
240/// @param needlesLength The length of the string of needles.
241/// If -1 is provided, the length is determined using standard library
242/// function \b strlen (which needs needles to be zero-terminated).
243///
244/// @return The index of the first character that is not included in \p{needles}.
245/// If all characters of haystack are included in \p{needles}, \c -1 is returned.
246//==============================================================================================
247template<typename TChar>
248integer IndexOfAnyExcluded( const TChar* haystack, integer haystackLength,
249 const TChar* needles, integer needlesLength );
250
251
252//==============================================================================================
253/// Same as #IndexOfAnyExcluded(const TChar*,integer,const TChar*,integer) but works on
254/// zero-terminated strings.
255///
256/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
257/// @param haystack Pointer to a zero-terminated character array to search in.
258/// @param needles Pointer to a zero-terminated set of characters to search for.
259///
260/// @return The index of the first character that is not included in \p{needles}.
261/// If all characters of haystack are included in \p{needles}, \c -1 is returned.
262//==============================================================================================
263template<typename TChar>
264integer IndexOfAnyExcludedZT( const TChar* haystack, const TChar* needles );
265
266//==============================================================================================
267/// Returns the index of the last character in \p{haystack} which is included in a given set
268/// of \p{needles}.
269///
270/// This method searches backwards from the end of the string.
271///
272/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
273/// @param haystack Pointer to the start of the string.
274/// @param startIdx The position to start the search from. This must be smaller than
275/// the length of the string and greater or equal to zero.
276/// @param needles Pointer to a set of characters to be searched for.
277/// @param needlesLength The length of the string of needles.
278/// If -1 is provided, the length is determined using standard library
279/// function \b strlen (which needs needles to be zero-terminated).
280///
281/// @return The index of the first character found which is included in the given set
282/// of characters. If nothing is found, -1 is returned.
283//==============================================================================================
284template<typename TChar>
285integer LastIndexOfAnyInclude( const TChar* haystack, integer startIdx,
286 const TChar* needles, integer needlesLength );
287
288//==============================================================================================
289/// Returns the index of the last character in \p{haystack} which is not included in a given
290/// set of \p{needles}.
291///
292/// This method searches backwards from the end of the string.
293///
294/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
295/// @param haystack Pointer to the start of the string.
296/// @param startIdx The position to start the search from. This must be smaller than
297/// the length of the string and greater or equal to zero.
298/// @param needles Pointer to a set of characters to be searched for.
299/// @param needlesLength The length of the string of needles.
300/// If -1 is provided, the length is determined using standard library
301/// function \b strlen (which needs needles to be zero-terminated).
302///
303/// @return The index of the first character found which is included in the given set
304/// of characters. If nothing is found, -1 is returned.
305//==============================================================================================
306template<typename TChar>
307integer LastIndexOfAnyExclude( const TChar* haystack, integer startIdx,
308 const TChar* needles, integer needlesLength );
309
310//==============================================================================================
311/// Returns the index of the first character which is not equal within two strings.
312/// If \p{haystack} starts with \p{needle}, then the length of \p{needle} is returned.
313///
314/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
315/// @param haystack Pointer to the start of the string.
316/// @param haystackLength The length of the string or the maximum position to search.
317/// If -1 is provided, the length is determined using standard library
318/// function \b strlen (which needs haystack to be zero-terminated).
319/// @param needle Pointer to the start of the string to compare with.
320/// @param needleLength The length of \p{needle}.
321/// If -1 is provided, the length is determined using standard library
322/// function \b strlen (which needs needles to be zero-terminated).
323/// @param sensitivity Denotes whether the comparison should be made case-sensitive
324/// or not.
325///
326/// @return The index of the first character found which is not equal in given strings.
327//==============================================================================================
328template<typename TChar>
329integer IndexOfFirstDifference( const TChar* haystack, integer haystackLength,
330 const TChar* needle, integer needleLength,
331 lang::Case sensitivity );
332
333//==============================================================================================
334/// Searches for a difference in two character arrays of equal length.
335///
336/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
337/// @param lhs The first array to compare.
338/// @param rhs The second array to compare.
339/// @param cmpLength The number of characters to compare.
340///
341/// @return \c true if the string arrays have identical contents, \c false otherwise.
342//==============================================================================================
343template<typename TChar>
344bool Equal( const TChar* lhs, const TChar* rhs, integer cmpLength )
345{
346 return ::memcmp( lhs, rhs, size_t(cmpLength) * sizeof(TChar) ) == 0;
347}
348
349//==============================================================================================
350/// Compares up to \p{cmpLength} characters of two character arrays.
351/// Comparison stops if termination character \c '\0' is found in one of the arrays.
352///
353/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
354/// @param lhs The first array to compare.
355/// @param rhs The second array to compare.
356/// @param cmpLength The number of characters to compare.
357///
358/// @return Negative value if lhs appears before rhs in lexicographical order.
359/// \c 0 if lhs and rhs are equal.
360/// Positive value if lhs appears after rhs in lexicographical order.
361//==============================================================================================
362template<typename TChar>
363int Compare( const TChar* lhs, const TChar* rhs, integer cmpLength )
364{
365 return std::char_traits<TChar>::compare( lhs, rhs, size_t(cmpLength) );
366}
367
368//==============================================================================================
369/// Compares two character arrays of equal length ignoring letter case.
370/// @tparam TChar One of the six (overlapping) \ref alib_characters_chars "character types".
371/// @param lhs The first array to compare.
372/// @param rhs The second array to compare.
373/// @param cmpLength The number of characters to compare.
374///
375/// @return Negative value if lhs appears before rhs in lexicographical order.
376/// \c 0 if lhs and rhs are equal.
377/// Positive value if lhs appears after rhs in lexicographical order.
378//==============================================================================================
379template<typename TChar>
380int CompareIgnoreCase( const TChar* lhs, const TChar* rhs, integer cmpLength );
381
382
383
384//! @cond NO_DOX
385// #################################################################################################
386// Narrow character specifics
387// #################################################################################################
388template<> inline void Fill<nchar>( nchar* dest, integer length, nchar c )
389{
390 memset( dest, c, size_t(length) );
391}
392
393template<> inline nchar ToUpper<nchar>(nchar c)
394{
395 return static_cast<nchar>( toupper(c) );
396}
397
398template<> inline nchar ToLower<nchar>(nchar c)
399{
400 return static_cast<nchar>( tolower(c) );
401}
402
404template<> inline void ToUpper<nchar>(nchar* src, integer length)
405{
406 nchar* end= src + length;
407 while( src != end )
408 {
409 *src= ToUpper<nchar>( *src );
410 ++src;
411 }
412}
413
414template<> inline void ToLower<nchar>(nchar* src, integer length)
415{
416 nchar* end= src + length;
417 while( src != end )
418 {
419 *src= ToLower<nchar>( *src );
420 ++src;
421 }
422}
424
425template<> inline int CompareIgnoreCase<nchar>( const nchar* lhs, const nchar* rhs, integer cmpLength )
426{
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) );
431 #else
432 #pragma message ( "Unknown Platform in file: " __FILE__ )
433 #endif
434}
435
436template<> inline integer IndexOfAnyIncludedZT <nchar>( const nchar* haystack, const nchar* needles )
437{
438 const nchar* result= std::strpbrk(haystack, needles);
439 return result ? result - haystack
440 : -1;
441}
442
443template<> inline integer IndexOfAnyExcludedZT<nchar>( const nchar* haystack, const nchar* needles )
444{
445 return static_cast<integer>( std::strspn(haystack, needles) );
446}
447
448
449
455extern template ALIB_API void Reverse <nchar>( nchar*,integer );
456
457
458// #################################################################################################
459// Wide character specifics
460// #################################################################################################
461template<> inline wchar ToUpper<wchar>(wchar c)
462{
463 return static_cast<wchar>(towupper(static_cast<wint_t>(c)));
464}
465
466template<> inline wchar ToLower<wchar>(wchar c)
467{
468 return static_cast<wchar>(towlower(static_cast<wint_t>(c)));
469}
470
472template<> inline void ToUpper<wchar>(wchar* src, integer length)
473{
474 wchar* end= src + length;
475 while( src != end )
476 {
477 *src= ToUpper<wchar>( *src );
478 ++src;
479 }
480}
481
482template<> inline void ToLower<wchar>(wchar* src, integer length)
483{
484 wchar* end= src + length;
485 while( src != end )
486 {
487 *src= ToLower<wchar>( *src );
488 ++src;
489 }
490}
492
493#if ALIB_CHARACTERS_NATIVE_WCHAR
494template<> inline void Fill<wchar>( wchar* dest, integer length, wchar c )
495{
496 wmemset( dest, c, size_t(length) );
497}
498
499template<> inline int CompareIgnoreCase<wchar>( const wchar* lhs, const wchar* rhs, integer cmpLength )
500{
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) );
505 #else
506 #pragma message ( "Unknown Platform in file: " __FILE__ )
507 #endif
508}
509
510template<> inline integer IndexOfAnyIncludedZT <wchar>( const wchar* haystack, const wchar* needles )
511{
512 const wchar* result= std::wcspbrk(haystack, needles);
513 return result ? result - haystack
514 : -1;
515}
516template<> inline integer IndexOfAnyExcludedZT<wchar>( const wchar* haystack, const wchar* needles )
517{
518 return static_cast<integer>( std::wcsspn(haystack, needles) );
519}
520
521
522#else
523template<> ALIB_API void Fill<wchar>( wchar* dest, integer length, wchar c );
524template<> ALIB_API int CompareIgnoreCase <wchar>( const wchar* lhs, const wchar* rhs, integer cmpLength );
525template<> ALIB_API integer IndexOfAnyIncludedZT<wchar>( const wchar* haystack, const wchar* needles );
526template<> ALIB_API integer IndexOfAnyExcludedZT<wchar>( const wchar* haystack, const wchar* needles );
527#endif
528
529
535extern template ALIB_API void Reverse <wchar>( wchar*,integer );
536
537
538
539// #################################################################################################
540// Strange character specifics
541// #################################################################################################
542template<> inline xchar ToUpper<xchar>(xchar c)
543{
544 return static_cast<xchar>(towupper(static_cast<wint_t>(c)));
545}
546
547template<> inline xchar ToLower<xchar>(xchar c)
548{
549 return static_cast<xchar>(towlower(static_cast<wint_t>(c)));
550}
551
553template<> inline void ToUpper<xchar>(xchar* src, integer length)
554{
555 xchar* end= src + length;
556 while( src != end )
557 {
558 *src= ToUpper<xchar>( *src );
559 ++src;
560 }
561}
562
563template<> inline void ToLower<xchar>(xchar* src, integer length)
564{
565 xchar* end= src + length;
566 while( src != end )
567 {
568 *src= ToLower<xchar>( *src );
569 ++src;
570 }
571}
573
574#if ALIB_CHARACTERS_NATIVE_WCHAR
575template<> ALIB_API void Fill<xchar>( xchar* dest, integer length, xchar c );
576template<> ALIB_API int CompareIgnoreCase<xchar>( const xchar* lhs, const xchar* rhs, integer cmpLength );
577template<> ALIB_API integer IndexOfAnyIncludedZT<xchar>( const xchar* haystack, const xchar* needles );
578template<> ALIB_API integer IndexOfAnyExcludedZT<xchar>( const xchar* haystack, const xchar* needles );
579#else
580template<> inline void Fill<xchar>( xchar* dest, integer length, xchar c )
581{
582 wmemset( dest, c, size_t(length) );
583}
584
585template<> inline int CompareIgnoreCase<xchar>( const xchar* lhs, const xchar* rhs, integer cmpLength )
586{
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) );
591 #else
592 #pragma message ( "Unknown Platform in file: " __FILE__ )
593 #endif
594}
595
596template<> inline integer IndexOfAnyIncludedZT <xchar>( const xchar* haystack, const xchar* needles )
597{
598 const xchar* result= std::wcspbrk(haystack, needles);
599 return result ? result - haystack
600 : -1;
601}
602template<> inline integer IndexOfAnyExcludedZT<xchar>( const xchar* haystack, const xchar* needles )
603{
604 return static_cast<integer>( std::wcsspn(haystack, needles) );
605}
606#endif
607
613extern template ALIB_API void Reverse <xchar>( xchar*,integer );
614//! @endcond
615
616// #################################################################################################
617// struct AlignedCharArray
618// #################################################################################################
619/// Encapsulates a fixed-size character buffer.
620/// The character type and the buffer's length are templated.
621/// Furthermore the buffer, and with it this type, is aligned to \c 8 bytes on 64-bit machines and
622/// to \c 4 bytes on 32-bit hardware.
623/// This supports fast access and compile-time optimizations.
624///
625/// An overloaded constructor and method #Fill allow filling the buffer with a distinct character.
626/// This is provided, as a frequent use-case for this struct is to provide
627/// \alib{strings;TString;String} objects of variable length.
628/// For example, when generating indentation in text files, a <c>std::basic_ostream</c> might be
629/// faster filled with spaces using a local variable of this type than putting character by
630/// character to the stream in a loop.
631///
632/// The type's name uses the word "local" because usually it is used with local (stack allocated)
633/// variables.
634/// @tparam TChar The character type.
635/// Alias names for C++ character types exist with
636/// - \alib{characters;character},
637/// - \alib{characters;nchar},
638/// - \alib{characters;wchar},
639/// - \alib{characters;xchar},
640/// - \alib{characters;complementChar}, and
641/// - \alib{characters;strangeChar}.
642///
643/// Defaults to \alib{characters;character}.
644///
645/// @tparam TLength The length of the local buffer. Defaults to 128 bytes.
646template<typename TChar= character, size_t TLength= 128/sizeof(TChar)>
648 /// The alignment of the field #buffer. Because this is the first (and only) field, this
649 /// struct itself shares this alignment.
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;
653
654 /// The buffer.
655 alignas(Alignment) TChar buffer[TLength];
656
657 /// Default constructor. Leaves the characters uninitialized.
658 constexpr AlignedCharArray() noexcept= default;
659
660 /// Constructor taking a character to initialize the buffer with.
661 /// @param fillChar The character to fill this local buffer with.
662 constexpr AlignedCharArray( TChar fillChar ) noexcept { Fill( fillChar ); }
663
664 /// Returns a pointer to the internal buffer.
665 /// @return A mutable pointer to the characters.
666 constexpr TChar* Buffer() noexcept { return buffer; }
667
668 /// Returns a pointer to the internal buffer.
669 /// @return A const pointer to the characters.
670 constexpr const TChar* Buffer() const noexcept { return buffer; }
671
672 /// Returns the number of characters in this buffer.
673 /// @return The value of template parameter \p{TLength}.
674 constexpr integer Length() const noexcept { return TLength; }
675
676 /// Fills the buffer with given \p{fillChar}.
677 /// @param fillChar The character to fill this local buffer with.
678 constexpr void Fill( TChar fillChar ) noexcept
679 { characters::Fill( buffer, TLength, fillChar); }
680};
681
682}
683
684/// Type alias in namespace \b alib.
685/// Note that the original struct has template parameters, which, for technical reasons can
686/// not be defaulted with this alias as they are defaulted in the original.
687/// Therefore this alias uses explicit defaults (which are not changeable).
689
690} // namespace [alib::character]
691
692
693#endif // HPP_ALIB_CHARACTERS_CHARARRAY
694
#define ALIB_WARNINGS_RESTORE
Definition alib.hpp:849
#define ALIB_API
Definition alib.hpp:639
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
Definition alib.hpp:760
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)
PLATFORM_SPECIFIC xchar
TChar ToUpper(TChar c)
void Reverse(TChar *src, integer length)
integer Length(const TChar *cstring)
integer LastIndexOfAnyInclude(const TChar *haystack, integer startIdx, const TChar *needles, integer needlesLength)
TChar ToLower(TChar c)
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
PLATFORM_SPECIFIC wchar
int CompareIgnoreCase(const TChar *lhs, const TChar *rhs, integer cmpLength)
Case
Denotes upper and lower case character treatment.
Definition alib.cpp:69
characters::nchar nchar
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:273
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