draw: use only one iconv for all

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-07-09 08:48:51 +02:00
parent 58eac8af1c
commit 9c495c0dee
1 changed files with 12 additions and 11 deletions

View File

@ -56,6 +56,8 @@ void draw_parser_data_wipe(draw_parser_data_t *pdata)
draw_image_delete(&pdata->bg_image); draw_image_delete(&pdata->bg_image);
} }
static iconv_t iso2utf8 = (iconv_t) -1;
/** Convert text from any charset to UTF-8 using iconv. /** Convert text from any charset to UTF-8 using iconv.
* \param iso The ISO string to convert. * \param iso The ISO string to convert.
* \param len The string size. * \param len The string size.
@ -64,7 +66,6 @@ void draw_parser_data_wipe(draw_parser_data_t *pdata)
char * char *
draw_iso2utf8(const char *iso, size_t len) draw_iso2utf8(const char *iso, size_t len)
{ {
iconv_t iso2utf8;
size_t utf8len; size_t utf8len;
char *utf8, *utf8p; char *utf8, *utf8p;
@ -74,6 +75,8 @@ draw_iso2utf8(const char *iso, size_t len)
if(!a_strcmp(nl_langinfo(CODESET), "UTF-8")) if(!a_strcmp(nl_langinfo(CODESET), "UTF-8"))
return NULL; return NULL;
if(iso2utf8 == (iconv_t) -1)
{
iso2utf8 = iconv_open("UTF-8", nl_langinfo(CODESET)); iso2utf8 = iconv_open("UTF-8", nl_langinfo(CODESET));
if(iso2utf8 == (iconv_t) -1) if(iso2utf8 == (iconv_t) -1)
{ {
@ -85,6 +88,7 @@ draw_iso2utf8(const char *iso, size_t len)
return NULL; return NULL;
} }
}
utf8len = 2 * len + 1; utf8len = 2 * len + 1;
utf8 = utf8p = p_new(char, utf8len); utf8 = utf8p = p_new(char, utf8len);
@ -95,9 +99,6 @@ draw_iso2utf8(const char *iso, size_t len)
p_delete(&utf8p); p_delete(&utf8p);
} }
if(iconv_close(iso2utf8))
warn("error closing iconv");
return utf8p; return utf8p;
} }