28 #include <SFML/System/Unicode.hpp>
50 std::size_t StrLen(
const T* Str)
52 std::size_t Length = 0;
53 while (*Str++) Length++;
60 std::locale GetCurrentLocale()
64 return std::locale(
"");
66 catch (std::runtime_error&)
81 const int Unicode::UTF8TrailingBytes[256] =
83 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
84 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
86 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
89 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
90 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5
92 const Uint32 Unicode::UTF8Offsets[6] =
94 0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080
96 const Uint8 Unicode::UTF8FirstBytes[7] =
98 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
118 std::size_t Length = StrLen(Str);
121 myUTF32String.reserve(Length + 1);
130 std::size_t Length = StrLen(Str);
134 myUTF32String.reserve(Length + 1);
135 switch (
sizeof(
wchar_t))
138 case 4 : std::copy(Str, Str + Length, std::back_inserter(myUTF32String));
break;
148 std::size_t Length = StrLen(Str);
151 myUTF32String.reserve(Length + 1);
160 std::size_t Length = StrLen(Str);
163 myUTF32String.reserve(Length+ 1);
175 myUTF32String.reserve(Str.length() + 1);
185 myUTF32String.reserve(Str.length() + 1);
188 switch (
sizeof(
wchar_t))
200 std::copy(Str.begin(), Str.end(), std::back_inserter(myUTF32String));
210 myUTF32String.reserve(Str.length() + 1);
215 myUTF32String.reserve(Str.length() + 1);
227 Unicode::Text::operator std::string()
const
230 Output.reserve(myUTF32String.length() + 1);
231 Unicode::UTF32ToANSI(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0, Unicode::GetDefaultLocale());
234 Unicode::Text::operator std::wstring()
const
242 Output.reserve(myUTF32String.length() + 1);
245 switch (
sizeof(
wchar_t))
250 UTF32ToUTF16(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0);
257 std::copy(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output));
269 Output.reserve(myUTF32String.length() * 4 + 1);
270 Unicode::UTF32ToUTF8(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0);
273 Unicode::Text::operator sf::Unicode::UTF16String()
const
275 Unicode::UTF16String Output;
276 Output.reserve(myUTF32String.length() * 2 + 1);
280 Unicode::Text::operator
const sf::Unicode::UTF32String&()
const
282 return myUTF32String;
289 const std::locale& Unicode::GetDefaultLocale()
295 static std::locale DefaultLocale = GetCurrentLocale();
297 return DefaultLocale;
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, using the given locale.
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, using the given locale.
Text()
Default constructor (empty text)
std::basic_string< Uint8 > UTF8String
Define a string type for each encoding Warning : in UTF8 and UTF16 strings, one element doesn't neces...
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, using the given locale.
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, using the given locale.
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, using the given locale.
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, using the given locale.