/*---------------------------------------------------------------------------* Project: Horizon File: enc_Main.cpp Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 46365 $ *---------------------------------------------------------------------------*/ #include #include #include namespace { const u16 utf16[] = { 0x30c9, 0x30ec, 0x30df, 0x30d5, 0x30a1, 0x30bd, 0x30e9, 0x30b7, 0x30c9, 0x000a, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0041, 0x0042, 0x0043, 0x000a, 0x0000 }; const u8 utf8[] = { 0xe3, 0x83, 0x89, 0xe3, 0x83, 0xac, 0xe3, 0x83, 0x9f, 0xe3, 0x83, 0x95, 0xe3, 0x82, 0xa1, 0xe3, 0x82, 0xbd, 0xe3, 0x83, 0xa9, 0xe3, 0x82, 0xb7, 0xe3, 0x83, 0x89, 0x0a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x41, 0x42, 0x43, 0x0a, 0x00 }; const u32 BUFFER_SIZE = 64; } extern "C" void nnMain( void ) { nn::Result result; s32 srcSize, dstSize; NN_LOG("* UTF8 str -> UTF16 str *\n"); u16 buffer16[BUFFER_SIZE]; /* Calculate the required size of the buffer */ srcSize = -1; result = nn::enc::ConvertStringUtf8ToUtf16Native( NULL, &dstSize, utf8, &srcSize ); NN_ASSERT_RESULT( result ); NN_EQUAL_ASSERT( dstSize, std::wcslen(reinterpret_cast(utf16))); NN_EQUAL_ASSERT( srcSize, std::strlen(reinterpret_cast(utf8))); /* Character code conversion */ result = nn::enc::ConvertStringUtf8ToUtf16Native( buffer16, &dstSize, utf8, &srcSize ); NN_ASSERT_RESULT( result ); NN_EQUAL_ASSERT( dstSize, std::wcslen(reinterpret_cast(utf16))); NN_EQUAL_ASSERT( srcSize, std::strlen(reinterpret_cast(utf8))); for(int i = 0; utf16[i] != 0; ++i) { NN_EQUAL_ASSERT( buffer16[i], utf16[i] ); } NN_LOG("* UTF16 str -> UTF8 str *\n"); u8 buffer8[BUFFER_SIZE]; /* Calculate the required size of the buffer */ srcSize = -1; result = nn::enc::ConvertStringUtf16NativeToUtf8( NULL, &dstSize, utf16, &srcSize ); NN_ASSERT_RESULT( result ); NN_EQUAL_ASSERT( dstSize, std::strlen(reinterpret_cast(utf8))); NN_EQUAL_ASSERT( srcSize, std::wcslen(reinterpret_cast(utf16))); /* Character code conversion */ result = nn::enc::ConvertStringUtf16NativeToUtf8( buffer8, &dstSize, utf16, &srcSize ); NN_ASSERT_RESULT( result ); NN_EQUAL_ASSERT( dstSize, std::strlen(reinterpret_cast(utf8))); NN_EQUAL_ASSERT( srcSize, std::wcslen(reinterpret_cast(utf16))); for(int i = 0; utf8[i] != 0; ++i) { NN_EQUAL_ASSERT( buffer8[i], utf8[i] ); } NN_LOG("*** End of EncDemo ***\n"); while(true){} }