Skip to content

Commit 658db1f

Browse files
committed
Code cleanup in mbfilter_uhc.c
1 parent 0a8c007 commit 658db1f

File tree

1 file changed

+25
-46
lines changed

1 file changed

+25
-46
lines changed

ext/mbstring/libmbfl/filters/mbfilter_uhc.c

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@ const struct mbfl_convert_vtbl vtbl_wchar_uhc = {
9292

9393
#define CK(statement) do { if ((statement) < 0) return (-1); } while (0)
9494

95-
int
96-
mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter)
95+
int mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter)
9796
{
98-
int c1, w = 0, flag = 0;
97+
int w = 0, flag = 0;
9998

10099
switch (filter->status) {
101100
case 0:
@@ -105,15 +104,13 @@ mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter)
105104
filter->status = 1;
106105
filter->cache = c;
107106
} else {
108-
w = c & MBFL_WCSGROUP_MASK;
109-
w |= MBFL_WCSGROUP_THROUGH;
110-
CK((*filter->output_function)(w, filter->data));
107+
CK((*filter->output_function)(c | MBFL_WCSGROUP_THROUGH, filter->data));
111108
}
112109
break;
113110

114111
case 1: /* dbcs second byte */
115112
filter->status = 0;
116-
c1 = filter->cache;
113+
int c1 = filter->cache;
117114

118115
if (c1 >= 0x81 && c1 <= 0xa0 && c >= 0x41 && c <= 0xfe) {
119116
w = (c1 - 0x81)*190 + (c - 0x41);
@@ -141,19 +138,10 @@ mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter)
141138
}
142139
}
143140

144-
if (flag > 0) {
145-
if (w <= 0) {
146-
w = (c1 << 8) | c;
147-
w &= MBFL_WCSPLANE_MASK;
148-
w |= MBFL_WCSPLANE_UHC;
149-
}
150-
CK((*filter->output_function)(w, filter->data));
151-
} else {
152-
w = (c1 << 8) | c;
153-
w &= MBFL_WCSGROUP_MASK;
154-
w |= MBFL_WCSGROUP_THROUGH;
155-
CK((*filter->output_function)(w, filter->data));
141+
if (flag <= 0 || w <= 0) {
142+
w = (c1 << 8) | c | MBFL_WCSPLANE_UHC;
156143
}
144+
CK((*filter->output_function)(w, filter->data));
157145
break;
158146

159147
default:
@@ -164,10 +152,23 @@ mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter)
164152
return c;
165153
}
166154

167-
int
168-
mbfl_filt_conv_wchar_uhc(int c, mbfl_convert_filter *filter)
155+
static int mbfl_filt_conv_uhc_wchar_flush(mbfl_convert_filter *filter)
156+
{
157+
if (filter->status == 1) {
158+
/* 2-byte character was truncated */
159+
CK((*filter->output_function)(filter->cache | MBFL_WCSGROUP_THROUGH, filter->data));
160+
}
161+
162+
if (filter->flush_function) {
163+
(*filter->flush_function)(filter->data);
164+
}
165+
166+
return 0;
167+
}
168+
169+
int mbfl_filt_conv_wchar_uhc(int c, mbfl_convert_filter *filter)
169170
{
170-
int c1, s = 0;
171+
int s = 0;
171172

172173
if (c >= ucs_a1_uhc_table_min && c < ucs_a1_uhc_table_max) {
173174
s = ucs_a1_uhc_table[c - ucs_a1_uhc_table_min];
@@ -185,16 +186,8 @@ mbfl_filt_conv_wchar_uhc(int c, mbfl_convert_filter *filter)
185186
s = ucs_r2_uhc_table[c - ucs_r2_uhc_table_min];
186187
}
187188

188-
if (s <= 0) {
189-
c1 = c & ~MBFL_WCSPLANE_MASK;
190-
if (c1 == MBFL_WCSPLANE_UHC) {
191-
s = c & MBFL_WCSPLANE_MASK;
192-
}
193-
if (c == 0) {
194-
s = 0;
195-
} else if (s <= 0) {
196-
s = -1;
197-
}
189+
if (s == 0 && c != 0) {
190+
s = -1;
198191
}
199192

200193
if (s >= 0) {
@@ -210,17 +203,3 @@ mbfl_filt_conv_wchar_uhc(int c, mbfl_convert_filter *filter)
210203

211204
return c;
212205
}
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

Comments
 (0)