~hikiko/nux/arb-srgba-shader

« back to all changes in this revision

Viewing changes to NuxCore/Character/NUnicode.cpp

  • 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
#include "NKernel.h"
 
2
#include "NUnicode.h"
 
3
 
 
4
 
 
5
NAMESPACE_BEGIN
 
6
 
 
7
ANSICHAR* UnicharToAnsicharConvertion::Convert(const UNICHAR* Source)
 
8
{
 
9
    std::wstring utf16string(Source);
 
10
    size_t utf16size = utf16string.length();
 
11
    size_t utf8size = 6 * utf16size;
 
12
    ANSICHAR *utf8string = new ANSICHAR[utf8size+1];
 
13
 
 
14
    const t_UTF16 *source_start = utf16string.c_str();
 
15
    const t_UTF16 *source_end = source_start + utf16size;
 
16
    t_UTF8* target_start = reinterpret_cast<t_UTF8*>(utf8string);
 
17
    t_UTF8* target_end = target_start + utf8size;
 
18
 
 
19
    ConversionResult res = ConvertUTF16toUTF8(&source_start, source_end, &target_start, target_end, lenientConversion);
 
20
    if (res != conversionOK)
 
21
    {
 
22
        delete utf8string;
 
23
        utf8string = 0;
 
24
    }
 
25
    // mark end of string
 
26
    *target_start = 0;
 
27
    return utf8string;
 
28
}
 
29
 
 
30
UNICHAR* AnsicharToUnicharConvertion::Convert(const ANSICHAR* Source)
 
31
{
 
32
    std::string utf8string(Source);
 
33
    size_t utf8size = utf8string.length();
 
34
    size_t utf16size = utf8size;
 
35
    UNICHAR *utf16string = new UNICHAR[utf16size+1];
 
36
 
 
37
    const t_UTF8 *source_start = reinterpret_cast<const t_UTF8*>(utf8string.c_str());
 
38
    const t_UTF8 *source_end = source_start + utf8size;
 
39
    t_UTF16* target_start = reinterpret_cast<t_UTF16*>(utf16string);
 
40
    t_UTF16* target_end = target_start + utf16size;
 
41
 
 
42
    ConversionResult res = ConvertUTF8toUTF16(&source_start, source_end, &target_start, target_end, lenientConversion);
 
43
    if (res != conversionOK)
 
44
    {
 
45
        delete utf16string;
 
46
        utf16string = 0;
 
47
    }
 
48
    // mark end of string
 
49
    *target_start = 0;
 
50
    return utf16string;
 
51
}
 
52
 
 
53
NAMESPACE_END
 
 
b'\\ No newline at end of file'