60 inline explicit DtUnicodeChar(
const unsigned short s,
const unsigned short c )
65 throw std::invalid_argument(
"UTF-16 characters are not a surrogate pair." );
74 template <
int sizeof_
wchar_t>
97 && codePoint != 0xfffe && codePoint != 0xffff );
105 if (
TrailSurrogateMin == ((*substringStart)&0xfffffc00) && start != substringStart
132 throw std::invalid_argument(
"Not a valid UTF 32 code point" );
158 template <
int sizeofWChar_t>
176 CodePoint X = (hi & 0x3F) << 10 | (lo & 0x3FF);
180 return (U << 16) | X;
188 | (
unsigned short)((cp >> 10) & 0x3F);
239 static inline unsigned int utf8Length(
const unsigned char c )
258 throw std::invalid_argument(
"Not a valid UTF8 string.");
261 inline unsigned int readUtf8(
const unsigned char* memory )
263 unsigned char c = *memory;
271 myCodePoint = ((c & 0x1F) << 6) | (*(memory + 1) & 0x3F);
276 myCodePoint = ((c & 0xF) << 12) | ((*(memory + 1) & 0x3F) << 6)
277 | (*(memory + 2) & 0x3F);
283 | ((*(memory + 1) & 0x3F) << 12)
284 | ((*(memory + 2) & 0x3F) << 6)
285 | (*(memory + 3) & 0x3F);
289 throw std::invalid_argument(
"Not a valid UTF8 string.");
300 *memory = (
unsigned char)((
myCodePoint >> 6) & 0x1F) | 0xC0;
301 *(memory+1) = (
unsigned char)((
myCodePoint) & 0x3F) | 0x80;
306 *memory = (
unsigned char)((
myCodePoint >> 12) & 0xF ) | 0xE0;
307 *(memory+1) = (
unsigned char)((
myCodePoint >> 6) & 0x3F) | 0x80;
308 *(memory+2) = (
unsigned char)((
myCodePoint ) & 0x3F) | 0x80;
312 *memory = (
unsigned char)((
myCodePoint >> 18) & 0x7 ) | 0xF0;
313 *(memory+1) = (
unsigned char)((
myCodePoint >> 12) & 0x3F) | 0x80;
314 *(memory+2) = (
unsigned char)((
myCodePoint >> 6 ) & 0x3F) | 0x80;
315 *(memory+3) = (
unsigned char)((
myCodePoint ) & 0x3F) | 0x80;
319 template <
int sizeofW
chart>
322 inline void writeWChar(
wchar_t* memory )
const;
344 inline unsigned int DtUnicodeChar::wchartLength<2>()
const
346 return utf16CodeUnits() << 1;
350 inline unsigned int DtUnicodeChar::wchartLength<4>()
const
352 return utf32Length();
357 return wchartLength<sizeof(wchar_t)>();
361 template <
int sizeof_
wchar_t>
370 if ( isSurrogate(c) )
372 throw std::invalid_argument(
"Invalid UTF-16 character" );
379 inline void DtUnicodeChar::writeWCharT<2>(
wchar_t* memory )
const
381 writeUtf16( reinterpret_cast<Surrogate*>(memory) );
385 inline void DtUnicodeChar::writeWCharT<4>(
wchar_t* memory )
const
387 writeUtf32( reinterpret_cast<unsigned int*>(memory) );
392 writeWCharT<sizeof(wchar_t)>( memory );