|
31 | 31 | #include "unicode_table_jis.h"
|
32 | 32 | #include "cp932_table.h"
|
33 | 33 |
|
34 |
| -static void mbfl_filt_conv_wchar_cp50220_ctor(mbfl_convert_filter *filt); |
35 |
| -static void mbfl_filt_conv_wchar_cp50220_dtor(mbfl_convert_filter *filt); |
36 | 34 | static int mbfl_filt_conv_cp5022x_wchar_flush(mbfl_convert_filter *filter);
|
| 35 | +static int mbfl_filt_conv_wchar_cp50220_flush(mbfl_convert_filter *filter); |
| 36 | +static int mbfl_filt_conv_wchar_cp50220(int c, mbfl_convert_filter *filter); |
37 | 37 |
|
38 | 38 | /* Previously, a dubious 'encoding' called 'cp50220raw' was supported
|
39 | 39 | * This was just CP50220, but the implementation was less strict regarding
|
@@ -92,10 +92,10 @@ const struct mbfl_convert_vtbl vtbl_cp50220_wchar = {
|
92 | 92 | const struct mbfl_convert_vtbl vtbl_wchar_cp50220 = {
|
93 | 93 | mbfl_no_encoding_wchar,
|
94 | 94 | mbfl_no_encoding_cp50220,
|
95 |
| - mbfl_filt_conv_wchar_cp50220_ctor, |
96 |
| - mbfl_filt_conv_wchar_cp50220_dtor, |
97 |
| - mbfl_filt_conv_wchar_cp50221, |
98 |
| - mbfl_filt_conv_any_jis_flush, |
| 95 | + mbfl_filt_conv_common_ctor, |
| 96 | + NULL, |
| 97 | + mbfl_filt_conv_wchar_cp50220, |
| 98 | + mbfl_filt_conv_wchar_cp50220_flush, |
99 | 99 | NULL,
|
100 | 100 | };
|
101 | 101 |
|
@@ -318,35 +318,45 @@ static int mbfl_filt_conv_cp5022x_wchar_flush(mbfl_convert_filter *filter)
|
318 | 318 | return 0;
|
319 | 319 | }
|
320 | 320 |
|
321 |
| -/* |
322 |
| - * wchar => CP50220 |
323 |
| - */ |
324 |
| -static void mbfl_filt_conv_wchar_cp50220_ctor(mbfl_convert_filter *filt) |
| 321 | +static int mbfl_filt_conv_wchar_cp50220(int c, mbfl_convert_filter *filter) |
325 | 322 | {
|
326 |
| - /* Insert a new convert filter into the chain, after this one, which will |
327 |
| - * actually perform the CP50220 conversion. Alter this filter so that it |
328 |
| - * converts halfwidth katakana instead */ |
329 |
| - mbfl_convert_filter *cp50220_filt = emalloc(sizeof(mbfl_convert_filter)); |
330 |
| - *cp50220_filt = *filt; |
331 |
| - |
332 |
| - /* Reinitialize */ |
333 |
| - mbfl_filt_conv_common_ctor(filt); |
334 |
| - filt->filter_function = vtbl_tl_jisx0201_jisx0208.filter_function; |
335 |
| - filt->filter_flush = (filter_flush_t)vtbl_tl_jisx0201_jisx0208.filter_flush; |
336 |
| - filt->output_function = (output_function_t)cp50220_filt->filter_function; |
337 |
| - filt->flush_function = (flush_function_t)cp50220_filt->filter_flush; |
338 |
| - filt->data = cp50220_filt; |
339 |
| - filt->opaque = (void*)(MBFL_FILT_TL_HAN2ZEN_KATAKANA | MBFL_FILT_TL_HAN2ZEN_GLUE); |
| 323 | + int mode = MBFL_FILT_TL_HAN2ZEN_KATAKANA | MBFL_FILT_TL_HAN2ZEN_GLUE, second = 0; |
| 324 | + bool consumed = false; |
| 325 | + |
| 326 | + if (filter->cache) { |
| 327 | + int s = mbfl_convert_kana(filter->cache, c, &consumed, &second, mode); |
| 328 | + filter->cache = consumed ? 0 : c; |
| 329 | + mbfl_filt_conv_wchar_cp50221(s, filter); |
| 330 | + if (second) { |
| 331 | + mbfl_filt_conv_wchar_cp50221(second, filter); |
| 332 | + } |
| 333 | + } else if (c == 0) { |
| 334 | + /* This case has to be handled separately, since `filter->cache == 0` means |
| 335 | + * no codepoint is cached */ |
| 336 | + (*filter->output_function)(0, filter->data); |
| 337 | + } else { |
| 338 | + filter->cache = c; |
| 339 | + } |
| 340 | + |
| 341 | + return 0; |
340 | 342 | }
|
341 | 343 |
|
342 |
| -static void mbfl_filt_conv_wchar_cp50220_dtor(mbfl_convert_filter *filt) |
| 344 | +static int mbfl_filt_conv_wchar_cp50220_flush(mbfl_convert_filter *filter) |
343 | 345 | {
|
344 |
| - efree(filt->data); |
| 346 | + int mode = MBFL_FILT_TL_HAN2ZEN_KATAKANA | MBFL_FILT_TL_HAN2ZEN_GLUE, second = 0; |
| 347 | + |
| 348 | + if (filter->cache) { |
| 349 | + int s = mbfl_convert_kana(filter->cache, 0, NULL, &second, mode); |
| 350 | + mbfl_filt_conv_wchar_cp50221(s, filter); |
| 351 | + if (second) { |
| 352 | + mbfl_filt_conv_wchar_cp50221(s, filter); |
| 353 | + } |
| 354 | + filter->cache = 0; |
| 355 | + } |
| 356 | + |
| 357 | + return mbfl_filt_conv_any_jis_flush(filter); |
345 | 358 | }
|
346 | 359 |
|
347 |
| -/* |
348 |
| - * wchar => CP50221 |
349 |
| - */ |
350 | 360 | int mbfl_filt_conv_wchar_cp50221(int c, mbfl_convert_filter *filter)
|
351 | 361 | {
|
352 | 362 | int s = 0;
|
|
0 commit comments