39 bool astringCheckReported=
false;
42template<
typename TChar>
43void TString<TChar>::dbgCheck()
const
46 if ( !astringCheckReported )
48 astringCheckReported=
true;
49 ALIB_MESSAGE(
"STRINGS",
"ALIB_DEBUG_STRINGS is enabled")
53 "Nulled string has a length of ",
int(length) )
56 for (
integer i= length -1 ; i >= 0 ; --i)
57 if ( buffer[i] ==
'\0' )
59 ALIB_ERROR(
"STRINGS",
"Found termination character '\\0' in buffer. Index=",
int(i) )
71template<
typename TChar>
72template<lang::Case TSensitivity>
79 ALIB_ASSERT_ERROR( startIdx >= 0 && startIdx <= length,
"STRINGS",
"Illegal start index given." )
80 ALIB_ASSERT_ERROR( endIdx <= length -nLen + 1 , "STRINGS", "Illegal end index given." )
82 const TChar* buf= buffer + startIdx;
83 const TChar* bufEnd= buffer + endIdx;
84 const TChar* nBuf= needle.Buffer();
85 const TChar* nBufEnd= nBuf + nLen;
87 while ( buf < bufEnd )
100template<
typename TChar>
104 while( idx < length )
107 if( buffer[idx] == opener ) ++openCnt;
108 if( buffer[idx] == closer && --openCnt == 0 )
115 return openCnt == 0 ? idx : -openCnt;
121template<
typename TChar>
128 if ( newIdx ==
nullptr )
129 indexPointer= &startIdx;
132 indexPointer= newIdx;
133 *indexPointer= startIdx;
140template<
typename TChar>
147 if ( newIdx ==
nullptr )
148 indexPointer= &startIdx;
151 indexPointer= newIdx;
152 *indexPointer= startIdx;
159template<
typename TChar>
166 if ( newIdx ==
nullptr )
167 indexPointer= &startIdx;
170 indexPointer= newIdx;
171 *indexPointer= startIdx;
178template<
typename TChar>
185 if ( newIdx ==
nullptr )
186 indexPointer= &startIdx;
189 indexPointer= newIdx;
190 *indexPointer= startIdx;
197template<
typename TChar>
204 if ( newIdx ==
nullptr )
205 indexPointer= &startIdx;
208 indexPointer= newIdx;
209 *indexPointer= startIdx;
216template<
typename TChar>
223 if ( newIdx ==
nullptr )
224 indexPointer= &startIdx;
227 indexPointer= newIdx;
228 *indexPointer= startIdx;
235template<
typename TChar>
242 if ( newIdx ==
nullptr )
243 indexPointer= &startIdx;
246 indexPointer= newIdx;
247 *indexPointer= startIdx;
264 const nchar* cs= buffer;
267 #if defined( _WIN32 )
269 int conversionSize= MultiByteToWideChar( CP_UTF8, 0, cs,
static_cast<int>( length ),
nullptr, 0 );
273 if ( conversionSize == 0 )
276 int error= GetLastError();
278 NString128 msg(
"AString: Conversion to wide character string failed (Error: " );
279 if ( error == ERROR_INSUFFICIENT_BUFFER ) msg._(
"ERROR_INSUFFICIENT_BUFFER." );
280 else if ( error == ERROR_INVALID_FLAGS ) msg._(
"ERROR_INVALID_FLAGS." );
281 else if ( error == ERROR_INVALID_PARAMETER ) msg._(
"ERROR_INVALID_PARAMETER" );
282 else if ( error == ERROR_NO_UNICODE_TRANSLATION ) msg._(
"ERROR_NO_UNICODE_TRANSLATION" );
290 if( conversionSize > length )
292 ALIB_ERROR(
"STRINGS",
"MBCS to WCS conversion failed. Conversion length=", conversionSize );
297 return conversionSize;
300 #elif defined (__GLIBCXX__) || defined(__APPLE__) || defined(__ANDROID_NDK__)
302 size_t conversionSize= mbsnrtowcs(
nullptr, &cs,
size_t(length), 0,
nullptr );
303 if ( conversionSize ==
size_t(-1) )
305 ALIB_WARNING(
"STRINGS",
"MBCS to WCS conversion failed. Illegal MBC sequence. Probably UTF-8 is not set in locale" )
310 NString128( "MBCS to WCS conversion failed. Conversion length=")
313 return static_cast<
integer>(conversionSize);
317 #pragma message ("Unknown Platform in file: " __FILE__ )
359 const xchar* src= buffer;
360 const xchar* srcEnd= buffer + length;
362#if ALIB_SIZEOF_WCHAR_T == 4
367 const char32_t uc =
static_cast<char32_t>( *src++ );
368 if ((uc - 0xd800) >= 2048)
374 && ((uc & 0xfffffc00) == 0xd800)
375 && ((
static_cast<char32_t>( *src++ ) & 0xfffffc00) == 0xdc00),
376 "STRINGS",
"Error decoding UTF16" )
391 || ( uc >= 0xe000 && uc <= 0x10ffff ),
"STRINGS",
392 "Illegal unicode 32 bit codepoint" )
422template<
typename TChar>
425 return std::hash<std::basic_string_view<TChar>>()(
426 std::basic_string_view<TChar>( Buffer(),
size_t(
Length() ) ) );
434template<
typename TChar>
437 std::size_t result= 68460391ul * ( size_t(length) + 1 );
440 auto* end = buffer + length;
441 while( begin != end )
442 result = 199ul * result + std::size_t(
ToUpper<TChar>( *begin++ ) );
453#if ALIB_DEBUG_STRINGS
454template void TString<nchar>::dbgCheck()
const;
455template void TString<wchar>::dbgCheck()
const;
456template void TString<xchar>::dbgCheck()
const;
integer IndexOfSegmentEnd(TChar opener, TChar closer, integer idx) const
ALIB_API uint64_t ParseHex(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
ALIB_API uint64_t ParseBin(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
std::size_t Hashcode() const
std::size_t HashcodeIgnoreCase() const
ALIB_API uint64_t ParseDec(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
ALIB_API double ParseFloat(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
ALIB_API int64_t ParseInt(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
ALIB_API integer indexOfString(const TString &needle, integer startIdx, integer endIdx) const
ALIB_API uint64_t ParseOct(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
ALIB_API uint64_t ParseDecDigits(integer startIdx=0, integer *newIdx=nullptr) const
integer WStringLength() const
#define ALIB_WARNING(...)
#define ALIB_MESSAGE(...)
#define ALIB_WARNINGS_RESTORE
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
integer Length(const TChar *cstring)
bool Equal(TChar lhs, TRhs rhs)
ALIB_API uint64_t ParseOct(const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf)
ALIB_API int64_t ParseInt(const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf)
ALIB_API uint64_t ParseHex(const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf)
ALIB_API uint64_t ParseBin(const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf)
uint64_t ParseDecDigits(const TString< TChar > &src, integer &idx)
ALIB_API double ParseFloat(const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf)
ALIB_API uint64_t ParseDec(const TString< TChar > &src, integer &idx, const TNumberFormat< TChar > &nf)
lang::uinteger uinteger
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.