27namespace alib {
namespace characters {
47#if defined(ALIB_CHARACTERS_NATIVE_WCHAR)
48# error "Preprocessor symbol ALIB_CHARACTERS_NATIVE_WCHAR must not be passed to the compiler. It is deduced in ALib headers."
85 #define A_NCHAR(STR) STR
88 #if ALIB_CHARACTERS_SIZEOF_WCHAR == ALIB_SIZEOF_WCHAR_T
90 # define ALIB_CHARACTERS_NATIVE_WCHAR 1
92 # if ALIB_CHARACTERS_SIZEOF_WCHAR == 2
93 using wchar = wchar_t;
94 using xchar = char32_t;
95 #define A_WCHAR(STR) L ## STR
96 #define A_XCHAR(STR) U ## STR
97 #define A_SCHAR(STR) U ## STR
99 using wchar = wchar_t;
100 using xchar = char16_t;
101 #define A_WCHAR(STR) L ## STR
102 #define A_XCHAR(STR) u ## STR
103 #define A_SCHAR(STR) u ## STR
108 # define ALIB_CHARACTERS_NATIVE_WCHAR 0
110 # if ALIB_CHARACTERS_SIZEOF_WCHAR == 2
111 using wchar = char16_t;
112 using xchar = wchar_t;
113 #define A_WCHAR(STR) u ## STR
114 #define A_XCHAR(STR) L ## STR
115 #define A_SCHAR(STR) L ## STR
117 using wchar = char32_t;
118 using xchar = wchar_t;
119 #define A_WCHAR(STR) U ## STR
120 #define A_XCHAR(STR) L ## STR
121 #define A_SCHAR(STR) L ## STR
176#elif !ALIB_CHARACTERS_WIDE
181 #define A_CHAR(STR) STR
182 #define A_CCHAR(STR) A_WCHAR(STR)
188 #define A_CHAR(STR) A_WCHAR(STR)
189 #define A_CCHAR(STR) STR
263template<
typename TString,
typename TChar,
typename TEnableIf=
void>
274 #if defined(ALIB_DOX)
292 const TChar*
Buffer(
const TString& src );
345template<
typename TString,
typename TChar,
typename TEnableIf=
void>
348 #if !defined(ALIB_DOX)
361 const TChar*
Buffer(
const TString& src );
404template<
typename TString,
typename TEnableIf=
void>
426template<
typename TString,
typename EnableIf=
void>
434#if !defined(ALIB_DOX)
435template<
typename T>
struct TT_CharArrayType <T, typename std::enable_if<characters::T_CharArray <T,nchar>::Access != AccessType::NONE>::type>: std::true_type {
using TChar=
nchar; };
436template<
typename T>
struct TT_CharArrayType <T, typename std::enable_if<characters::T_CharArray <T,wchar>::Access != AccessType::NONE>::type>: std::true_type {
using TChar=
wchar; };
437template<
typename T>
struct TT_CharArrayType <T, typename std::enable_if<characters::T_CharArray <T,xchar>::Access != AccessType::NONE>::type>: std::true_type {
using TChar=
xchar; };
438template<
typename T>
struct TT_ZTCharArrayType<T, typename std::enable_if<characters::T_ZTCharArray<T,nchar>::Access != AccessType::NONE>::type>: std::true_type {
using TChar=
nchar; };
439template<
typename T>
struct TT_ZTCharArrayType<T, typename std::enable_if<characters::T_ZTCharArray<T,wchar>::Access != AccessType::NONE>::type>: std::true_type {
using TChar=
wchar; };
440template<
typename T>
struct TT_ZTCharArrayType<T, typename std::enable_if<characters::T_ZTCharArray<T,xchar>::Access != AccessType::NONE>::type>: std::true_type {
using TChar=
xchar; };
448#if !defined(ALIB_DOX)
450#define ALIB_CHARACTER_ARRAY_internal( C_ZTC, TString, TChar, Const, pAccess, pConstruction) \
451template<> struct T_ ## C_ZTC ## harArray<TString, TChar> \
453 static constexpr AccessType Access= AccessType:: pAccess; \
454 static constexpr ConstructionType Construction= ConstructionType:: pConstruction; \
456 static inline const TChar* Buffer( TString Const & src ); \
457 static inline integer Length( TString Const & src ); \
459 static inline TString Construct( const TChar* array, integer length ); \
465#define ALIB_CHARACTER_ARRAY( TString, TChar, Access , Construction ) \
466ALIB_CHARACTER_ARRAY_internal( C , TString, TChar, const, Access , Construction )
468#define ALIB_CHARACTER_ARRAY_MUTABLE( TString, TChar, Construction ) \
469ALIB_CHARACTER_ARRAY_internal( C , TString, TChar, , MutableOnly, Construction )
471#define ALIB_CHARACTER_ZT_ARRAY( TString, TChar, Access , Construction ) \
472ALIB_CHARACTER_ARRAY_internal( ZTC, TString, TChar, const, Access , Construction )
474#define ALIB_CHARACTER_ZT_ARRAY_MUTABLE( TString, TChar, Construction ) \
475ALIB_CHARACTER_ARRAY_internal( ZTC, TString, TChar, , MutableOnly, Construction )
479#define ALIB_CHARACTER_ARRAY_IMPL_BUFFER( TString, TChar, ... ) \
480const TChar* T_CharArray<TString,TChar>::Buffer(TString const& src ) { __VA_ARGS__ }
482#define ALIB_CHARACTER_ARRAY_IMPL_LENGTH( TString, TChar, ... ) \
483integer T_CharArray<TString,TChar>::Length(TString const& src ) { __VA_ARGS__ }
485#define ALIB_CHARACTER_ARRAY_IMPL_BUFFER_MUTABLE( TString, TChar, ... ) \
486const TChar* T_CharArray<TString,TChar>::Buffer(TString & src ) { __VA_ARGS__ }
488#define ALIB_CHARACTER_ARRAY_IMPL_LENGTH_MUTABLE( TString, TChar, ... ) \
489integer T_CharArray<TString,TChar>::Length(TString & src ) { __VA_ARGS__ }
491#define ALIB_CHARACTER_ARRAY_IMPL_CONSTRUCT( TString, TChar, ... ) \
492 TString T_CharArray <TString,TChar>::Construct( const TChar* array, integer length ) { __VA_ARGS__ }
494#define ALIB_CHARACTER_ZT_ARRAY_IMPL_BUFFER( TString, TChar, ... ) \
495const TChar* T_ZTCharArray<TString,TChar>::Buffer( TString const& src ) { __VA_ARGS__ }
497#define ALIB_CHARACTER_ZT_ARRAY_IMPL_LENGTH( TString, TChar, ... ) \
498integer T_ZTCharArray<TString,TChar>::Length( TString const& src ) { __VA_ARGS__ }
500#define ALIB_CHARACTER_ZT_ARRAY_IMPL_BUFFER_MUTABLE(TString, TChar, ... ) \
501const TChar* T_ZTCharArray<TString,TChar>::Buffer( TString & src ) { __VA_ARGS__ }
503#define ALIB_CHARACTER_ZT_ARRAY_IMPL_LENGTH_MUTABLE(TString, TChar, ... ) \
504integer T_ZTCharArray<TString,TChar>::Length( TString & src ) { __VA_ARGS__ }
506#define ALIB_CHARACTER_ZT_ARRAY_IMPL_CONSTRUCT( TString, TChar, ... ) \
507 TString T_ZTCharArray<TString,TChar>::Construct( const TChar* array, integer length ) { __VA_ARGS__ }
514#if !defined(ALIB_DOX)
516template<
size_t TCapacity,
typename TChar>
517struct T_CharArray<TChar[TCapacity], TChar>
520 static constexpr const TChar*
Buffer( TChar
const (&src) [TCapacity] ) {
return src; }
521 static constexpr integer Length( TChar
const (& ) [TCapacity] ) {
return TCapacity -1; }
525template<
size_t TCapacity,
typename TChar>
526struct T_ZTCharArray<TChar[TCapacity], TChar>
529 static constexpr const TChar*
Buffer( TChar
const (&src) [TCapacity] ) {
return src; }
530 static constexpr integer Length( TChar
const (& ) [TCapacity] ) {
return TCapacity -1; }
534template<
typename TChar>
struct T_CharArray<TChar const*, TChar>
538 static constexpr const TChar* Buffer(
const TChar*
const & src ) {
return src; }
539 static constexpr integer Length(
const TChar*
const & src ) {
return src ?
static_cast<integer>( std::char_traits<TChar>::length(src) ) : 0; }
540 static constexpr const TChar* Construct(
const TChar* array,
integer ) {
return array; }
543template<
typename TChar>
struct T_ZTCharArray<TChar const*, TChar>
547 static constexpr const TChar* Buffer(
const TChar*
const & src ) {
return src; }
548 static constexpr integer Length(
const TChar*
const & src ) {
return src ?
static_cast<integer>( std::char_traits<TChar>::length(src) ) : 0; }
549 static constexpr const TChar* Construct(
const TChar* array,
integer ) {
return array; }
553template<
typename TChar>
struct T_CharArray<TChar*, TChar>
557 static constexpr const TChar* Buffer( TChar*
const & src ) {
return src; }
558 static constexpr integer Length( TChar*
const & src ) {
return src ?
static_cast<integer>( std::char_traits<TChar>::length(src) ) : 0; }
559 static constexpr TChar* Construct(
const TChar* array,
integer ) {
return const_cast<TChar*
>( array ); }
563template<
typename TChar>
struct T_ZTCharArray<TChar*, TChar>
567 static constexpr const TChar* Buffer( TChar*
const & src ) {
return src; }
568 static constexpr integer Length( TChar*
const & src ) {
return src ?
static_cast<integer>( std::char_traits<TChar>::length(src) ) : 0; }
569 static constexpr TChar* Construct(
const TChar* array,
integer ) {
return const_cast<TChar*
>( array ); }
594#if !defined(ALIB_DOX)
599#define ATMP_CHAR_COMPLEMENT( TChar ) typename TT_ComplementChar<TChar>::type
620 #if defined(ALIB_DOX)
627#if !defined(ALIB_DOX)
629template<>
struct TT_CharOfSize<sizeof(
wchar)> :
public std::true_type {
using type=
wchar; };
630template<>
struct TT_CharOfSize<sizeof(
xchar)> :
public std::true_type {
using type=
xchar; };
644template<
typename TChar>
struct TT_IsChar :
public std::false_type {};
646#if !defined(ALIB_DOX)
648template<>
struct TT_IsChar<
wchar> :
public std::true_type {};
649template<>
struct TT_IsChar<
xchar> :
public std::true_type {};