/*---------------------------------------------------------------------------* Project: Revolution ENC sample demo File: sample.c Copyright 2006 Nintendo. 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. $Log: sample.c,v $ Revision 1.10 2007/10/30 07:04:47 yoshioka_yasuhiro Modified the NUL termination of internal encoding. Revision 1.9 2007/02/05 08:01:20 yoshioka_yasuhiro Modified the character encoding. Revision 1.8 2006/12/26 00:54:01 yoshioka_yasuhiro Deleted unused codes. Revision 1.7 2006/10/27 12:20:16 yoshioka_yasuhiro Divided into unicode.c, latin.c and japanese.c. Added auto converter demo. Revision 1.6 2006/08/14 04:31:35 yoshioka_yasuhiro Added demos for ENCConvertStringJisToUnicode and ENCConvertStringUnicodeToJis. Revision 1.4 2006/08/09 10:37:37 yoshioka_yasuhiro Specification change. ENCConverString* functions returns a result code, and read/write dstlen and srclen. Revision 1.3 2006/08/08 10:48:23 yoshioka_yasuhiro Fix for specification change. Modified termination check. Revision 1.1 2006/08/07 06:43:14 yoshioka_yasuhiro Initial commit. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include static const u16 wcs[] = { 0x002A, 0x0045, 0x004E, 0x0043, 0x0020, 0x0044, 0x0045, 0x004D, 0x004F, 0x002A, 0x000A, 0x0075, 0x006E, 0x006B, 0x006E, 0x006F, 0x0077, 0x006E, 0x0020, 0x0063, 0x0068, 0x0061, 0x0072, 0x0061, 0x0063, 0x0074, 0x0065, 0x0072, 0x0073, 0x000A, 0x0100, 0x0110, 0x0120, 0x0130, 0x0140, 0x0150, 0x0160, 0x0170, 0x000A, 0x0061, 0x0072, 0x0065, 0x0020, 0x0073, 0x006B, 0x0069, 0x0070, 0x0070, 0x0065, 0x0064, 0x0020, 0x006F, 0x0072, 0x0020, 0x0063, 0x006F, 0x006E, 0x0076, 0x0065, 0x0072, 0x0074, 0x0065, 0x0064, 0x0020, 0x0074, 0x006F, 0x0020, 0x0027, 0x003F, 0x0027, 0x0000 }; static const u8 mbs[] = { 0x75, 0x6E, 0x6B, 0x6E, 0x6F, 0x77, 0x6E, 0x20, 0x63, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x73, 0x0A, 0x1B, 0x24, 0x42, 0x22, 0x32, 0x22, 0x33, 0x22, 0x34, 0x22, 0x35, 0x22, 0x36, 0x1B, 0x28, 0x42, 0x0A, 0x61, 0x72, 0x65, 0x20, 0x73, 0x6B, 0x69, 0x70, 0x70, 0x65, 0x64, 0x20, 0x6F, 0x72, 0x20, 0x63, 0x6F, 0x6E, 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x20, 0x74, 0x6F, 0x20, 0x27, 0x3F, 0x27, 0x00 }; #define LENGTH 0x400 /* these characters must be convertible. */ static const u16 altNomap = L'?'; static const u16 altInvalid = L'@'; int main() { s32 dstlen, srclen; u8 buffer8[LENGTH]; u16 buffer16[LENGTH]; ENCResult result; ENCContext lenContext, convContext; /* convert from internal encoding */ { srclen = -1; ENCInitContext(&lenContext); ENCSetExternalEncoding(&lenContext, (const u8*)"Shift_JIS"); ENCSetBreakType(&lenContext, ENC_BR_KEEP); ENCSetAlternativeCharacter(&lenContext, altNomap, altInvalid); /* ENCContext has the state of a conversion sequence. */ ENCDuplicateContext(&convContext, &lenContext); result = ENCConvertFromInternalEncoding(&lenContext, NULL, &dstlen, wcs, &srclen); OSReport("result: %d, dstlen: %d, srclen: %d\n", result, dstlen, srclen); result = ENCConvertFromInternalEncoding(&convContext, buffer8, &dstlen, wcs, &srclen); OSReport("result: %d, dstlen: %d, srclen: %d\n", result, dstlen, srclen); buffer8[dstlen] = 0; OSReport("\n%s\n\n", buffer8); } /* convert to internal encoding */ { srclen = -1; ENCInitContext(&lenContext); ENCSetExternalEncoding(&lenContext, (const u8*)"ISO-2022-JP"); ENCSetBreakType(&lenContext, ENC_BR_KEEP); ENCSetAlternativeCharacter(&lenContext, altNomap, altInvalid); /* ENCContext has the state of a conversion sequence. */ ENCDuplicateContext(&convContext, &lenContext); result = ENCConvertToInternalEncoding(&lenContext, NULL, &dstlen, mbs, &srclen); OSReport("result: %d, dstlen: %d, srclen: %d\n", result, dstlen, srclen); result = ENCConvertToInternalEncoding(&convContext, buffer16, &dstlen, mbs, &srclen); OSReport("result: %d, dstlen: %d, srclen: %d\n", result, dstlen, srclen); buffer16[dstlen / sizeof(u16)] = 0; OSReport("\n"); { u32 i; u32 length = dstlen / ENC_INTERNAL_CHAR_WIDTH + 1; for (i = 0; i < length; ++i) { OSReport("0x%04X\n", buffer16[i]); } } OSReport("\n\n"); } OSHalt("Finish"); return 0; }