9#if !defined(HPP_ALIB_STRINGS_TASTRING_INLINING)
10# error "ALib sources with ending '.inl' must not be included from outside."
27#if !defined(ASTR_TCHAR_SPEC)
28# error "Preprocessor symbol ASTR_TCHAR_SPEC has to be given as ALIB_CHAR_TYPE_ID_XYZ before invoking this .INL"
30#if !defined(ASTR_TALLOC_SPEC)
31# error "Preprocessor symbol ASTR_TCHAR_SPEC has to be given as ALIB_CHAR_TYPE_ID_XYZ before invoking this .INL"
35#if ASTR_TCHAR_SPEC == ALIB_CHAR_TYPE_ID_N
36# define TCHARNAME nchar
37#elif ASTR_TCHAR_SPEC == ALIB_CHAR_TYPE_ID_W
38# define TCHARNAME wchar
39#elif ASTR_TCHAR_SPEC == ALIB_CHAR_TYPE_ID_X
40# define TCHARNAME xchar
63#if ALIB_EXT_LIB_THREADS_AVAILABLE
74template void T_Append<TFormat<TCHARNAME> , TCHARNAME, ASTR_TALLOC_SPEC>::operator()( TAString<TCHARNAME, ASTR_TALLOC_SPEC>&,
const TFormat<TCHARNAME>& );
75template void T_Append<TFormat<TCHARNAME>::Tab , TCHARNAME, ASTR_TALLOC_SPEC>::operator()( TAString<TCHARNAME, ASTR_TALLOC_SPEC>&,
const TFormat<TCHARNAME>::Tab& );
76template void T_Append<TFormat<TCHARNAME>::Field , TCHARNAME, ASTR_TALLOC_SPEC>::operator()( TAString<TCHARNAME, ASTR_TALLOC_SPEC>&,
const TFormat<TCHARNAME>::Field& );
77template void T_Append<TFormat<TCHARNAME>::Escape, TCHARNAME, ASTR_TALLOC_SPEC>::operator()( TAString<TCHARNAME, ASTR_TALLOC_SPEC>&,
const TFormat<TCHARNAME>::Escape& );
78template void T_Append<TFormat<TCHARNAME>::Bin , TCHARNAME, ASTR_TALLOC_SPEC>::operator()( TAString<TCHARNAME, ASTR_TALLOC_SPEC>&,
const TFormat<TCHARNAME>::Bin& );
79template void T_Append<TFormat<TCHARNAME>::Hex , TCHARNAME, ASTR_TALLOC_SPEC>::operator()( TAString<TCHARNAME, ASTR_TALLOC_SPEC>&,
const TFormat<TCHARNAME>::Hex& );
80template void T_Append<TFormat<TCHARNAME>::Oct , TCHARNAME, ASTR_TALLOC_SPEC>::operator()( TAString<TCHARNAME, ASTR_TALLOC_SPEC>&,
const TFormat<TCHARNAME>::Oct& );
81template void T_Append<TFormat<TCHARNAME>::Fill , TCHARNAME, ASTR_TALLOC_SPEC>::operator()( TAString<TCHARNAME, ASTR_TALLOC_SPEC>&,
const TFormat<TCHARNAME>::Fill& );
98#define CHECKING_VERSION_IMPLEMENTATION_OF_APPEND(TChar,TAllocator,TCharParam) \
99 template<> template<> \
101 TAString<TChar,TAllocator>& TAString<TChar,TAllocator>::Append<CHK> ( const TCharParam* src, integer srcLength ) \
103 if( !src ) return *this; \
104 if ( srcLength <= 0 ) \
106 if ( base::IsNull() ) \
110 return Append<NC>( src, srcLength ); \
115#if ALIB_CHARACTERS_NATIVE_WCHAR
116# define REAL_WCHAR wchar
117# define REAL_XCHAR xchar
119# define REAL_WCHAR xchar
120# define REAL_XCHAR wchar
129#if ( (ASTR_TCHAR_SPEC == ALIB_CHAR_TYPE_ID_W) && ALIB_CHARACTERS_NATIVE_WCHAR ) || ( (ASTR_TCHAR_SPEC == ALIB_CHAR_TYPE_ID_X) && !ALIB_CHARACTERS_NATIVE_WCHAR )
137 EnsureRemainingCapacity( srcLength );
140 #if defined( _WIN32 )
143 integer conversionSize= MultiByteToWideChar( CP_UTF8, 9,
144 src,
static_cast<int>( srcLength ),
145 vbuffer + length,
static_cast<int>( Capacity() - length ) );
148 if ( conversionSize == 0 )
151 int error= GetLastError();
154 "MBCS to WCS conversion failed (Error: ",
155 ( error == ERROR_INSUFFICIENT_BUFFER ?
"ERROR_INSUFFICIENT_BUFFER."
156 : error == ERROR_INVALID_FLAGS ?
"ERROR_INVALID_FLAGS."
157 : error == ERROR_INVALID_PARAMETER ?
"ERROR_INVALID_PARAMETER"
158 : error == ERROR_NO_UNICODE_TRANSLATION ?
"ERROR_NO_UNICODE_TRANSLATION"
164 NString128(
"MBCS to WCS conversion failed. Requested length=" )._( srcLength )
165 ._(
", conversion length=" )._(conversionSize)
169 length+= conversionSize;
174 #elif defined (__GLIBCXX__) || defined(__APPLE__) || defined(__ANDROID_NDK__)
176 while(srcLength > 0 )
178 integer actConversionLenght= srcLength;
179 for(
int pass= 0 ; pass < 2 ; ++pass )
182 mbstate_t ps; memset( &ps, 0,
sizeof(mbstate_t) );
183 const nchar* srcp= src;
184 size_t wcWritten= mbsnrtowcs( vbuffer + length, &srcp,
185 size_t(actConversionLenght),
186 size_t(Capacity() - length), &ps );
189 if( wcWritten ==
static_cast<size_t >(-1) )
200 *(vbuffer + length++)=
'?';
205 actConversionLenght= srcp - src;
211 srcLength-= actConversionLenght;
218 #pragma message ("Unknown Platform in file: " __FILE__ )
222CHECKING_VERSION_IMPLEMENTATION_OF_APPEND(
wchar_t, ASTR_TALLOC_SPEC,
char )
225#if ALIB_SIZEOF_WCHAR_T == 4
232 EnsureRemainingCapacity( srcLength );
235 const char16_t* srcEnd= src + srcLength;
238 const char32_t uc = *src++;
239 if ((uc - 0xd800) >= 2048)
241 vbuffer[length++] =
static_cast<wchar_t>(uc);
246 && ((uc & 0xfffffc00) == 0xd800)
247 && ((*src & 0xfffffc00) == 0xdc00),
248 "STRINGS",
"Error decoding UTF16" )
250 vbuffer[length++]= static_cast<
wchar_t>( (uc << 10)
251 + ((*src++) - 0x35fdc00 ) );
258 CHECKING_VERSION_IMPLEMENTATION_OF_APPEND(
wchar_t, ASTR_TALLOC_SPEC,
char16_t )
267 EnsureRemainingCapacity( srcLength * 2 );
269 const char32_t* srcEnd= src + srcLength;
274 || ( uc >= 0xe000 && uc <= 0x10ffff ),
275 "STRINGS",
"Illegal unicode 32 bit codepoint" )
279 vbuffer[length++]=
static_cast<wchar_t>( uc );
284 vbuffer[length++]=
static_cast<wchar_t>( ( uc >> 10 ) + 0xd800 );
285 vbuffer[length++]=
static_cast<wchar_t>( ( uc & 0x3ff ) + 0xdc00 );
292 CHECKING_VERSION_IMPLEMENTATION_OF_APPEND(
wchar_t, ASTR_TALLOC_SPEC,
char32_t )
302#if ASTR_TCHAR_SPEC == ALIB_CHAR_TYPE_ID_X
304#if ALIB_SIZEOF_WCHAR_T == 2
306 template<>
template<>
310 EnsureRemainingCapacity( srcLength );
313 const wchar_t* srcEnd= src + srcLength;
316 const char32_t uc = *src++;
317 if ((uc - 0xd800) >= 2048)
319 vbuffer[length++] =
static_cast<REAL_XCHAR
>(uc);
324 && ((uc & 0xfffffc00) == 0xd800)
325 && ((*src & 0xfffffc00) == 0xdc00),
326 "STRINGS",
"Error decoding UTF16" )
328 vbuffer[length++]= static_cast<REAL_XCHAR>( (uc << 10)
329 + ((*src++) - 0x35fdc00 ) );
338 template<>
template<>
343 EnsureRemainingCapacity( srcLength * 2 );
345 const wchar_t* srcEnd= src + srcLength;
350 || ( uc >= 0xe000 && uc <= 0x10ffff ),
351 "STRINGS",
"Illegal unicode 32 bit codepoint" )
355 vbuffer[length++]=
static_cast<REAL_XCHAR
>( uc );
360 vbuffer[length++]=
static_cast<REAL_XCHAR
>( ( uc >> 10 ) + 0xd800 );
361 vbuffer[length++]=
static_cast<REAL_XCHAR
>( ( uc & 0x3ff ) + 0xdc00 );
376 TLocalString<REAL_WCHAR,8192> converter;
377 converter.Append<NC>( src, srcLength );
378 return Append<NC>( converter.Buffer(), converter.Length() );
381CHECKING_VERSION_IMPLEMENTATION_OF_APPEND(REAL_XCHAR , ASTR_TALLOC_SPEC,
char )
382CHECKING_VERSION_IMPLEMENTATION_OF_APPEND(REAL_XCHAR , ASTR_TALLOC_SPEC,
wchar_t )
389#if ASTR_TCHAR_SPEC == ALIB_CHAR_TYPE_ID_N
401 #if defined( _WIN32 )
404 EnsureRemainingCapacity( srcLength * 2 );
407 int conversionSize= WideCharToMultiByte( CP_UTF8, 0,
408 src,
static_cast<int>( srcLength),
409 TString<nchar>::vbuffer + TString<nchar>::length,
static_cast<int>( Capacity() - TString<nchar>::length ),
411 if ( conversionSize > 0 )
413 TString<nchar>::length+= conversionSize;
418 int error= GetLastError();
419 if (error == ERROR_INSUFFICIENT_BUFFER )
421 EnsureRemainingCapacity( srcLength );
427 "AString: Cannot convert wide character string to UTF-8. Error: ",
428 ( error == ERROR_INVALID_FLAGS ?
"ERROR_INVALID_FLAGS."
429 : error == ERROR_INVALID_PARAMETER ?
"ERROR_INVALID_PARAMETER"
430 : error == ERROR_NO_UNICODE_TRANSLATION ?
"ERROR_NO_UNICODE_TRANSLATION"
438 #elif defined (__GLIBCXX__) || defined(__APPLE__) || defined(__ANDROID_NDK__)
443 EnsureRemainingCapacity( maxConversionSize );
444 memset( &ps, 0,
sizeof(mbstate_t) );
445 const wchar_t* srcp= src;
446 size_t conversionSize= wcsnrtombs( TString<nchar>::vbuffer + TString<nchar>::length, &srcp,
size_t(srcLength),
size_t(maxConversionSize), &ps);
447 if ( conversionSize ==
size_t( -1 ) )
449 ALIB_WARNING(
"STRINGS",
"Cannot convert WCS to MBCS. Check locale settings (should be UTF-8)" )
453 if ( conversionSize < 1 )
455 ALIB_ERROR(
"STRINGS",
"Error converting WCS to MBCS." )
459 TString<
nchar>::length+= conversionSize;
463 #pragma message ("Unknown Platform in file: " __FILE__ )
474 TLocalString<wchar_t,2048> converter;
476 converter.Append<NC>( src, srcLength );
477 Append<NC>( converter.Buffer(), converter.Length() );
482CHECKING_VERSION_IMPLEMENTATION_OF_APPEND(
char , ASTR_TALLOC_SPEC,
wchar )
483CHECKING_VERSION_IMPLEMENTATION_OF_APPEND(
char , ASTR_TALLOC_SPEC,
xchar )
493#undef CHECKING_VERSION_IMPLEMENTATION_OF_APPEND
497#undef ASTR_TALLOC_SPEC
498#undef ASTR_TCHAR_SPEC
ALIB_API integer SearchAndReplace(TChar needle, TChar replacement, integer startIdx=0, integer endIdx=strings::MAX_LEN)
ALIB_API void GrowBufferAtLeastBy(integer minimumGrowth)
TAString & Append(const TCharSrc *src, integer srcLength)
ALIB_API integer TrimAt(integer idx, const TCString< TChar > &trimChars=TT_CStringConstants< TChar >::DefaultWhitespaces())
ALIB_API TAString & Trim(const TCString< TChar > &trimChars=TT_CStringConstants< TChar >::DefaultWhitespaces())
void DbgDisableBufferReplacementWarning()
ALIB_API void SetBuffer(integer newCapacity)
#define ALIB_WARNING(...)
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_IGNORE_SIGN_CONVERSION
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
#define ALIB_STRING_DBG_CHK(instance)
#define ALIB_ASSERT(cond)
Case
Denotes upper and lower case character treatment.
NLocalString< 128 > NString128
Type alias name for TLocalString<nchar,128>.
lang::uinteger uinteger
Type alias in namespace alib.
NLocalString< 64 > NString64
Type alias name for TLocalString<nchar,64>.
characters::wchar wchar
Type alias in namespace alib.
characters::xchar xchar
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
void operator()(TAString< TChar > &target, const TAppendable &src)