00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "platform.h"
00022 #include "extractor.h"
00023 #include "convert.h"
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 char *
00034 EXTRACTOR_common_convert_to_utf8 (const char *input, size_t len, const char *charset)
00035 {
00036 size_t tmpSize;
00037 size_t finSize;
00038 char *tmp;
00039 char *ret;
00040 char *itmp;
00041 const char *i;
00042 iconv_t cd;
00043
00044 i = input;
00045 cd = iconv_open ("UTF-8", charset);
00046 if (cd == (iconv_t) - 1)
00047 return strdup (i);
00048 tmpSize = 3 * len + 4;
00049 tmp = malloc (tmpSize);
00050 itmp = tmp;
00051 finSize = tmpSize;
00052 if (iconv (cd, (char **) &input, &len, &itmp, &finSize) == (size_t) - 1)
00053 {
00054 iconv_close (cd);
00055 free (tmp);
00056 return strdup (i);
00057 }
00058 ret = malloc (tmpSize - finSize + 1);
00059 memcpy (ret, tmp, tmpSize - finSize);
00060 ret[tmpSize - finSize] = '\0';
00061 free (tmp);
00062 iconv_close (cd);
00063 return ret;
00064 }
00065
00066