fix iconv open caching
This commit is contained in:
parent
cdaeba390d
commit
40a6bb8f56
@ -43,8 +43,9 @@ using std::string;
|
|||||||
bool transcode(const string &in, string &out, const string &icode,
|
bool transcode(const string &in, string &out, const string &icode,
|
||||||
const string &ocode, int *ecnt)
|
const string &ocode, int *ecnt)
|
||||||
{
|
{
|
||||||
|
LOGDEB(("Transcode: %s -> %s\n", icode.c_str(), ocode.c_str()));
|
||||||
#ifdef ICONV_CACHE_OPEN
|
#ifdef ICONV_CACHE_OPEN
|
||||||
static iconv_t ic;
|
static iconv_t ic = (iconv_t)-1;
|
||||||
static string cachedicode;
|
static string cachedicode;
|
||||||
static string cachedocode;
|
static string cachedocode;
|
||||||
#else
|
#else
|
||||||
@ -66,18 +67,20 @@ bool transcode(const string &in, string &out, const string &icode,
|
|||||||
if((ic = iconv_open(ocode.c_str(), icode.c_str())) == (iconv_t)-1) {
|
if((ic = iconv_open(ocode.c_str(), icode.c_str())) == (iconv_t)-1) {
|
||||||
out = string("iconv_open failed for ") + icode
|
out = string("iconv_open failed for ") + icode
|
||||||
+ " -> " + ocode;
|
+ " -> " + ocode;
|
||||||
|
#ifdef ICONV_CACHE_OPEN
|
||||||
|
cachedicode.erase();
|
||||||
|
cachedocode.erase();
|
||||||
|
#endif
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
#ifdef ICONV_CACHE_OPEN
|
#ifdef ICONV_CACHE_OPEN
|
||||||
cachedicode.assign(icode);
|
cachedicode.assign(icode);
|
||||||
cachedocode.assign(ocode);
|
cachedocode.assign(ocode);
|
||||||
} else {
|
|
||||||
iconv(ic, 0, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
icopen = true;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
icopen = true;
|
||||||
|
|
||||||
while (isiz > 0) {
|
while (isiz > 0) {
|
||||||
size_t osiz;
|
size_t osiz;
|
||||||
op = obuf;
|
op = obuf;
|
||||||
@ -107,20 +110,25 @@ bool transcode(const string &in, string &out, const string &icode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef ICONV_CACHE_OPEN
|
#ifndef ICONV_CACHE_OPEN
|
||||||
|
icopen = false;
|
||||||
if(iconv_close(ic) == -1) {
|
if(iconv_close(ic) == -1) {
|
||||||
out.erase();
|
out.erase();
|
||||||
out = string("iconv_close failed for ") + icode
|
out = string("iconv_close failed for ") + icode
|
||||||
+ " -> " + ocode;
|
+ " -> " + ocode;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
icopen = false;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
#ifndef ICONV_CACHE_OPEN
|
|
||||||
if (icopen)
|
if (icopen)
|
||||||
|
#ifndef ICONV_CACHE_OPEN
|
||||||
iconv_close(ic);
|
iconv_close(ic);
|
||||||
|
#else
|
||||||
|
iconv(ic, 0, 0, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mecnt)
|
if (mecnt)
|
||||||
LOGDEB(("transcode: [%s]->[%s] %d errors\n",
|
LOGDEB(("transcode: [%s]->[%s] %d errors\n",
|
||||||
icode.c_str(), ocode.c_str(), mecnt));
|
icode.c_str(), ocode.c_str(), mecnt));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user