| 1 |
|
| /* ---------------------------------------------------------------------------- |
| 2 |
|
| * ucs2_utf8.c |
| 3 |
|
| * ---------------------------------------------------------------------------- |
| 4 |
|
| * Mastering programed by YAMASHINA Hio |
| 5 |
|
| * ---------------------------------------------------------------------------- |
| 6 |
|
| * $Id: ucs2_utf8.c 4654 2006-07-03 01:33:16Z hio $ |
| 7 |
|
| * ------------------------------------------------------------------------- */ |
| 8 |
|
| |
| 9 |
|
| |
| 10 |
|
| #include "Japanese.h" |
| 11 |
|
| |
| 12 |
|
| #undef ENABLE_SURROGATE_PAIR |
| 13 |
|
| |
| 14 |
|
| /* ---------------------------------------------------------------------------- |
| 15 |
|
| * convert ucs2 into utf-8 |
| 16 |
|
| * ------------------------------------------------------------------------- */ |
| 17 |
|
| EXTERN_C |
| 18 |
|
| SV* |
| 19 |
37 |
| xs_ucs2_utf8(SV* sv_str) |
| 20 |
|
| { |
| 21 |
|
| UJ_UINT8* src; |
| 22 |
|
| int len; |
| 23 |
|
| SV_Buf result; |
| 24 |
|
| const UJ_UINT8* src_end; |
| 25 |
|
| UJ_UINT8 buf[4]; |
| 26 |
|
| |
| 27 |
37 |
▶ | if( sv_str==&PL_sv_undef ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( sv_str==&PL_sv_undef ) |
0 |
37 |
37 |
|
| 28 |
|
| { |
| 29 |
0 |
| return newSVpvn("",0); |
| 30 |
|
| } |
| 31 |
|
| |
| 32 |
37 |
| src = (UJ_UINT8*)SvPV(sv_str,PL_na); |
| 33 |
37 |
| len = sv_len(sv_str); |
| 34 |
37 |
| src_end = src+(len&~1); |
| 35 |
|
| /*fprintf(stderr,"Unicode::Japanese::(xs)ucs2_utf8\n",len);*/ |
| 36 |
|
| /*bin_dump("in ",src,len);*/ |
| 37 |
37 |
▶ | SV_Buf_init(&result,len*3/2+4); |
Branch: 2 branches
| Branch | True | False | Total |
| SV_Buf_init(&result,len*3/2+4); |
37 |
0 |
37 |
| SV_Buf_init(&result,len*3/2+4); |
0 |
37 |
37 |
|
| 38 |
|
| |
| 39 |
37 |
▶ | if( len&1 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( len&1 ) |
0 |
37 |
37 |
|
| 40 |
|
| { |
| 41 |
0 |
| Perl_croak(aTHX_ "Unicode::Japanese::ucs2_utf8, invalid length (not 2*n)"); |
| 42 |
|
| } |
| 43 |
|
| |
| 44 |
74 |
▶ | for(; src<src_end; src+=2 ) |
Branch: 1 branch
| Branch | True | False | Total |
| for(; src<src_end; src+=2 ) |
37 |
37 |
74 |
|
| 45 |
|
| { |
| 46 |
37 |
| const UJ_UINT16 ucs2 = (src[0]<<8)+src[1]; /* ntohs */ |
| 47 |
37 |
▶ | if( ucs2<0x80 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( ucs2<0x80 ) |
0 |
37 |
37 |
|
| 48 |
|
| { |
| 49 |
0 |
▶ | SV_Buf_append_ch(&result,(UJ_UINT8)ucs2); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch(&result,(UJ_UINT8)ucs2); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,(UJ_UINT8)ucs2); |
0 |
0 |
0 |
| SV_Buf_append_ch(&result,(UJ_UINT8)ucs2); |
0 |
0 |
0 |
|
| 50 |
37 |
▶ | }else if( ucs2<0x800 ) |
Branch: 1 branch
| Branch | True | False | Total |
| }else if( ucs2<0x800 ) |
4 |
33 |
37 |
|
| 51 |
|
| { |
| 52 |
4 |
| buf[0] = 0xC0 | (ucs2 >> 6); |
| 53 |
4 |
| buf[1] = 0x80 | (ucs2 & 0x3F); |
| 54 |
4 |
▶ | SV_Buf_append_mem(&result, buf, 2); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result, buf, 2); |
0 |
4 |
4 |
| SV_Buf_append_mem(&result, buf, 2); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result, buf, 2); |
0 |
0 |
0 |
|
| 55 |
33 |
▶ | }else if( !(0xd800 <= ucs2 && ucs2 <= 0xdfff) ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( !(0xd800 <= ucs2 && ucs2 <= 0xdfff) ) |
12 |
21 |
33 |
| }else if( !(0xd800 <= ucs2 && ucs2 <= 0xdfff) ) |
12 |
0 |
12 |
|
| 56 |
|
| { /* normal char (non surrogate pair) */ |
| 57 |
33 |
| buf[0] = 0xE0 | (ucs2 >> 12); |
| 58 |
33 |
| buf[1] = 0x80 | ((ucs2 >> 6) & 0x3F); |
| 59 |
33 |
| buf[2] = 0x80 | (ucs2 & 0x3F); |
| 60 |
33 |
▶ | SV_Buf_append_mem(&result, buf, 3); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_mem(&result, buf, 3); |
0 |
33 |
33 |
| SV_Buf_append_mem(&result, buf, 3); |
0 |
0 |
0 |
| SV_Buf_append_mem(&result, buf, 3); |
0 |
0 |
0 |
|
| 61 |
|
| }else |
| 62 |
|
| { /* surrogate pair */ |
| 63 |
0 |
▶ | if( src+2<src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src+2<src_end ) |
0 |
0 |
0 |
|
| 64 |
|
| { |
| 65 |
|
| #ifdef ENABLE_SURROGATE_PAIR |
| 66 |
|
| const UJ_UINT16 ucs2a = (src[0]<<8)+src[1]; /* ntohs */ |
| 67 |
|
| const UJ_UINT32 ucs4 = ((ucs2&0x03FF)<<10|(ucs2a&0x3FF))+0x010000; |
| 68 |
|
| src += 2; |
| 69 |
|
| if( 0x010000<=ucs4 && ucs4<=0x1FFFFF ) |
| 70 |
|
| { |
| 71 |
|
| buf[0] = 0xF0 | ((ucs2>>18) & 0x3F); |
| 72 |
|
| buf[1] = 0x80 | ((ucs2>>12) & 0x3F); |
| 73 |
|
| buf[2] = 0x80 | ((ucs2>>6) & 0x3F); |
| 74 |
|
| buf[3] = 0x80 | (ucs2 & 0x3F); |
| 75 |
|
| SV_Buf_append_mem(&result, buf, 4); |
| 76 |
|
| }else |
| 77 |
|
| { |
| 78 |
|
| /* utf8 not support >= U+1FFFFF */ |
| 79 |
|
| /* or illegal representation */ |
| 80 |
|
| SV_Buf_append_ch(&result,'?'); |
| 81 |
|
| } |
| 82 |
|
| #else |
| 83 |
|
| { |
| 84 |
|
| /* surrogate pair disabled. */ |
| 85 |
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 |
|
| 86 |
|
| } |
| 87 |
|
| #endif |
| 88 |
|
| }else |
| 89 |
|
| { |
| 90 |
|
| /* no 2nd char of surrogate pair */ |
| 91 |
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 |
|
| 92 |
|
| } |
| 93 |
|
| } |
| 94 |
|
| } |
| 95 |
|
| |
| 96 |
|
| /*bin_dump("out",result.getBegin(),result.getLength()); */ |
| 97 |
37 |
| SV_Buf_setLength(&result); |
| 98 |
|
| |
| 99 |
37 |
| return SV_Buf_getSv(&result); |
| 100 |
|
| } |
| 101 |
|
| |
| 102 |
|
| /* ---------------------------------------------------------------------------- |
| 103 |
|
| * convert utf-8 into ucs2 |
| 104 |
|
| * ------------------------------------------------------------------------- */ |
| 105 |
|
| EXTERN_C |
| 106 |
|
| SV* |
| 107 |
35 |
| xs_utf8_ucs2(SV* sv_str) |
| 108 |
|
| { |
| 109 |
|
| UJ_UINT8* src; |
| 110 |
|
| int len; |
| 111 |
|
| SV_Buf result; |
| 112 |
|
| const UJ_UINT8* src_end; |
| 113 |
|
| |
| 114 |
35 |
▶ | if( sv_str==&PL_sv_undef ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( sv_str==&PL_sv_undef ) |
0 |
35 |
35 |
|
| 115 |
|
| { |
| 116 |
0 |
| return newSVpvn("",0); |
| 117 |
|
| } |
| 118 |
|
| |
| 119 |
35 |
| src = (UJ_UINT8*)SvPV(sv_str,PL_na); |
| 120 |
35 |
| len = sv_len(sv_str); |
| 121 |
35 |
| src_end = src+len; |
| 122 |
|
| /*fprintf(stderr,"Unicode::Japanese::(xs)utf8_ucs2\n",len); */ |
| 123 |
|
| /*bin_dump("in ",src,len); */ |
| 124 |
35 |
▶ | SV_Buf_init(&result,len*2); |
Branch: 2 branches
| Branch | True | False | Total |
| SV_Buf_init(&result,len*2); |
35 |
0 |
35 |
| SV_Buf_init(&result,len*2); |
0 |
35 |
35 |
|
| 125 |
|
| |
| 126 |
70 |
▶ | while( src<src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| while( src<src_end ) |
35 |
35 |
70 |
|
| 127 |
|
| { |
| 128 |
|
| UJ_UINT32 ucs; |
| 129 |
35 |
▶ | if( *src<=0x7f ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( *src<=0x7f ) |
1 |
34 |
35 |
|
| 130 |
|
| { /* ascii. */ |
| 131 |
2 |
▶ | SV_Buf_append_ch2(&result,htons(*src)); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons(*src)); |
1 |
0 |
1 |
| SV_Buf_append_ch2(&result,htons(*src)); |
1 |
0 |
1 |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
1 |
1 |
|
| 132 |
1 |
| ++src; |
| 133 |
1 |
| continue; |
| 134 |
|
| } |
| 135 |
34 |
▶ | if( 0xc0<=*src && *src<=0xdf ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( 0xc0<=*src && *src<=0xdf ) |
34 |
0 |
34 |
| if( 0xc0<=*src && *src<=0xdf ) |
1 |
33 |
34 |
|
| 136 |
0 |
| { /* length [2] */ |
| 137 |
1 |
| const int utf8_len = 2; |
| 138 |
1 |
| const UJ_UINT32 ucs_min = 0x80; |
| 139 |
1 |
| const UJ_UINT32 ucs_max = 0x7ff; |
| 140 |
1 |
▶ | if( src+1>=src_end || |
Branch: 1 branch
| Branch | True | False | Total |
| if( src+1>=src_end || |
1 |
0 |
1 |
|
| 141 |
1 |
▶ | src[1]<0x80 || 0xbf<src[1] ) |
Branch: 2 branches
| Branch | True | False | Total |
| src[1]<0x80 || 0xbf<src[1] ) |
1 |
0 |
1 |
| src[1]<0x80 || 0xbf<src[1] ) |
0 |
1 |
1 |
|
| 142 |
|
| { |
| 143 |
0 |
▶ | SV_Buf_append_ch2(&result,htons(*src)); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
0 |
0 |
|
| 144 |
0 |
| ++src; |
| 145 |
0 |
| continue; |
| 146 |
|
| } |
| 147 |
|
| |
| 148 |
|
| /* compute code point */ |
| 149 |
1 |
| ucs = ((src[0] & 0x1F)<<6)|(src[1] & 0x3F); |
| 150 |
1 |
| src += utf8_len; |
| 151 |
1 |
▶ | if( ucs_min<=ucs && ucs<=ucs_max ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( ucs_min<=ucs && ucs<=ucs_max ) |
0 |
1 |
1 |
| if( ucs_min<=ucs && ucs<=ucs_max ) |
0 |
0 |
0 |
|
| 152 |
|
| { /* noop */ |
| 153 |
|
| }else |
| 154 |
|
| { /* illegal sequence */ |
| 155 |
1 |
▶ | SV_Buf_append_ch2(&result,htons('?')); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
1 |
1 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
|
| 156 |
1 |
| continue; |
| 157 |
|
| } |
| 158 |
|
| |
| 159 |
|
| /* ok. */ |
| 160 |
33 |
▶ | }else if( 0xe0<=*src && *src<=0xef ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( 0xe0<=*src && *src<=0xef ) |
33 |
0 |
33 |
| }else if( 0xe0<=*src && *src<=0xef ) |
30 |
3 |
33 |
|
| 161 |
29 |
| { /* length [3] */ |
| 162 |
30 |
| const int utf8_len = 3; |
| 163 |
30 |
| const UJ_UINT32 ucs_min = 0x800; |
| 164 |
30 |
| const UJ_UINT32 ucs_max = 0xffff; |
| 165 |
30 |
▶ | if( src+2>=src_end || |
Branch: 1 branch
| Branch | True | False | Total |
| if( src+2>=src_end || |
30 |
0 |
30 |
|
| 166 |
30 |
▶ | src[1]<0x80 || 0xbf<src[1] || |
Branch: 2 branches
| Branch | True | False | Total |
| src[1]<0x80 || 0xbf<src[1] || |
30 |
0 |
30 |
| src[1]<0x80 || 0xbf<src[1] || |
30 |
0 |
30 |
|
| 167 |
30 |
▶ | src[2]<0x80 || 0xbf<src[2] ) |
Branch: 2 branches
| Branch | True | False | Total |
| src[2]<0x80 || 0xbf<src[2] ) |
30 |
0 |
30 |
| src[2]<0x80 || 0xbf<src[2] ) |
0 |
30 |
30 |
|
| 168 |
|
| { |
| 169 |
0 |
▶ | SV_Buf_append_ch2(&result,htons(*src)); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
0 |
0 |
|
| 170 |
0 |
| ++src; |
| 171 |
0 |
| continue; |
| 172 |
|
| } |
| 173 |
|
| |
| 174 |
|
| /* compute code point */ |
| 175 |
30 |
| ucs = ((src[0] & 0x0F)<<12)|((src[1] & 0x3F)<<6)|(src[2] & 0x3F); |
| 176 |
30 |
| src += utf8_len; |
| 177 |
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 |
|
| 178 |
|
| { /* noop */ |
| 179 |
|
| }else |
| 180 |
|
| { /* illegal sequence */ |
| 181 |
1 |
▶ | SV_Buf_append_ch2(&result,htons('?')); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
1 |
1 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
|
| 182 |
1 |
| continue; |
| 183 |
|
| } |
| 184 |
|
| |
| 185 |
29 |
▶ | if( ucs<0xD800 || ucs>0xDBFF ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( ucs<0xD800 || ucs>0xDBFF ) |
12 |
17 |
29 |
| if( ucs<0xD800 || ucs>0xDBFF ) |
0 |
12 |
12 |
|
| 186 |
|
| { /* normal char, noop */ |
| 187 |
|
| }else |
| 188 |
|
| { /* delete surrogate pair range */ |
| 189 |
0 |
▶ | SV_Buf_append_ch2(&result,htons('?')); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
|
| 190 |
0 |
| continue; |
| 191 |
|
| } |
| 192 |
|
| |
| 193 |
|
| /* ok. */ |
| 194 |
3 |
▶ | }else if( 0xf0<=*src && *src<=0xf7 ) |
Branch: 2 branches
| Branch | True | False | Total |
| }else if( 0xf0<=*src && *src<=0xf7 ) |
3 |
0 |
3 |
| }else if( 0xf0<=*src && *src<=0xf7 ) |
1 |
2 |
3 |
|
| 195 |
0 |
| { /* length [4] */ |
| 196 |
1 |
| const int utf8_len = 4; |
| 197 |
1 |
| const UJ_UINT32 ucs_min = 0x010000; |
| 198 |
1 |
| const UJ_UINT32 ucs_max = 0x10ffff; |
| 199 |
1 |
▶ | if( src+3>=src_end || |
Branch: 1 branch
| Branch | True | False | Total |
| if( src+3>=src_end || |
1 |
0 |
1 |
|
| 200 |
1 |
▶ | src[1]<0x80 || 0xbf<src[1] || |
Branch: 2 branches
| Branch | True | False | Total |
| src[1]<0x80 || 0xbf<src[1] || |
1 |
0 |
1 |
| src[1]<0x80 || 0xbf<src[1] || |
1 |
0 |
1 |
|
| 201 |
1 |
▶ | src[2]<0x80 || 0xbf<src[2] || |
Branch: 2 branches
| Branch | True | False | Total |
| src[2]<0x80 || 0xbf<src[2] || |
1 |
0 |
1 |
| src[2]<0x80 || 0xbf<src[2] || |
1 |
0 |
1 |
|
| 202 |
1 |
▶ | src[3]<0x80 || 0xbf<src[3] ) |
Branch: 2 branches
| Branch | True | False | Total |
| src[3]<0x80 || 0xbf<src[3] ) |
1 |
0 |
1 |
| src[3]<0x80 || 0xbf<src[3] ) |
0 |
1 |
1 |
|
| 203 |
|
| { |
| 204 |
0 |
▶ | SV_Buf_append_ch2(&result,htons(*src)); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
0 |
0 |
|
| 205 |
0 |
| ++src; |
| 206 |
0 |
| continue; |
| 207 |
|
| } |
| 208 |
|
| |
| 209 |
|
| /* compute code point */ |
| 210 |
1 |
| ucs = ((src[0] & 0x07)<<18)|((src[1] & 0x3F)<<12)| |
| 211 |
1 |
| ((src[2] & 0x3f) << 6)|(src[3] & 0x3F); |
| 212 |
1 |
| src += utf8_len; |
| 213 |
1 |
▶ | if( ucs_min<=ucs && ucs<=ucs_max ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( ucs_min<=ucs && ucs<=ucs_max ) |
0 |
1 |
1 |
| if( ucs_min<=ucs && ucs<=ucs_max ) |
0 |
0 |
0 |
|
| 214 |
|
| { /* noop */ |
| 215 |
|
| }else |
| 216 |
|
| { /* illegal sequence */ |
| 217 |
1 |
▶ | SV_Buf_append_ch2(&result,htons('?')); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
1 |
1 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
|
| 218 |
1 |
| continue; |
| 219 |
|
| } |
| 220 |
|
| |
| 221 |
|
| #if ENABLE_SURROGATE_PAIR |
| 222 |
|
| { /* encode surrogate pair */ |
| 223 |
|
| const UJ_UINT32 surrogate = ucs - 0x010000; |
| 224 |
|
| SV_Buf_append_ch2(&result,htons(((surrogate>>10)&0x03FF)|0xD800)); |
| 225 |
|
| SV_Buf_append_ch2(&result,htons(((surrogate )&0x03FF)|0xDC00)); |
| 226 |
|
| continue; |
| 227 |
|
| } |
| 228 |
|
| #else |
| 229 |
|
| { /* not supported */ |
| 230 |
0 |
▶ | SV_Buf_append_ch2(&result,htons('?')); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
|
| 231 |
0 |
| continue; |
| 232 |
|
| } |
| 233 |
|
| #endif |
| 234 |
|
| |
| 235 |
|
| /* ok. */ |
| 236 |
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 |
|
| 237 |
1 |
| { |
| 238 |
1 |
| const int utf8_len = 5; |
| 239 |
1 |
▶ | if( src+utf8_len<=src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src+utf8_len<=src_end ) |
0 |
1 |
1 |
|
| 240 |
|
| { /* noop */ |
| 241 |
|
| }else |
| 242 |
|
| { /* no enough sequence */ |
| 243 |
0 |
▶ | SV_Buf_append_ch2(&result,htons('?')); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
|
| 244 |
0 |
| ++src; |
| 245 |
0 |
| continue; |
| 246 |
|
| } |
| 247 |
|
| /* check follow sequences */ |
| 248 |
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 |
|
| 249 |
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 |
|
| 250 |
|
| { /* noop */ |
| 251 |
|
| }else |
| 252 |
|
| { |
| 253 |
0 |
▶ | SV_Buf_append_ch2(&result,htons('?')); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
|
| 254 |
0 |
| ++src; |
| 255 |
0 |
| continue; |
| 256 |
|
| } |
| 257 |
|
| |
| 258 |
|
| /* compute code point */ |
| 259 |
1 |
| src += utf8_len; |
| 260 |
1 |
▶ | SV_Buf_append_ch2(&result,htons('?')); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
1 |
1 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
|
| 261 |
1 |
| continue; |
| 262 |
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 |
|
| 263 |
1 |
| { |
| 264 |
1 |
| const int utf8_len = 6; |
| 265 |
1 |
▶ | if( src+utf8_len<=src_end ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( src+utf8_len<=src_end ) |
0 |
1 |
1 |
|
| 266 |
|
| { /* noop */ |
| 267 |
|
| }else |
| 268 |
|
| { /* no enough sequence */ |
| 269 |
0 |
▶ | SV_Buf_append_ch2(&result,htons('?')); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
|
| 270 |
0 |
| ++src; |
| 271 |
0 |
| continue; |
| 272 |
|
| } |
| 273 |
|
| /* check follow sequences */ |
| 274 |
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 |
|
| 275 |
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 |
|
| 276 |
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 |
|
| 277 |
|
| { /* noop */ |
| 278 |
|
| }else |
| 279 |
|
| { |
| 280 |
0 |
▶ | SV_Buf_append_ch2(&result,htons('?')); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
|
| 281 |
0 |
| ++src; |
| 282 |
0 |
| continue; |
| 283 |
|
| } |
| 284 |
|
| |
| 285 |
|
| /* compute code point */ |
| 286 |
1 |
| src += utf8_len; |
| 287 |
1 |
▶ | SV_Buf_append_ch2(&result,htons('?')); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
1 |
1 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
|
| 288 |
1 |
| continue; |
| 289 |
|
| }else |
| 290 |
|
| { /* invalid */ |
| 291 |
0 |
▶ | SV_Buf_append_ch2(&result,htons(*src)); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons(*src)); |
0 |
0 |
0 |
|
| 292 |
0 |
| ++src; |
| 293 |
0 |
| continue; |
| 294 |
|
| } |
| 295 |
|
| |
| 296 |
29 |
▶ | if( ucs & ~0xFFFF ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( ucs & ~0xFFFF ) |
0 |
29 |
29 |
|
| 297 |
|
| { /* ucs2¤ÎÈϰϳ° (ucs4¤ÎÈϰÏ) */ |
| 298 |
0 |
▶ | SV_Buf_append_ch2(&result,htons('?')); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons('?')); |
0 |
0 |
0 |
|
| 299 |
0 |
| continue; |
| 300 |
|
| } |
| 301 |
29 |
▶ | SV_Buf_append_ch2(&result,htons(ucs)); |
Branch: 3 branches
| Branch | True | False | Total |
| SV_Buf_append_ch2(&result,htons(ucs)); |
0 |
29 |
29 |
| SV_Buf_append_ch2(&result,htons(ucs)); |
0 |
0 |
0 |
| SV_Buf_append_ch2(&result,htons(ucs)); |
0 |
0 |
0 |
|
| 302 |
|
| /*bin_dump("now",dst_begin,dst-dst_begin); */ |
| 303 |
|
| } |
| 304 |
|
| |
| 305 |
|
| /*bin_dump("out",result.getBegin(),result.getLength()); */ |
| 306 |
35 |
| SV_Buf_setLength(&result); |
| 307 |
|
| |
| 308 |
35 |
| return SV_Buf_getSv(&result); |
| 309 |
|
| } |
| 310 |
|
| |
| 311 |
|
| /* ---------------------------------------------------------------------------- |
| 312 |
|
| * End Of File. |
| 313 |
|
| * ------------------------------------------------------------------------- */ |