1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: enc_Main.cpp
4
5 Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Rev: 46365 $
14 *---------------------------------------------------------------------------*/
15
16 #include <nn.h>
17 #include <nn/dbg.h>
18 #include <nn/enc.h>
19
20 namespace
21 {
22
23 const u16 utf16[] = {
24 0x30c9, 0x30ec, 0x30df, 0x30d5, 0x30a1,
25 0x30bd, 0x30e9, 0x30b7, 0x30c9, 0x000a,
26 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
27 0x0041, 0x0042, 0x0043, 0x000a, 0x0000
28 };
29
30 const u8 utf8[] = {
31 0xe3, 0x83, 0x89, 0xe3, 0x83, 0xac, 0xe3, 0x83, 0x9f,
32 0xe3, 0x83, 0x95, 0xe3, 0x82, 0xa1, 0xe3, 0x82, 0xbd,
33 0xe3, 0x83, 0xa9, 0xe3, 0x82, 0xb7, 0xe3, 0x83, 0x89,
34 0x0a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x41, 0x42, 0x43,
35 0x0a, 0x00
36 };
37
38 const u32 BUFFER_SIZE = 64;
39
40 }
41
nnMain(void)42 extern "C" void nnMain( void )
43 {
44 nn::Result result;
45
46 s32 srcSize, dstSize;
47
48 NN_LOG("* UTF8 str -> UTF16 str *\n");
49 u16 buffer16[BUFFER_SIZE];
50 /* Calculate the required size of the buffer */
51 srcSize = -1;
52 result = nn::enc::ConvertStringUtf8ToUtf16Native(
53 NULL, &dstSize, utf8, &srcSize
54 );
55 NN_ASSERT_RESULT( result );
56 NN_EQUAL_ASSERT(
57 dstSize, std::wcslen(reinterpret_cast<const wchar_t*>(utf16)));
58 NN_EQUAL_ASSERT(
59 srcSize, std::strlen(reinterpret_cast<const char*>(utf8)));
60 /* Character code conversion */
61 result = nn::enc::ConvertStringUtf8ToUtf16Native(
62 buffer16, &dstSize, utf8, &srcSize
63 );
64 NN_ASSERT_RESULT( result );
65 NN_EQUAL_ASSERT(
66 dstSize, std::wcslen(reinterpret_cast<const wchar_t*>(utf16)));
67 NN_EQUAL_ASSERT(
68 srcSize, std::strlen(reinterpret_cast<const char*>(utf8)));
69 for(int i = 0; utf16[i] != 0; ++i)
70 {
71 NN_EQUAL_ASSERT( buffer16[i], utf16[i] );
72 }
73
74 NN_LOG("* UTF16 str -> UTF8 str *\n");
75 u8 buffer8[BUFFER_SIZE];
76 /* Calculate the required size of the buffer */
77 srcSize = -1;
78 result = nn::enc::ConvertStringUtf16NativeToUtf8(
79 NULL, &dstSize, utf16, &srcSize
80 );
81 NN_ASSERT_RESULT( result );
82 NN_EQUAL_ASSERT(
83 dstSize, std::strlen(reinterpret_cast<const char*>(utf8)));
84 NN_EQUAL_ASSERT(
85 srcSize, std::wcslen(reinterpret_cast<const wchar_t*>(utf16)));
86 /* Character code conversion */
87 result = nn::enc::ConvertStringUtf16NativeToUtf8(
88 buffer8, &dstSize, utf16, &srcSize
89 );
90 NN_ASSERT_RESULT( result );
91 NN_EQUAL_ASSERT(
92 dstSize, std::strlen(reinterpret_cast<const char*>(utf8)));
93 NN_EQUAL_ASSERT(
94 srcSize, std::wcslen(reinterpret_cast<const wchar_t*>(utf16)));
95 for(int i = 0; utf8[i] != 0; ++i)
96 {
97 NN_EQUAL_ASSERT( buffer8[i], utf8[i] );
98 }
99
100 NN_LOG("*** End of EncDemo ***\n");
101 while(true){}
102 }
103