Back to index

im-sdk  12.3.91
convert_u16_hanja_to_u8.c
Go to the documentation of this file.
00001 #include <glib.h>
00002 #include "utfchar.h"
00003 #include "hanjatable.h"
00004 unsigned char *
00005 convert_u16_to_u8 (UTFCHAR *u16str)
00006 {
00007   gchar *u8str;
00008   int u16len = _utfchar_length (u16str) * sizeof (UTFCHAR);
00009   int bytes_read = 0;
00010   int bytes_written = 0;
00011   GError *gerror = NULL;
00012   
00013   u8str = g_convert ((const gchar *)u16str,
00014                    u16len,
00015                    "UTF-8", "UTF-16",
00016                    &bytes_read,
00017                    &bytes_written,
00018                    &gerror);
00019   if (gerror)
00020     return NULL;
00021 
00022   return u8str;
00023 }
00024 int
00025 main (int argc, char **argv)
00026 {
00027   int n_table_length;
00028   int i,j;
00029   const unsigned short *hangul;
00030   const unsigned short *hanja;
00031   unsigned short buffer[2] = { 0x0000, 0x0000};
00032 
00033   unsigned char *u8hangul;
00034   unsigned char *u8hanja;
00035   n_table_length = sizeof (hanjatable) / sizeof (hanjatable[0]);
00036 
00037   for (i = 0 ; i < n_table_length; i++){
00038     hangul =  hanjatable[i];
00039     hanja = hangul + 1;
00040     memset (buffer, 0, sizeof (buffer));
00041     memcpy (buffer, hangul, sizeof (unsigned short));
00042     u8hangul = convert_u16_to_u8 (buffer);
00043 
00044     while (*hanja){
00045       memset (buffer, 0, sizeof (buffer));
00046       memcpy (buffer, hanja, sizeof (unsigned short));
00047       u8hanja = convert_u16_to_u8 (buffer);
00048       printf ("[%s][%s]@\n",u8hangul, u8hanja );
00049       g_free ((gpointer) u8hanja);    
00050       hanja++;
00051     }
00052     
00053     g_free ((gpointer) u8hangul);
00054 
00055   }
00056   return 0;  
00057 }