30template <
typename In,
typename Out>
41 if (wctomb(&Char,
static_cast<wchar_t>(*Begin++)) >= 0)
44 *Output++ = Replacement;
50 const std::ctype<wchar_t>& Facet = std::use_facet< std::ctype<wchar_t> >(Locale);
54 *Output++ = Facet.narrow(
static_cast<wchar_t>(*Begin++), Replacement);
66template <
typename In,
typename Out>
77 mbtowc(&Char, &*Begin, 1);
79 *Output++ =
static_cast<Uint32
>(Char);
85 const std::ctype<wchar_t>& Facet = std::use_facet< std::ctype<wchar_t> >(Locale);
89 *Output++ =
static_cast<Uint32
>(Facet.widen(*Begin++));
101template <
typename In,
typename Out>
107 int TrailingBytes = UTF8TrailingBytes[
static_cast<int>(*Begin)];
108 if (Begin + TrailingBytes < End)
111 switch (TrailingBytes)
113 case 5 : c += *Begin++; c <<= 6;
114 case 4 : c += *Begin++; c <<= 6;
115 case 3 : c += *Begin++; c <<= 6;
116 case 2 : c += *Begin++; c <<= 6;
117 case 1 : c += *Begin++; c <<= 6;
118 case 0 : c += *Begin++;
120 c -= UTF8Offsets[TrailingBytes];
126 if ((c >= 0xD800) && (c <= 0xDFFF))
130 *Output++ = Replacement;
135 *Output++ =
static_cast<Uint16
>(c);
138 else if (c > 0x0010FFFF)
142 *Output++ = Replacement;
148 *Output++ =
static_cast<Uint16
>((c >> 10) + 0xD800);
149 *Output++ =
static_cast<Uint16
>((c & 0x3FFUL) + 0xDC00);
162template <
typename In,
typename Out>
168 int TrailingBytes = UTF8TrailingBytes[
static_cast<int>(*Begin)];
169 if (Begin + TrailingBytes < End)
172 switch (TrailingBytes)
174 case 5 : c += *Begin++; c <<= 6;
175 case 4 : c += *Begin++; c <<= 6;
176 case 3 : c += *Begin++; c <<= 6;
177 case 2 : c += *Begin++; c <<= 6;
178 case 1 : c += *Begin++; c <<= 6;
179 case 0 : c += *Begin++;
181 c -= UTF8Offsets[TrailingBytes];
184 if ((c < 0xD800) || (c > 0xDFFF))
193 *Output++ = Replacement;
206template <
typename In,
typename Out>
214 if ((c >= 0xD800) && (c <= 0xDBFF))
220 if ((d >= 0xDC00) && (d <= 0xDFFF))
221 c =
static_cast<Uint32
>(((c - 0xD800) << 10) + (d - 0xDC00) + 0x0010000);
227 *Output++ = Replacement;
236 *Output++ = Replacement;
243 int BytesToWrite = 1;
244 if (c < 0x80) BytesToWrite = 1;
245 else if (c < 0x800) BytesToWrite = 2;
246 else if (c < 0x10000) BytesToWrite = 3;
247 else if (c <= 0x0010FFFF) BytesToWrite = 4;
251 switch (BytesToWrite)
253 case 4 : Bytes[3] =
static_cast<Uint8
>((c | 0x80) & 0xBF); c >>= 6;
254 case 3 : Bytes[2] =
static_cast<Uint8
>((c | 0x80) & 0xBF); c >>= 6;
255 case 2 : Bytes[1] =
static_cast<Uint8
>((c | 0x80) & 0xBF); c >>= 6;
256 case 1 : Bytes[0] =
static_cast<Uint8
> (c | UTF8FirstBytes[BytesToWrite]);
260 const Uint8* CurByte = Bytes;
261 switch (BytesToWrite)
263 case 4 : *Output++ = *CurByte++;
264 case 3 : *Output++ = *CurByte++;
265 case 2 : *Output++ = *CurByte++;
266 case 1 : *Output++ = *CurByte++;
279template <
typename In,
typename Out>
285 if ((c >= 0xD800) && (c <= 0xDBFF))
291 if ((d >= 0xDC00) && (d <= 0xDFFF))
294 *Output++ =
static_cast<Uint32
>(((c - 0xD800) << 10) + (d - 0xDC00) + 0x0010000);
300 *Output++ = Replacement;
304 else if ((c >= 0xDC00) && (c <= 0xDFFF))
308 *Output++ = Replacement;
313 *Output++ =
static_cast<Uint32
>(c);
325template <
typename In,
typename Out>
335 *Output++ = Replacement;
342 int BytesToWrite = 1;
343 if (c < 0x80) BytesToWrite = 1;
344 else if (c < 0x800) BytesToWrite = 2;
345 else if (c < 0x10000) BytesToWrite = 3;
346 else if (c <= 0x0010FFFF) BytesToWrite = 4;
350 switch (BytesToWrite)
352 case 4 : Bytes[3] =
static_cast<Uint8
>((c | 0x80) & 0xBF); c >>= 6;
353 case 3 : Bytes[2] =
static_cast<Uint8
>((c | 0x80) & 0xBF); c >>= 6;
354 case 2 : Bytes[1] =
static_cast<Uint8
>((c | 0x80) & 0xBF); c >>= 6;
355 case 1 : Bytes[0] =
static_cast<Uint8
> (c | UTF8FirstBytes[BytesToWrite]);
359 const Uint8* CurByte = Bytes;
360 switch (BytesToWrite)
362 case 4 : *Output++ = *CurByte++;
363 case 3 : *Output++ = *CurByte++;
364 case 2 : *Output++ = *CurByte++;
365 case 1 : *Output++ = *CurByte++;
378template <
typename In,
typename Out>
387 if ((c >= 0xD800) && (c <= 0xDFFF))
391 *Output++ = Replacement;
396 *Output++ =
static_cast<Uint16
>(c);
399 else if (c > 0x0010FFFF)
403 *Output++ = Replacement;
409 *Output++ =
static_cast<Uint16
>((c >> 10) + 0xD800);
410 *Output++ =
static_cast<Uint16
>((c & 0x3FFUL) + 0xDC00);
421template <
typename In>
424 std::size_t Length = 0;
427 int NbBytes = UTF8TrailingBytes[
static_cast<int>(*Begin)];
428 if (Begin + NbBytes < End)
431 Begin += NbBytes + 1;
441template <
typename In>
444 std::size_t Length = 0;
447 if ((*Begin >= 0xD800) && (*Begin <= 0xDBFF))
450 if ((Begin < End) && ((*Begin >= 0xDC00) && (*Begin <= 0xDFFF)))
470template <
typename In>
static Out ANSIToUTF32(In Begin, In End, Out Output, const std::locale &Locale=GetDefaultLocale())
Generic function to convert an ANSI characters range to an UTF-32 characters range,...
static std::size_t GetUTF16Length(In Begin, In End)
Get the number of characters composing an UTF-16 string.
static Out UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement='?')
Generic function to convert an UTF-8 characters range to an UTF-16 characters range,...
static Out UTF32ToUTF8(In Begin, In End, Out Output, Uint8 Replacement='?')
Generic function to convert an UTF-32 characters range to an UTF-8 characters range,...
static Out UTF16ToUTF32(In Begin, In End, Out Output, Uint32 Replacement='?')
Generic function to convert an UTF-16 characters range to an UTF-32 characters range,...
static std::size_t GetUTF32Length(In Begin, In End)
Get the number of characters composing an UTF-32 string.
static Out UTF16ToUTF8(In Begin, In End, Out Output, Uint8 Replacement='?')
Generic function to convert an UTF-16 characters range to an UTF-8 characters range,...
static Out UTF32ToANSI(In Begin, In End, Out Output, char Replacement='?', const std::locale &Locale=GetDefaultLocale())
Generic function to convert an UTF-32 characters range to an ANSI characters range,...
static Out UTF32ToUTF16(In Begin, In End, Out Output, Uint16 Replacement='?')
Generic function to convert an UTF-32 characters range to an UTF-16 characters range,...
static std::size_t GetUTF8Length(In Begin, In End)
Get the number of characters composing an UTF-8 string.
static Out UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement='?')
Generic function to convert an UTF-8 characters range to an UTF-32 characters range,...