Unicode.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef SFML_UNICODE_HPP
26#define SFML_UNICODE_HPP
27
29// Headers
31#include <SFML/Config.hpp>
32#include <iterator>
33#include <locale>
34#include <string>
35#include <stdlib.h>
36
37
38namespace sf
39{
44class SFML_API Unicode
45{
46public :
47
54 typedef std::basic_string<Uint8> UTF8String;
55 typedef std::basic_string<Uint16> UTF16String;
56 typedef std::basic_string<Uint32> UTF32String;
57
63 class SFML_API Text
64 {
65 public :
66
68 /// Default constructor (empty text)
69 ///
70 ////////////////////////////////////////////////////////////
71 Text();
72
79 Text(const char* Str);
80 Text(const wchar_t* Str);
81 Text(const Uint8* Str);
82 Text(const Uint16* Str);
83 Text(const Uint32* Str);
84 Text(const std::string& Str);
85 Text(const std::wstring& Str);
86 Text(const Unicode::UTF8String& Str);
87 Text(const Unicode::UTF16String& Str);
88 Text(const Unicode::UTF32String& Str);
89
96 operator std::string () const;
97 operator std::wstring () const;
98 operator Unicode::UTF8String () const;
99 operator Unicode::UTF16String () const;
100 operator const Unicode::UTF32String&() const;
101
102 private :
105 // Data member
107 sf::Unicode::UTF32String myUTF32String;
108 };
109
123 template <typename In, typename Out>
124 static Out UTF32ToANSI(In Begin, In End, Out Output, char Replacement = '?', const std::locale& Locale = GetDefaultLocale());
125
138 template <typename In, typename Out>
139 static Out ANSIToUTF32(In Begin, In End, Out Output, const std::locale& Locale = GetDefaultLocale());
140
153 template <typename In, typename Out>
154 static Out UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement = '?');
155
157
164 ///
165 /// \return Iterator to the end of the output sequence which has been written
166 ///
167 ////////////////////////////////////////////////////////////
168 template <typename In, typename Out>
169 static Out UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement = '?');
170
183 template <typename In, typename Out>
184 static Out UTF16ToUTF8(In Begin, In End, Out Output, Uint8 Replacement = '?');
185
198 template <typename In, typename Out>
199 static Out UTF16ToUTF32(In Begin, In End, Out Output, Uint32 Replacement = '?');
200
201
208 /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
209 ///
210 /// \return Iterator to the end of the output sequence which has been written
211 ///
212 ////////////////////////////////////////////////////////////
213 template <typename In, typename Out>
214 static Out UTF32ToUTF8(In Begin, In End, Out Output, Uint8 Replacement = '?');
215
228 template <typename In, typename Out>
229 static Out UTF32ToUTF16(In Begin, In End, Out Output, Uint16 Replacement = '?');
230
240 template <typename In>
241 static std::size_t GetUTF8Length(In Begin, In End);
242
252 template <typename In>
253 static std::size_t GetUTF16Length(In Begin, In End);
254
264 template <typename In>
265 static std::size_t GetUTF32Length(In Begin, In End);
266
267private :
268
274
275 static const std::locale& GetDefaultLocale();
276
278 // Static member data
280 static const int UTF8TrailingBytes[256];
281 static const Uint32 UTF8Offsets[6];
282 static const Uint8 UTF8FirstBytes[7];
283};
284
285#include <SFML/System/Unicode.inl>
286
287} // namespace sf
288
289
290#endif // SFML_UNICODE_HPP
This class is an abstract definition of a unicode text, it can be converted from and to any kind of s...
Definition Unicode.hpp:64
Text()
Default constructor (empty text).
Definition Unicode.cpp:105
Provides utility functions to convert from and to any unicode and ASCII encoding.
Definition Unicode.hpp:45
static std::size_t GetUTF16Length(In Begin, In End)
Get the number of characters composing an UTF-16 string.
Definition Unicode.hpp:443
std::basic_string< Uint8 > UTF8String
Define a string type for each encoding Warning : in UTF8 and UTF16 strings, one element doesn't neces...
Definition Unicode.hpp:54
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,...
Definition Unicode.hpp:327
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,...
Definition Unicode.hpp:281
static std::size_t GetUTF32Length(In Begin, In End)
Get the number of characters composing an UTF-32 string.
Definition Unicode.hpp:472
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,...
Definition Unicode.hpp:208
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,...
Definition Unicode.hpp:380
static std::size_t GetUTF8Length(In Begin, In End)
Get the number of characters composing an UTF-8 string.
Definition Unicode.hpp:423
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,...
Definition Unicode.hpp:164