36
36
#define UNICODE_TABLE_UHC_DEF
37
37
#include "unicode_table_uhc.h"
38
38
39
+ static int mbfl_filt_conv_uhc_wchar_flush (mbfl_convert_filter * filter );
40
+
39
41
static const unsigned char mblen_table_uhc [] = { /* 0x81-0xFE */
40
42
1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
41
43
1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
@@ -74,7 +76,7 @@ const struct mbfl_convert_vtbl vtbl_uhc_wchar = {
74
76
mbfl_filt_conv_common_ctor ,
75
77
NULL ,
76
78
mbfl_filt_conv_uhc_wchar ,
77
- mbfl_filt_conv_common_flush ,
79
+ mbfl_filt_conv_uhc_wchar_flush ,
78
80
NULL ,
79
81
};
80
82
@@ -99,7 +101,7 @@ mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter)
99
101
case 0 :
100
102
if (c >= 0 && c < 0x80 ) { /* latin */
101
103
CK ((* filter -> output_function )(c , filter -> data ));
102
- } else if (c > 0x80 && c < 0xff && c != 0xc9 ) { /* dbcs lead byte */
104
+ } else if (c > 0x80 && c < 0xfe && c != 0xc9 ) { /* dbcs lead byte */
103
105
filter -> status = 1 ;
104
106
filter -> cache = c ;
105
107
} else {
@@ -113,23 +115,23 @@ mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter)
113
115
filter -> status = 0 ;
114
116
c1 = filter -> cache ;
115
117
116
- if (c1 >= 0x81 && c1 <= 0xa0 ) {
118
+ if (c1 >= 0x81 && c1 <= 0xa0 && c >= 0x41 && c <= 0xfe ) {
117
119
w = (c1 - 0x81 )* 190 + (c - 0x41 );
118
120
if (w >= 0 && w < uhc1_ucs_table_size ) {
119
121
flag = 1 ;
120
122
w = uhc1_ucs_table [w ];
121
123
} else {
122
124
w = 0 ;
123
125
}
124
- } else if (c1 >= 0xa1 && c1 <= 0xc6 ) {
126
+ } else if (c1 >= 0xa1 && c1 <= 0xc6 && c >= 0x41 && c <= 0xfe ) {
125
127
w = (c1 - 0xa1 )* 190 + (c - 0x41 );
126
128
if (w >= 0 && w < uhc2_ucs_table_size ) {
127
129
flag = 2 ;
128
130
w = uhc2_ucs_table [w ];
129
131
} else {
130
132
w = 0 ;
131
133
}
132
- } else if (c1 >= 0xc7 && c1 <= 0xfe ) {
134
+ } else if (c1 >= 0xc7 && c1 < 0xfe && c >= 0xa1 && c < = 0xfe ) {
133
135
w = (c1 - 0xc7 )* 94 + (c - 0xa1 );
134
136
if (w >= 0 && w < uhc3_ucs_table_size ) {
135
137
flag = 3 ;
@@ -147,14 +149,10 @@ mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter)
147
149
}
148
150
CK ((* filter -> output_function )(w , filter -> data ));
149
151
} else {
150
- if ((c >= 0 && c < 0x21 ) || c == 0x7f ) { /* CTLs */
151
- CK ((* filter -> output_function )(c , filter -> data ));
152
- } else {
153
- w = (c1 << 8 ) | c ;
154
- w &= MBFL_WCSGROUP_MASK ;
155
- w |= MBFL_WCSGROUP_THROUGH ;
156
- CK ((* filter -> output_function )(w , filter -> data ));
157
- }
152
+ w = (c1 << 8 ) | c ;
153
+ w &= MBFL_WCSGROUP_MASK ;
154
+ w |= MBFL_WCSGROUP_THROUGH ;
155
+ CK ((* filter -> output_function )(w , filter -> data ));
158
156
}
159
157
break ;
160
158
@@ -186,6 +184,7 @@ mbfl_filt_conv_wchar_uhc(int c, mbfl_convert_filter *filter)
186
184
} else if (c >= ucs_r2_uhc_table_min && c < ucs_r2_uhc_table_max ) {
187
185
s = ucs_r2_uhc_table [c - ucs_r2_uhc_table_min ];
188
186
}
187
+
189
188
if (s <= 0 ) {
190
189
c1 = c & ~MBFL_WCSPLANE_MASK ;
191
190
if (c1 == MBFL_WCSPLANE_UHC ) {
@@ -197,6 +196,7 @@ mbfl_filt_conv_wchar_uhc(int c, mbfl_convert_filter *filter)
197
196
s = -1 ;
198
197
}
199
198
}
199
+
200
200
if (s >= 0 ) {
201
201
if (s < 0x80 ) { /* latin */
202
202
CK ((* filter -> output_function )(s , filter -> data ));
@@ -210,3 +210,17 @@ mbfl_filt_conv_wchar_uhc(int c, mbfl_convert_filter *filter)
210
210
211
211
return c ;
212
212
}
213
+
214
+ static int mbfl_filt_conv_uhc_wchar_flush (mbfl_convert_filter * filter )
215
+ {
216
+ if (filter -> status == 1 ) {
217
+ /* 2-byte character was truncated */
218
+ CK ((* filter -> output_function )(filter -> cache | MBFL_WCSGROUP_THROUGH , filter -> data ));
219
+ }
220
+
221
+ if (filter -> flush_function ) {
222
+ (* filter -> flush_function )(filter -> data );
223
+ }
224
+
225
+ return 0 ;
226
+ }
0 commit comments