~hikiko/nux/arb-srgba-shader

« back to all changes in this revision

Viewing changes to NuxCore/Character/NUTF.h

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-01 19:25:37 UTC
  • Revision ID: neil.patel@canonical.com-20100901192537-mfz7rm6q262pewg6
Import and build NuxCore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef NUTF_H
 
2
#define NUTF_H
 
3
 
 
4
// http://en.wikipedia.org/wiki/UTF-16
 
5
 
 
6
// In computing, UTF-16 (16-bit Unicode Transformation Format) is a variable-length character encoding
 
7
// for Unicode, capable of encoding the entire Unicode repertoire. The encoding form maps code points
 
8
// (characters) into a sequence of 16-bit words, called code units. For characters in the Basic
 
9
// Multilingual Plane (BMP) the resulting encoding is a single 16-bit word. For characters in the other
 
10
// planes, the encoding will result in a pair of 16-bit words, together called a surrogate pair. All possible
 
11
// code points from U+0000 through U+10FFFF, except for the surrogate code points U+D800�U+DFFF
 
12
// (which are not characters), are uniquely mapped by UTF-16 regardless of the code point's current or
 
13
// future character assignment or use.
 
14
// 
 
15
// As many uses in computing require units of bytes (octets) there are three related encoding schemes
 
16
// which map to octet sequences instead of words: namely UTF-16, UTF-16BE, and UTF-16LE. They
 
17
// differ only in the byte order chosen to represent each 16-bit unit and whether they make use of a
 
18
// Byte Order Mark. All of the schemes will result in either a 2 or 4-byte sequence for any given character.
 
19
// 
 
20
// UTF-16 is officially defined in Annex Q of the international standard ISO/IEC 10646-1. It is also
 
21
// described in The Unicode Standard version 3.0 and higher, as well as in the IETF's RFC 2781.
 
22
//
 
23
// UCS-2 (2-byte Universal Character Set) is an obsolete character encoding which is a predecessor
 
24
// to UTF-16. The UCS-2 encoding form is nearly identical to that of UTF-16, except that it does not
 
25
// support surrogate pairs and therefore can only encode characters in the BMP range U+0000 through
 
26
// U+FFFF. As a consequence it is a fixed-length encoding that always encodes characters into a
 
27
// single 16-bit value. As with UTF-16, there are three related encoding schemes (UCS-2, UCS-2BE, UCS-2LE)
 
28
// that map characters to a specific byte sequence.
 
29
// 
 
30
// Because of the technical similarities and upwards compatibility from UCS-2 to UTF-16, the two
 
31
// encodings are often erroneously conflated and used as if interchangeable, so that strings encoded
 
32
// in UTF-16 are sometimes misidentified as being encoded in UCS-2.
 
33
 
 
34
NAMESPACE_BEGIN
 
35
 
 
36
//! Convert UTF-16 to UTF-8
 
37
class NUTF8
 
38
{
 
39
    // UTF-8 encoded characters may theoretically be up to six bytes long, however 16-bit BMP characters are only up to three bytes long.
 
40
public:
 
41
    explicit NUTF8(const UNICHAR* Source);
 
42
    explicit NUTF8(const std::wstring& Source);
 
43
    ~NUTF8();
 
44
 
 
45
    operator const char* ();
 
46
 
 
47
private:
 
48
    void Convert(const UNICHAR*);
 
49
    //void Convert(const t_UTF32*);
 
50
    char* utf8;
 
51
 
 
52
};
 
53
 
 
54
//! Convert UTF-8 to UTF-16
 
55
class NUTF16
 
56
{
 
57
public:
 
58
    explicit NUTF16(const char* Source);
 
59
    explicit NUTF16(const std::string& Source);
 
60
    ~NUTF16();
 
61
 
 
62
    operator const UNICHAR* ();
 
63
 
 
64
private:
 
65
    void Convert(const char*);
 
66
    UNICHAR* unicode;
 
67
 
 
68
};
 
69
 
 
70
NAMESPACE_END
 
71
 
 
72
#endif // NUTF_H