/* by Jinsuk Kim, http://www.jinsuk.pe.kr */ #include #include int Hanja2Hangul(char *s) /* input should be UTF-8 encoded stream */ { unsigned char c; unsigned short unicode = 0x00000000; int i, j, len; len = strlen(s); for (i=0; i> 8; } else { nbytes = 3; byte[2] = (unicode & 0x3f) | 0x80; byte[1] = ((unicode << 2) & 0x3f00 | 0x8000) >> 8; byte[0] = ((unicode << 4) & 0x3f0000 | 0xe00000) >> 16; } */ /* entered here, we guarantee unicode is greater than 0x0800 */ unicode = HjHgMap[unicode]; byte[2] = (unicode & 0x3f) | 0x80; byte[1] = ((unicode << 2) & 0x3f00 | 0x8000) >> 8; byte[0] = ((unicode << 4) & 0x3f0000 | 0xe00000) >> 16; for (j=0; j<3; j++) { s[i-3+j] = byte[j]; } continue; } } return 0; }