12 char *WcReplace = "?";
13 char *WcReplaceW = "??";
15 static Str wc_conv_to_ces(Str is, wc_ces ces);
18 wc_Str_conv(Str is, wc_ces f_ces, wc_ces t_ces)
20 if (f_ces != WC_CES_WTF)
21 is = (*WcCesInfo[WC_CES_INDEX(f_ces)].conv_from)(is, f_ces);
22 if (t_ces != WC_CES_WTF)
23 return wc_conv_to_ces(is, t_ces);
29 wc_Str_conv_strict(Str is, wc_ces f_ces, wc_ces t_ces)
32 wc_option opt = WcOption;
34 WcOption.strict_iso2022 = WC_TRUE;
35 WcOption.no_replace = WC_TRUE;
36 WcOption.fix_width_conv = WC_FALSE;
37 os = wc_Str_conv(is, f_ces, t_ces);
43 wc_conv_to_ces(Str is, wc_ces ces)
46 wc_uchar *sp = (wc_uchar *)is->ptr;
47 wc_uchar *ep = sp + is->length;
52 case WC_CES_HZ_GB_2312:
53 for (p = sp; p < ep && *p != '~' && *p < 0x80; p++)
56 case WC_CES_TCVN_5712:
57 case WC_CES_VISCII_11:
59 for (p = sp; p < ep && 0x20 <= *p && *p < 0x80; p++)
63 for (p = sp; p < ep && *p < 0x80; p++)
70 os = Strnew_size(is->length);
72 p--; /* for precompose */
74 Strcat_charp_n(os, is->ptr, (int)(p - sp));
76 wc_output_init(ces, &st);
79 case WC_CES_ISO_2022_JP:
80 case WC_CES_ISO_2022_JP_2:
81 case WC_CES_ISO_2022_JP_3:
82 case WC_CES_ISO_2022_CN:
83 case WC_CES_ISO_2022_KR:
84 case WC_CES_HZ_GB_2312:
85 case WC_CES_TCVN_5712:
86 case WC_CES_VISCII_11:
93 (*st.ces_info->push_to)(os, wtf_parse(&p), &st);
97 if (*p < 0x80 && wtf_width(p + 1)) {
98 Strcat_char(os, (char)*p);
101 (*st.ces_info->push_to)(os, wtf_parse(&p), &st);
106 wc_push_end(os, &st);
112 wc_Str_conv_with_detect(Str is, wc_ces *f_ces, wc_ces hint, wc_ces t_ces)
116 if (*f_ces == WC_CES_WTF || hint == WC_CES_WTF) {
119 } else if (WcOption.auto_detect == WC_OPT_DETECT_OFF) {
123 if (*f_ces & WC_CES_T_8BIT)
125 detect = wc_auto_detect(is->ptr, is->length, hint);
126 if (WcOption.auto_detect == WC_OPT_DETECT_ON) {
127 if ((detect & WC_CES_T_8BIT) ||
128 ((detect & WC_CES_T_NASCII) && ! (*f_ces & WC_CES_T_8BIT)))
131 if ((detect & WC_CES_T_ISO_2022) && ! (*f_ces & WC_CES_T_8BIT))
135 return wc_Str_conv(is, detect, t_ces);
139 wc_push_end(Str os, wc_status *st)
141 if (st->ces_info->id & WC_CES_T_ISO_2022)
142 wc_push_to_iso2022_end(os, st);
143 else if (st->ces_info->id == WC_CES_HZ_GB_2312)
144 wc_push_to_hz_end(os, st);
146 else if (st->ces_info->id == WC_CES_UTF_8)
147 wc_push_to_utf8_end(os, st);
148 else if (st->ces_info->id == WC_CES_UTF_7)
149 wc_push_to_utf7_end(os, st);