| 1 |
|
| /* ---------------------------------------------------------------------------- |
| 2 |
|
| * conv.c |
| 3 |
|
| * convert sjis <=> utf8 |
| 4 |
|
| * ---------------------------------------------------------------------------- |
| 5 |
|
| * Mastering programed by YAMASHINA Hio |
| 6 |
|
| * ---------------------------------------------------------------------------- |
| 7 |
|
| * $Id: conv.c 4697 2007-09-14 06:17:00Z pho $ |
| 8 |
|
| * ------------------------------------------------------------------------- */ |
| 9 |
|
| |
| 10 |
|
| #ifdef _MSC_VER |
| 11 |
|
| #include "EXTERN.h" |
| 12 |
|
| #include "perl.h" |
| 13 |
|
| #include "XSUB.h" |
| 14 |
|
| #include <windows.h> |
| 15 |
|
| #include <winsock.h> |
| 16 |
|
| #define snprintf _snprintf |
| 17 |
|
| #endif |
| 18 |
|
| |
| 19 |
|
| #include "Japanese.h" |
| 20 |
|
| #include <stdio.h> |
| 21 |
|
| |
| 22 |
|
| #define DISP_S2U 0 |
| 23 |
|
| #define DISP_U2S 0 |
| 24 |
|
| |
| 25 |
|
| #if DISP_U2S |
| 26 |
|
| #define ECHO_U2S(arg) fprintf arg |
| 27 |
|
| #define ON_U2S(cmd) cmd |
| 28 |
|
| #else |
| 29 |
|
| #define ECHO_U2S(arg) |
| 30 |
|
| #define ON_U2S(cmd) |
| 31 |
|
| #endif |
| 32 |
|
| |
| 33 |
|
| #ifndef __cplusplus |
| 34 |
|
| #undef bool |
| 35 |
|
| #undef true |
| 36 |
|
| #undef false |
| 37 |
|
| typedef enum bool { false, true, } bool; |
| 38 |
|
| #endif |
| 39 |
|
| |
| 40 |
|
| /* ---------------------------------------------------------------------------- |
| 41 |
|
| * SV* sv_utf8 = xs_sjis_utf8(SV* sv_sjis) |
| 42 |
|
| * convert string from sjis to utf8. |
| 43 |
|
| * ------------------------------------------------------------------------- */ |
| 44 |
|
| EXTERN_C |
| 45 |
|
| SV* |
| 46 |
24 |
| xs_sjis_utf8(SV* sv_str) |
| 47 |
|
| { |
| 48 |
|
| STRLEN src_len; |
| 49 |
|
| UJ_UINT8* src; |
| 50 |
|
| int len; |
| 51 |
|
| |
| 52 |
|
| SV_Buf result; |
| 53 |
|
| const UJ_UINT8* src_end; |
| 54 |
|
| |
| 55 |
24 |
▶ | if( sv_str==&PL_sv_undef ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( sv_str==&PL_sv_undef ) |
0 |
24 |
24 |
|
| 56 |
|
| { |
| 57 |
0 |
| return newSVsv(&PL_sv_undef); |
| 58 |
|
| } |
| 59 |
|
| |
| 60 |
24 |
| src = (UJ_UINT8*)SvPV(sv_str,src_len); |
| 61 |
24 |
| len = sv_len(sv_str); |
| 62 |
|
| #if DISP_S2U |
| 63 |
|
| fprintf(stderr,"Unicode::Japanese::(xs)sjis_utf8\n",len); |
| 64 |
|
| bin_dump("in ",src,len); |
| 65 |
|
| #endif |
| 66 |
24 |
▶ | SV_Buf_init(&result,len*3/2+4); |
Branch: 2 branches
| Branch | True | False | Total |
| SV_Buf_init(&result,len*3/2+4); |
24 |
0 |
24 |
| SV_Buf_init(&result,len*3/2+4); |
8 |
16 |
24 |
|
| 67 |
24 |
| src_end = src+len; |
| 68 |
|
| |
| 69 |
144 |
▶ | while( src<src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| while( src<src_end ) |
120 |
24 |
144 |
|
| 70 |
|
| { |
| 71 |
|
| const UJ_UINT8* ptr; |
| 72 |
120 |
▶ | if( src[0]<0x80 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src[0]<0x80 ) |
92 |
28 |
120 |
|
| 73 |
|
| { /* ASCII */ |
| 74 |
|
| ECHO_U2S((stderr,"ascii: %02x\n",src[0])); |
| 75 |
92 |
▶ | SV_Buf_append_ch(&result,*src); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,*src); |
0 |
92 |
92 |
| SV_Buf_append_ch(&result,*src); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,*src); |
0 |
0 |
0 |
|
| 76 |
92 |
| ++src; |
| 77 |
92 |
| continue; |
| 78 |
28 |
▶ | }else if( 0xa1<=src[0] && src[0]<=0xdf ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( 0xa1<=src[0] && src[0]<=0xdf ) |
12 |
16 |
28 |
| }else if( 0xa1<=src[0] && src[0]<=0xdf ) |
12 |
0 |
12 |
|
| 79 |
|
| { /* half-width katakana (ja:Ⱦ³Ñ¥«¥Ê) */ |
| 80 |
|
| ECHO_U2S((stderr,"kana: %02x\n",src[0])); |
| 81 |
12 |
| ptr = (UJ_UINT8*)&g_s2u_table[(src[0]-0xa1)*3]; |
| 82 |
12 |
| ++src; |
| 83 |
16 |
▶ | }else if( src+1<src_end && 0x81<=src[0] && src[0]<=0x9f ) |
Branch: 3 branches
| Branch | True | False | Total |
| }else if( src+1<src_end && 0x81<=src[0] && src[0]<=0x9f ) |
16 |
0 |
16 |
| }else if( src+1<src_end && 0x81<=src[0] && src[0]<=0x9f ) |
16 |
0 |
16 |
| }else if( src+1<src_end && 0x81<=src[0] && src[0]<=0x9f ) |
16 |
0 |
16 |
|
| 84 |
16 |
| { /* a two-bytes letter (ja:2¥Ð¥¤¥Èʸ»ú) */ |
| 85 |
16 |
| const UJ_UINT16 sjis = (src[0]<<8)+src[1]; /* ntohs */ |
| 86 |
|
| ECHO_U2S((stderr,"sjis.dbcs#1: %04x\n",sjis)); |
| 87 |
16 |
| ptr = (UJ_UINT8*)&g_s2u_table[(sjis - 0x8100 + 0x3f)*3]; |
| 88 |
16 |
| src += 2; |
| 89 |
0 |
▶ | }else if( src+1<src_end && 0xe0<=src[0] && src[0]<=0xfc ) |
Branch: 3 branches
| Branch | True | False | Total |
| }else if( src+1<src_end && 0xe0<=src[0] && src[0]<=0xfc ) |
0 |
0 |
0 |
| }else if( src+1<src_end && 0xe0<=src[0] && src[0]<=0xfc ) |
0 |
0 |
0 |
| }else if( src+1<src_end && 0xe0<=src[0] && src[0]<=0xfc ) |
0 |
0 |
0 |
|
| 90 |
0 |
| { /* a two-bytes letter (ja:2¥Ð¥¤¥Èʸ»ú) */ |
| 91 |
0 |
| const UJ_UINT16 sjis = (src[0]<<8)+src[1]; /* ntohs */ |
| 92 |
|
| ECHO_U2S((stderr,"sjis.dbcs#2: %04x\n",sjis)); |
| 93 |
0 |
| ptr = (UJ_UINT8*)&g_s2u_table[(sjis- 0xe000 + 0x1f3f)*3]; |
| 94 |
0 |
| src += 2; |
| 95 |
|
| }else |
| 96 |
|
| { /* unknown */ |
| 97 |
|
| /*fprintf(stderr,"unknown: %02x\n",src[0]); */ |
| 98 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 99 |
0 |
| ++src; |
| 100 |
0 |
| continue; |
| 101 |
|
| } |
| 102 |
|
| |
| 103 |
|
| ECHO_U2S((stderr,"offset: 0x%04x\n",ptr-g_s2u_table)); |
| 104 |
|
| ECHO_U2S((stderr,"utf8-char : %02x %02x %02x\n",ptr[0],ptr[1],ptr[2])); |
| 105 |
28 |
▶ | if( ptr[2] ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( ptr[2] ) |
28 |
0 |
28 |
|
| 106 |
|
| { |
| 107 |
|
| /*fprintf(stderr,"utf8-len: [%d]\n",3); */ |
| 108 |
30 |
▶ | SV_Buf_append_mem(&result, ptr, 3); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result, ptr, 3); |
2 |
26 |
28 |
| SV_Buf_append_mem(&result, ptr, 3); |
2 |
0 |
2 |
| SV_Buf_append_mem(&result, ptr, 3); |
2 |
0 |
2 |
|
| 109 |
0 |
▶ | }else if( ptr[1] ) |
Branch: 1 branch
| Branch | True | False | Total |
| }else if( ptr[1] ) |
0 |
0 |
0 |
|
| 110 |
|
| { |
| 111 |
|
| /*fprintf(stderr,"utf8-len: [%d]\n",2); */ |
| 112 |
0 |
▶ | SV_Buf_append_mem(&result, ptr, 2); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result, ptr, 2); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result, ptr, 2); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result, ptr, 2); |
0 |
0 |
0 |
|
| 113 |
0 |
▶ | }else if( ptr[0] ) |
Branch: 1 branch
| Branch | True | False | Total |
| }else if( ptr[0] ) |
0 |
0 |
0 |
|
| 114 |
|
| { |
| 115 |
|
| /*fprintf(stderr,"utf8-len: [%d]\n",1); */ |
| 116 |
0 |
▶ | SV_Buf_append_ch(&result,*ptr); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,*ptr); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,*ptr); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,*ptr); |
0 |
0 |
0 |
|
| 117 |
|
| }else |
| 118 |
|
| { |
| 119 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 120 |
|
| } |
| 121 |
|
| } |
| 122 |
|
| #if DISP_S2U |
| 123 |
|
| bin_dump("out",result.getBegin(),result.getLength()); |
| 124 |
|
| #endif |
| 125 |
24 |
| SV_Buf_setLength(&result); |
| 126 |
|
| |
| 127 |
24 |
| return SV_Buf_getSv(&result); |
| 128 |
|
| } |
| 129 |
|
| |
| 130 |
|
| /* ---------------------------------------------------------------------------- |
| 131 |
|
| * SV* sv_sjis = xs_utf8_sjis(SV* sv_utf8) |
| 132 |
|
| * convert from utf8 to sjis. |
| 133 |
|
| * ------------------------------------------------------------------------- */ |
| 134 |
|
| EXTERN_C |
| 135 |
|
| SV* |
| 136 |
112 |
| xs_utf8_sjis(SV* sv_str) |
| 137 |
|
| { |
| 138 |
|
| const UJ_UINT8* src; |
| 139 |
|
| int len; |
| 140 |
|
| SV_Buf result; |
| 141 |
|
| const UJ_UINT8* src_end; |
| 142 |
|
| static const UJ_UINT8 char_null[2] = { '\0', '\0' }; |
| 143 |
|
| static const UJ_UINT8 char_unknown[2] = { '?', '\0' }; |
| 144 |
|
| |
| 145 |
112 |
▶ | if( sv_str==&PL_sv_undef ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( sv_str==&PL_sv_undef ) |
0 |
112 |
112 |
|
| 146 |
|
| { |
| 147 |
0 |
| return newSVsv(&PL_sv_undef); |
| 148 |
|
| } |
| 149 |
112 |
| src = (UJ_UINT8*)SvPV(sv_str,PL_na); |
| 150 |
112 |
| len = sv_len(sv_str); |
| 151 |
|
| |
| 152 |
|
| ECHO_U2S((stderr,"Unicode::Japanese::(xs)utf8_sjis\n")); |
| 153 |
|
| ON_U2S( bin_dump("in ",src,len) ); |
| 154 |
|
| |
| 155 |
112 |
▶ | SV_Buf_init(&result,len+4); |
Branch: 2 branches
| Branch | True | False | Total |
| SV_Buf_init(&result,len+4); |
112 |
0 |
112 |
| SV_Buf_init(&result,len+4); |
54 |
58 |
112 |
|
| 156 |
112 |
| src_end = src+len; |
| 157 |
|
| |
| 158 |
232 |
▶ | while( src<src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| while( src<src_end ) |
120 |
112 |
232 |
|
| 159 |
|
| { |
| 160 |
|
| UJ_UINT32 ucs; |
| 161 |
|
| const UJ_UINT8* sjis_ptr; |
| 162 |
|
| |
| 163 |
120 |
▶ | if( *src<=0x7f ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( *src<=0x7f ) |
57 |
63 |
120 |
|
| 164 |
57 |
| { |
| 165 |
|
| /* append the block of contiguous ascii chars (ja:ASCII¤Ï¤Þ¤È¤á¤ÆÄɲáÁ) */ |
| 166 |
57 |
| int len = 1; |
| 167 |
823 |
▶ | while( src+len<src_end && src[len]<=0x7f ) |
Branch: 2 branches
| Branch | True | False | Total |
| while( src+len<src_end && src[len]<=0x7f ) |
766 |
57 |
823 |
| while( src+len<src_end && src[len]<=0x7f ) |
766 |
0 |
766 |
|
| 168 |
|
| { |
| 169 |
766 |
| ++len; |
| 170 |
|
| } |
| 171 |
57 |
▶ | SV_Buf_append_mem(&result,src,len); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result,src,len); |
0 |
57 |
57 |
| SV_Buf_append_mem(&result,src,len); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result,src,len); |
0 |
0 |
0 |
|
| 172 |
57 |
| src+=len; |
| 173 |
57 |
| continue; |
| 174 |
|
| } |
| 175 |
|
| |
| 176 |
|
| /* non-ascii */ |
| 177 |
63 |
▶ | if( 0xe0<=*src && *src<=0xef ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( 0xe0<=*src && *src<=0xef ) |
58 |
5 |
63 |
| if( 0xe0<=*src && *src<=0xef ) |
30 |
28 |
58 |
|
| 178 |
29 |
| { /* 3-bytes letters. most letters are 3-bytes. */ |
| 179 |
30 |
| const int utf8_len = 3; |
| 180 |
30 |
| const UJ_UINT32 ucs_min = 0x800; |
| 181 |
30 |
| const UJ_UINT32 ucs_max = 0xffff; |
| 182 |
|
| ECHO_U2S((stderr,"utf8-len: [%d]\n",utf8_len)); |
| 183 |
|
| /* check the length */ |
| 184 |
30 |
▶ | if( src+utf8_len<=src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src+utf8_len<=src_end ) |
0 |
30 |
30 |
|
| 185 |
|
| { /* noop */ |
| 186 |
|
| }else |
| 187 |
|
| { /* no enough space in the buffer */ |
| 188 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 189 |
0 |
| ++src; |
| 190 |
0 |
| continue; |
| 191 |
|
| } |
| 192 |
|
| /* check successive bytes */ |
| 193 |
30 |
▶ | if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf ) |
Branch: 4 branches
| Branch | True | False | Total |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf ) |
30 |
0 |
30 |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf ) |
30 |
0 |
30 |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf ) |
30 |
0 |
30 |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf ) |
30 |
0 |
30 |
|
| 194 |
|
| { /* noop */ |
| 195 |
|
| }else |
| 196 |
|
| { |
| 197 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 198 |
0 |
| ++src; |
| 199 |
0 |
| continue; |
| 200 |
|
| } |
| 201 |
|
| |
| 202 |
|
| /* compute the code point */ |
| 203 |
30 |
| ucs = ((src[0] & 0x0F)<<12)|((src[1] & 0x3F)<<6)|(src[2] & 0x3F); |
| 204 |
30 |
| src += utf8_len; |
| 205 |
30 |
▶ | if( ucs_min<=ucs && ucs<=ucs_max ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( ucs_min<=ucs && ucs<=ucs_max ) |
29 |
1 |
30 |
| if( ucs_min<=ucs && ucs<=ucs_max ) |
29 |
0 |
29 |
|
| 206 |
|
| { /* noop */ |
| 207 |
|
| }else |
| 208 |
|
| { /* illegal sequence */ |
| 209 |
1 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
1 |
1 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 210 |
1 |
| continue; |
| 211 |
|
| } |
| 212 |
|
| /* ok. */ |
| 213 |
33 |
▶ | }else if( 0xf0<=*src && *src<=0xf7 ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( 0xf0<=*src && *src<=0xf7 ) |
28 |
5 |
33 |
| }else if( 0xf0<=*src && *src<=0xf7 ) |
26 |
2 |
28 |
|
| 214 |
0 |
| { |
| 215 |
26 |
| const int utf8_len = 4; |
| 216 |
26 |
| const UJ_UINT32 ucs_min = 0x010000; |
| 217 |
26 |
| const UJ_UINT32 ucs_max = 0x10ffff; |
| 218 |
|
| ECHO_U2S((stderr,"utf8-len: [%d]\n",utf8_len)); |
| 219 |
|
| /* check the length */ |
| 220 |
26 |
▶ | if( src+utf8_len<=src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src+utf8_len<=src_end ) |
0 |
26 |
26 |
|
| 221 |
|
| { /* noop */ |
| 222 |
|
| }else |
| 223 |
|
| { /* no enough space in the buffer */ |
| 224 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 225 |
0 |
| ++src; |
| 226 |
0 |
| continue; |
| 227 |
|
| } |
| 228 |
|
| /* check successive bytes */ |
| 229 |
26 |
▶ | if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
Branch: 4 branches
| Branch | True | False | Total |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
26 |
0 |
26 |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
26 |
0 |
26 |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
26 |
0 |
26 |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
26 |
0 |
26 |
|
| 230 |
26 |
▶ | && 0x80<=src[3] && src[3]<=0xbf ) |
Branch: 2 branches
| Branch | True | False | Total |
| && 0x80<=src[3] && src[3]<=0xbf ) |
26 |
0 |
26 |
| && 0x80<=src[3] && src[3]<=0xbf ) |
26 |
0 |
26 |
|
| 231 |
|
| { /* noop */ |
| 232 |
|
| }else |
| 233 |
|
| { |
| 234 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 235 |
0 |
| ++src; |
| 236 |
0 |
| continue; |
| 237 |
|
| } |
| 238 |
|
| |
| 239 |
|
| /* compute the code point */ |
| 240 |
26 |
| ucs = ((src[0] & 0x07)<<18)|((src[1] & 0x3F)<<12)| |
| 241 |
26 |
| ((src[2] & 0x3f) << 6)|(src[3] & 0x3F); |
| 242 |
26 |
| src += utf8_len; |
| 243 |
26 |
▶ | if( ucs_min<=ucs && ucs<=ucs_max ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( ucs_min<=ucs && ucs<=ucs_max ) |
25 |
1 |
26 |
| if( ucs_min<=ucs && ucs<=ucs_max ) |
25 |
0 |
25 |
|
| 244 |
|
| { /* noop */ |
| 245 |
|
| }else |
| 246 |
|
| { /* illegal sequence */ |
| 247 |
1 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
1 |
1 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 248 |
1 |
| continue; |
| 249 |
|
| } |
| 250 |
|
| /* private area (emoji) */ |
| 251 |
25 |
▶ | if( 0x0f0000<=ucs && ucs<=0x0fffff ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( 0x0f0000<=ucs && ucs<=0x0fffff ) |
25 |
0 |
25 |
| if( 0x0f0000<=ucs && ucs<=0x0fffff ) |
25 |
0 |
25 |
|
| 252 |
|
| { |
| 253 |
25 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
25 |
25 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 254 |
25 |
| continue; |
| 255 |
|
| } |
| 256 |
|
| |
| 257 |
|
| /* > U+10FFFF isn't representable in UTF-8 (RFC 3629). */ |
| 258 |
0 |
▶ | if( ucs>0x10FFFF ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( ucs>0x10FFFF ) |
0 |
0 |
0 |
|
| 259 |
|
| { |
| 260 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 261 |
0 |
| continue; |
| 262 |
|
| } |
| 263 |
7 |
▶ | }else if( 0xc0<=*src && *src<=0xdf ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( 0xc0<=*src && *src<=0xdf ) |
7 |
0 |
7 |
| }else if( 0xc0<=*src && *src<=0xdf ) |
5 |
2 |
7 |
|
| 264 |
4 |
| { |
| 265 |
5 |
| const int utf8_len = 2; |
| 266 |
5 |
| const UJ_UINT32 ucs_min = 0x80; |
| 267 |
5 |
| const UJ_UINT32 ucs_max = 0x7ff; |
| 268 |
|
| ECHO_U2S((stderr,"utf8-len: [%d]\n",utf8_len)); |
| 269 |
|
| /* check the length */ |
| 270 |
5 |
▶ | if( src+utf8_len<=src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src+utf8_len<=src_end ) |
0 |
5 |
5 |
|
| 271 |
|
| { /* noop */ |
| 272 |
|
| }else |
| 273 |
|
| { /* no enough space in the buffer */ |
| 274 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 275 |
0 |
| ++src; |
| 276 |
0 |
| continue; |
| 277 |
|
| } |
| 278 |
|
| /* check follow sequences */ |
| 279 |
5 |
▶ | if( 0x80<=src[1] && src[1]<=0xbf ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( 0x80<=src[1] && src[1]<=0xbf ) |
5 |
0 |
5 |
| if( 0x80<=src[1] && src[1]<=0xbf ) |
5 |
0 |
5 |
|
| 280 |
|
| { /* noop */ |
| 281 |
|
| }else |
| 282 |
|
| { |
| 283 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 284 |
0 |
| ++src; |
| 285 |
0 |
| continue; |
| 286 |
|
| } |
| 287 |
|
| |
| 288 |
|
| /* compute the code point */ |
| 289 |
5 |
| ucs = ((src[0] & 0x1F)<<6)|(src[1] & 0x3F); |
| 290 |
5 |
| src += utf8_len; |
| 291 |
5 |
▶ | if( ucs_min<=ucs && ucs<=ucs_max ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( ucs_min<=ucs && ucs<=ucs_max ) |
4 |
1 |
5 |
| if( ucs_min<=ucs && ucs<=ucs_max ) |
4 |
0 |
4 |
|
| 292 |
|
| { /* noop */ |
| 293 |
|
| }else |
| 294 |
|
| { /* illegal sequence */ |
| 295 |
1 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
1 |
1 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 296 |
1 |
| continue; |
| 297 |
|
| } |
| 298 |
|
| |
| 299 |
|
| /* ok. */ |
| 300 |
2 |
▶ | }else if( 0xf8<=*src && *src<=0xfb ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( 0xf8<=*src && *src<=0xfb ) |
2 |
0 |
2 |
| }else if( 0xf8<=*src && *src<=0xfb ) |
1 |
1 |
2 |
|
| 301 |
1 |
| { |
| 302 |
1 |
| const int utf8_len = 5; |
| 303 |
|
| ECHO_U2S((stderr,"utf8-len: [%d]\n",utf8_len)); |
| 304 |
|
| /* check the length */ |
| 305 |
1 |
▶ | if( src+utf8_len<=src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src+utf8_len<=src_end ) |
0 |
1 |
1 |
|
| 306 |
|
| { /* noop */ |
| 307 |
|
| }else |
| 308 |
|
| { /* no enough space in the buffer */ |
| 309 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 310 |
0 |
| ++src; |
| 311 |
0 |
| continue; |
| 312 |
|
| } |
| 313 |
|
| /* check successive bytes */ |
| 314 |
1 |
▶ | if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
Branch: 4 branches
| Branch | True | False | Total |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
1 |
0 |
1 |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
1 |
0 |
1 |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
1 |
0 |
1 |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
1 |
0 |
1 |
|
| 315 |
1 |
▶ | && 0x80<=src[3] && src[3]<=0xbf && 0x80<=src[4] && src[4]<=0xbf ) |
Branch: 4 branches
| Branch | True | False | Total |
| && 0x80<=src[3] && src[3]<=0xbf && 0x80<=src[4] && src[4]<=0xbf ) |
1 |
0 |
1 |
| && 0x80<=src[3] && src[3]<=0xbf && 0x80<=src[4] && src[4]<=0xbf ) |
1 |
0 |
1 |
| && 0x80<=src[3] && src[3]<=0xbf && 0x80<=src[4] && src[4]<=0xbf ) |
1 |
0 |
1 |
| && 0x80<=src[3] && src[3]<=0xbf && 0x80<=src[4] && src[4]<=0xbf ) |
1 |
0 |
1 |
|
| 316 |
|
| { /* noop */ |
| 317 |
|
| }else |
| 318 |
|
| { |
| 319 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 320 |
0 |
| ++src; |
| 321 |
0 |
| continue; |
| 322 |
|
| } |
| 323 |
|
| |
| 324 |
|
| /* compute the code point */ |
| 325 |
|
| /* > U+10FFFF isn't representable in UTF-8 (RFC 3629). */ |
| 326 |
1 |
| src += utf8_len; |
| 327 |
1 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
1 |
1 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 328 |
1 |
| continue; |
| 329 |
1 |
▶ | }else if( 0xfc<=*src && *src<=0xfd ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( 0xfc<=*src && *src<=0xfd ) |
1 |
0 |
1 |
| }else if( 0xfc<=*src && *src<=0xfd ) |
1 |
0 |
1 |
|
| 330 |
1 |
| { |
| 331 |
1 |
| const int utf8_len = 6; |
| 332 |
|
| ECHO_U2S((stderr,"utf8-len: [%d]\n",utf8_len)); |
| 333 |
|
| /* check the length */ |
| 334 |
1 |
▶ | if( src+utf8_len<=src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src+utf8_len<=src_end ) |
0 |
1 |
1 |
|
| 335 |
|
| { /* noop */ |
| 336 |
|
| }else |
| 337 |
|
| { /* no enough space in the buffer */ |
| 338 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 339 |
0 |
| ++src; |
| 340 |
0 |
| continue; |
| 341 |
|
| } |
| 342 |
|
| /* check successive bytes */ |
| 343 |
1 |
▶ | if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
Branch: 4 branches
| Branch | True | False | Total |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
1 |
0 |
1 |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
1 |
0 |
1 |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
1 |
0 |
1 |
| if( 0x80<=src[1] && src[1]<=0xbf && 0x80<=src[2] && src[2]<=0xbf |
1 |
0 |
1 |
|
| 344 |
1 |
▶ | && 0x80<=src[3] && src[3]<=0xbf && 0x80<=src[4] && src[4]<=0xbf |
Branch: 4 branches
| Branch | True | False | Total |
| && 0x80<=src[3] && src[3]<=0xbf && 0x80<=src[4] && src[4]<=0xbf |
1 |
0 |
1 |
| && 0x80<=src[3] && src[3]<=0xbf && 0x80<=src[4] && src[4]<=0xbf |
1 |
0 |
1 |
| && 0x80<=src[3] && src[3]<=0xbf && 0x80<=src[4] && src[4]<=0xbf |
1 |
0 |
1 |
| && 0x80<=src[3] && src[3]<=0xbf && 0x80<=src[4] && src[4]<=0xbf |
1 |
0 |
1 |
|
| 345 |
1 |
▶ | && 0x80<=src[5] && src[5]<=0xbf ) |
Branch: 2 branches
| Branch | True | False | Total |
| && 0x80<=src[5] && src[5]<=0xbf ) |
1 |
0 |
1 |
| && 0x80<=src[5] && src[5]<=0xbf ) |
1 |
0 |
1 |
|
| 346 |
|
| { /* noop */ |
| 347 |
|
| }else |
| 348 |
|
| { |
| 349 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 350 |
0 |
| ++src; |
| 351 |
0 |
| continue; |
| 352 |
|
| } |
| 353 |
|
| |
| 354 |
|
| /* compute the code point */ |
| 355 |
|
| /* > U+10FFFF isn't representable in UTF-8 (RFC 3629). */ |
| 356 |
1 |
| src += utf8_len; |
| 357 |
1 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
1 |
1 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 358 |
1 |
| continue; |
| 359 |
|
| }else |
| 360 |
|
| { |
| 361 |
0 |
▶ | SV_Buf_append_ch(&result,'?'); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,'?'); |
0 |
0 |
0 |
|
| 362 |
0 |
| ++src; |
| 363 |
0 |
| continue; |
| 364 |
|
| } |
| 365 |
|
| |
| 366 |
|
| /* ucs => sjis */ |
| 367 |
|
| ECHO_U2S((stderr,"ucs [%04x]\n",ucs)); |
| 368 |
33 |
▶ | if( ucs<=0x9FFF ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( ucs<=0x9FFF ) |
27 |
6 |
33 |
|
| 369 |
|
| { |
| 370 |
27 |
| sjis_ptr = g_u2s_table + ucs*2; |
| 371 |
6 |
▶ | }else if( 0xF900<=ucs && ucs<=0xFFFF ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( 0xF900<=ucs && ucs<=0xFFFF ) |
6 |
0 |
6 |
| }else if( 0xF900<=ucs && ucs<=0xFFFF ) |
6 |
0 |
6 |
|
| 372 |
|
| { |
| 373 |
6 |
| sjis_ptr = g_u2s_table + (ucs - 0xF900 + 0xA000)*2; |
| 374 |
0 |
▶ | }else if( 0x0FE000<=ucs && ucs<=0x0FFFFF ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( 0x0FE000<=ucs && ucs<=0x0FFFFF ) |
0 |
0 |
0 |
| }else if( 0x0FE000<=ucs && ucs<=0x0FFFFF ) |
0 |
0 |
0 |
|
| 375 |
|
| { /* emoji. */ |
| 376 |
0 |
| sjis_ptr = char_unknown; /* "?\0" */ |
| 377 |
|
| }else |
| 378 |
|
| { |
| 379 |
0 |
| sjis_ptr = char_null; /* "\0\0" */ |
| 380 |
|
| } |
| 381 |
33 |
▶ | if( sjis_ptr[0]!=0 || sjis_ptr[1]!=0 ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( sjis_ptr[0]!=0 || sjis_ptr[1]!=0 ) |
3 |
30 |
33 |
| if( sjis_ptr[0]!=0 || sjis_ptr[1]!=0 ) |
0 |
3 |
3 |
|
| 382 |
|
| { /* this letter can actually be mapped. */ |
| 383 |
30 |
▶ | if( sjis_ptr[1]!=0 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( sjis_ptr[1]!=0 ) |
22 |
8 |
30 |
|
| 384 |
|
| { |
| 385 |
22 |
▶ | SV_Buf_append_mem(&result, sjis_ptr, 2); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result, sjis_ptr, 2); |
0 |
22 |
22 |
| SV_Buf_append_mem(&result, sjis_ptr, 2); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result, sjis_ptr, 2); |
0 |
0 |
0 |
|
| 386 |
|
| }else |
| 387 |
|
| { |
| 388 |
8 |
▶ | SV_Buf_append_ch(&result, *sjis_ptr); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result, *sjis_ptr); |
0 |
8 |
8 |
| SV_Buf_append_ch(&result, *sjis_ptr); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result, *sjis_ptr); |
0 |
0 |
0 |
|
| 389 |
|
| } |
| 390 |
3 |
▶ | }else if( ucs<=0x7F ) |
Branch: 1 branch
| Branch | True | False | Total |
| }else if( ucs<=0x7F ) |
0 |
3 |
3 |
|
| 391 |
|
| { |
| 392 |
0 |
▶ | SV_Buf_append_ch(&result,(UJ_UINT8)ucs); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,(UJ_UINT8)ucs); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,(UJ_UINT8)ucs); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,(UJ_UINT8)ucs); |
0 |
0 |
0 |
|
| 393 |
|
| }else |
| 394 |
|
| { |
| 395 |
6 |
▶ | SV_Buf_append_entityref(&result,ucs); |
Branch: 8 branches
| Branch | True | False | Total |
| SV_Buf_append_entityref(&result,ucs); |
3 |
0 |
3 |
| SV_Buf_append_entityref(&result,ucs); |
3 |
0 |
3 |
| SV_Buf_append_entityref(&result,ucs); |
3 |
0 |
3 |
| SV_Buf_append_entityref(&result,ucs); |
3 |
0 |
3 |
| SV_Buf_append_entityref(&result,ucs); |
3 |
0 |
3 |
| SV_Buf_append_entityref(&result,ucs); |
0 |
0 |
0 |
| SV_Buf_append_entityref(&result,ucs); |
0 |
0 |
0 |
| SV_Buf_append_entityref(&result,ucs); |
0 |
0 |
0 |
|
| 396 |
|
| } |
| 397 |
|
| } /* while */ |
| 398 |
|
| |
| 399 |
|
| ON_U2S( bin_dump("out",SV_Buf_getBegin(&result),SV_Buf_getLength(&result)) ); |
| 400 |
112 |
| SV_Buf_setLength(&result); |
| 401 |
|
| |
| 402 |
112 |
| return SV_Buf_getSv(&result); |
| 403 |
|
| } |
| 404 |
|
| |
| 405 |
|
| /* ---------------------------------------------------------------------------- |
| 406 |
|
| * End Of File. |
| 407 |
|
| * ------------------------------------------------------------------------- */ |