Transcoder_Test.cpp

Go to the documentation of this file.
00001 // -*- C++ -*- Transcoder_Test.cpp,v 1.8 2005/01/21 02:19:19 ossama Exp
00002 
00003 #include "ACEXML/common/Transcode.h"
00004 #include "ace/Log_Msg.h"
00005 #include "ace/OS_NS_string.h"
00006 #include "ace/OS_main.h"
00007 
00008 void dump_utf16 (const ACEXML_UTF16 *data,
00009                  size_t len)
00010 {
00011   size_t ptr = 0;
00012 
00013   while (1)
00014     {
00015       ACE_DEBUG ((LM_DEBUG, "%04x", data[ptr]));
00016 
00017       if (++ptr >= len)
00018         break;
00019 
00020       if (ptr % 4 == 0)
00021         ACE_DEBUG ((LM_DEBUG, "\n"));
00022       else
00023         ACE_DEBUG ((LM_DEBUG, "  "));
00024     }
00025   ACE_DEBUG ((LM_DEBUG, "\n"));
00026   return;
00027 }
00028 
00029 int
00030 ACE_TMAIN (int, ACE_TCHAR*[])
00031 {
00032   ACEXML_UTF16 org [18];
00033 //  =  { 1, 2, 4, 8, 0x10, 0x20, 0x40,
00034 //      0x80,
00035 //      0x100, 0x200, 0x400,
00036 //      0x800, 0x801, 0x802, 0x804, 0x808, 0x810, 0x820,
00037 //      0x840, 0x880, 0x900, 0xa00, 0xc00,
00038 //      0x1000, 0x2000, 0x4000, 0x8000, 0 }
00039   ACEXML_UCS4 temp = 1;
00040 
00041   ACE_OS::memset (org, 0, sizeof org);
00042   size_t x;
00043 
00044   for (x = 0; temp < 0x10000; x++, temp <<= 1)
00045     {
00046       org[x] = static_cast<ACEXML_UTF16> (temp);
00047     }
00048 
00049   ACE_DEBUG ((LM_DEBUG, "Original UTF16 string:\n"));
00050   dump_utf16 (org, x);
00051   ACE_DEBUG ((LM_DEBUG, "\n\n"));
00052 
00053   ACEXML_UTF8 decoded [MAXPATHLEN];
00054   ACE_OS::memset (decoded, 0, sizeof decoded);
00055 
00056   ACEXML_Transcoder::utf16s2utf8s (org, decoded, MAXPATHLEN);
00057 
00058   ACE_DEBUG ((LM_DEBUG, "Transcoded UTF8 string:\n"));
00059   ACE_HEX_DUMP ((LM_DEBUG, decoded, ACE_OS::strlen (decoded) + 1));
00060   ACE_DEBUG ((LM_DEBUG, "\n\n"));
00061 
00062   ACEXML_UTF16 after [18];
00063   ACE_OS::memset (after, 0, sizeof after);
00064   ACEXML_Transcoder::utf8s2utf16s (decoded, after, 18);
00065 
00066   ACE_DEBUG ((LM_DEBUG, "Restored UTF16 string:\n"));
00067   dump_utf16 (after, x);
00068   ACE_DEBUG ((LM_DEBUG, "\n\n"));
00069 
00070   return 0;
00071 }

Generated on Thu Nov 9 11:45:40 2006 for ACEXML by doxygen 1.3.6