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