10#if !defined (HPP_ALIB_STRINGS_STRING)
14#if !defined (HPP_ALIB_STRINGS_DETAIL_NUMBERCONVERSION)
18#if ALIB_DEBUG && !defined(HPP_ALIB_STRINGS_LOCALSTRING)
45 bool astringCheckReported=
false;
48template<
typename TChar>
49void TString<TChar>::dbgCheck()
const
52 if ( !astringCheckReported )
54 astringCheckReported=
true;
55 ALIB_MESSAGE(
"STRINGS",
"ALIB_DEBUG_STRINGS is enabled")
59 "Nulled string has a length of ",
int(length) )
62 for (
integer i= length -1 ; i >= 0 ; --i)
63 if ( buffer[i] ==
'\0' )
65 ALIB_ERROR(
"STRINGS",
"Found termination character '\\0' in buffer. Index=",
int(i) )
77template<
typename TChar>
78template<lang::Case TSensitivity>
85 const TChar* buf= buffer + startIdx;
86 const TChar* bufEnd= buffer + length - nLen + 1;
87 const TChar* nBuf= needle.Buffer();
88 const TChar* nBufEnd= nBuf + nLen;
90 while ( buf < bufEnd )
103template<
typename TChar>
107 while( idx < length )
110 if( buffer[idx] == opener ) ++openCnt;
111 if( buffer[idx] == closer )
118 return openCnt == 0 ? idx : -openCnt;
124template<
typename TChar>
131 if ( newIdx ==
nullptr )
132 indexPointer= &startIdx;
135 indexPointer= newIdx;
136 *indexPointer= startIdx;
139 return detail::ParseDecDigits<TChar>( *
this, *indexPointer );
143template<
typename TChar>
150 if ( newIdx ==
nullptr )
151 indexPointer= &startIdx;
154 indexPointer= newIdx;
155 *indexPointer= startIdx;
162template<
typename TChar>
169 if ( newIdx ==
nullptr )
170 indexPointer= &startIdx;
173 indexPointer= newIdx;
174 *indexPointer= startIdx;
181template<
typename TChar>
188 if ( newIdx ==
nullptr )
189 indexPointer= &startIdx;
192 indexPointer= newIdx;
193 *indexPointer= startIdx;
200template<
typename TChar>
207 if ( newIdx ==
nullptr )
208 indexPointer= &startIdx;
211 indexPointer= newIdx;
212 *indexPointer= startIdx;
219template<
typename TChar>
226 if ( newIdx ==
nullptr )
227 indexPointer= &startIdx;
230 indexPointer= newIdx;
231 *indexPointer= startIdx;
238template<
typename TChar>
245 if ( newIdx ==
nullptr )
246 indexPointer= &startIdx;
249 indexPointer= newIdx;
250 *indexPointer= startIdx;
267 const nchar* cs= buffer;
270 #if defined( _WIN32 )
272 int conversionSize= MultiByteToWideChar( CP_UTF8, 0, cs,
static_cast<int>( length ),
nullptr, 0 );
276 if ( conversionSize == 0 )
279 int error= GetLastError();
281 NString128 msg(
"AString: Conversion to wide character string failed (Error: " );
282 if ( error == ERROR_INSUFFICIENT_BUFFER ) msg._(
"ERROR_INSUFFICIENT_BUFFER." );
283 else if ( error == ERROR_INVALID_FLAGS ) msg._(
"ERROR_INVALID_FLAGS." );
284 else if ( error == ERROR_INVALID_PARAMETER ) msg._(
"ERROR_INVALID_PARAMETER" );
285 else if ( error == ERROR_NO_UNICODE_TRANSLATION ) msg._(
"ERROR_NO_UNICODE_TRANSLATION" );
293 if( conversionSize > length )
295 ALIB_ERROR(
"STRINGS",
"MBCS to WCS conversion failed. Conversion length=", conversionSize );
300 return conversionSize;
303 #elif defined (__GLIBCXX__) || defined(__APPLE__) || defined(__ANDROID_NDK__)
305 size_t conversionSize= mbsnrtowcs(
nullptr, &cs,
static_cast<size_t>(length), 0,
nullptr );
306 if ( conversionSize ==
static_cast<size_t>(-1) )
308 ALIB_WARNING(
"STRINGS",
"MBCS to WCS conversion failed. Illegal MBC sequence. Probably UTF-8 is not set in locale" )
313 NString128( "MBCS to WCS conversion failed. Conversion length=")
316 return static_cast<
integer>(conversionSize);
320 #pragma message ("Unknown Platform in file: " __FILE__ )
326template integer TString<nchar>::indexOfString<lang::Case::Sensitive>(
const TString<nchar>&,
integer)
const;
327template integer TString<nchar>::indexOfString<lang::Case::Ignore >(
const TString<nchar>&,
integer)
const;
341template integer TString<wchar>::indexOfString<lang::Case::Sensitive>(
const TString<wchar>&,
integer)
const;
342template integer TString<wchar>::indexOfString<lang::Case::Ignore >(
const TString<wchar>&,
integer)
const;
362 const xchar* src= buffer;
363 const xchar* srcEnd= buffer + length;
365#if ALIB_SIZEOF_WCHAR_T == 4
370 const char32_t uc =
static_cast<char32_t>( *src++ );
371 if ((uc - 0xd800) >= 2048)
377 && ((uc & 0xfffffc00) == 0xd800)
378 && ((
static_cast<char32_t>( *src++ ) & 0xfffffc00) == 0xdc00),
379 "STRINGS",
"Error decoding UTF16" )
394 || ( uc >= 0xe000 && uc <= 0x10ffff ),
"STRINGS",
395 "Illegal unicode 32 bit codepoint" )
411template integer TString<xchar>::indexOfString<lang::Case::Sensitive>(
const TString<xchar>&,
integer)
const;
412template integer TString<xchar>::indexOfString<lang::Case::Ignore >(
const TString<xchar>&,
integer)
const;
425template<
typename TChar>
428 return std::hash<std::basic_string_view<TChar>>()(
429 std::basic_string_view<TChar>( Buffer(),
static_cast<size_t>( Length() ) ) );
437template<
typename TChar>
440 std::size_t result= 68460391ul * (
static_cast<size_t>(length) + 1 );
443 auto* end = buffer + length;
444 while( begin != end )
456#if ALIB_DEBUG_STRINGS
457template void TString<nchar>::dbgCheck()
const;
458template void TString<wchar>::dbgCheck()
const;
459template void TString<xchar>::dbgCheck()
const;
ALIB_API integer indexOfString(const TString &needle, integer startIdx) 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 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
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)
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)
ALIB_API CString EMPTY_STRING
A global instance of a nulled zero-terminated string of standard character size.
ALIB_API WCString EMPTY_W_STRING
A global instance of a nulled zero-terminated string of wide character size.
WString NULL_W_STRING
A global instance of a nulled string of wide character size.
lang::uinteger uinteger
Type alias in namespace alib.
ComplementString NULL_COMPLEMENT_STRING
A global instance of a nulled string of complementary character size.
ALIB_API NCString EMPTY_N_STRING
A global instance of a nulled zero-terminated string of wide character size.
NString NULL_N_STRING
A global instance of a nulled string of wide character size.
ALIB_API XString EMPTY_X_STRING
A global instance of a nulled zero-terminated string of strange character size.
XString NULL_X_STRING
A global instance of a nulled string of strange character size.
StrangeString NULL_STRANGE_STRING
A global instance of a nulled string of strange character size.
String NULL_STRING
A global instance of a nulled string of standard character size.
ALIB_API StrangeCString EMPTY_STRANGE_STRING
A global instance of a nulled zero-terminated string of strange character size.
ALIB_API ComplementCString EMPTY_COMPLEMENT_STRING
A global instance of a nulled zero-terminated string of complementary character size.
lang::integer integer
Type alias in namespace alib.