MCPcopy Create free account
hub / github.com/acl-dev/acl / update_begin

Method update_begin

lib_acl_cpp/src/stdlib/charset_conv.cpp:207–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205 || ((x) != NULL && (y) != NULL && !strcasecmp((x), (y))))
206
207bool charset_conv::update_begin(const char* fromCharset,
208 const char* toCharset)
209{
210#ifdef HAVE_H_ICONV
211 if (EQ2(fromCharset, toCharset)) {
212 return true;
213 }
214
215 if (fromCharset == NULL || toCharset == NULL) {
216 if (m_iconv != (iconv_t) -1) {
217 return true;
218 }
219
220 logger_error("input invalid, from: %s, to: %s, m_conv: %s",
221 fromCharset ? fromCharset : "null",
222 toCharset ? toCharset : "null",
223 m_iconv == (iconv_t) -1 ? "invalid" : "valud");
224 m_errmsg = "input invalid";
225 return false;
226 }
227
228 // ���Դ�� UTF-8 ���룬�� m_pTuf8Pre �� UTF8_HEADER ͷ����
229 // һ���ֽڿ�ʼ����ƥ�䣬��������һ���ֽ� '\0' ��ʼƥ�䣬
230 // ������ UTF-8 ͷ��ƥ�����
231 if (EQ(fromCharset, "utf-8") || EQ(fromCharset, "utf8")) {
232 m_pUtf8Pre = UTF8_HEADER;
233 } else {
234 m_pUtf8Pre = &UTF8_HEADER[3];
235 }
236
237 if ((iconv_t) m_iconv != (iconv_t) -1
238 && EQ(m_fromCharset, fromCharset)
239 && EQ(m_toCharset, toCharset)) {
240
241 return true;
242 }
243
244 SCOPY(m_fromCharset, fromCharset, sizeof(m_fromCharset));
245 SCOPY(m_toCharset, toCharset, sizeof(m_toCharset));
246
247 if (m_iconv != (iconv_t) -1) {
248 __iconv_close((iconv_t) m_iconv);
249 }
250 m_iconv = (iconv_t) __iconv_open(toCharset, fromCharset);
251 if (m_iconv == (iconv_t) -1) {
252 logger_error("iconv_open(%s, %s) error(%s)",
253 toCharset, fromCharset, last_serror());
254 m_errmsg.format("iconv_open(%s, %s) error(%s)",
255 toCharset, fromCharset, last_serror());
256 return false;
257 } else {
258#ifdef ACL_WINDOWS
259# ifndef USE_WIN_ICONV
260 int n = 1;
261 __iconvctl(m_iconv, ICONV_TRIVIALP, &n);
262
263 n = 1;
264 __iconvctl(m_iconv, ICONV_SET_DISCARD_ILSEQ, &n);

Callers 1

createMethod · 0.45

Calls 2

last_serrorFunction · 0.70
formatMethod · 0.45

Tested by

no test coverage detected