convert.h File Reference

#include "platform.h"
#include "extractor.h"

Go to the source code of this file.

Functions

char * EXTRACTOR_common_convert_to_utf8 (const char *input, size_t len, const char *charset)


Function Documentation

char* EXTRACTOR_common_convert_to_utf8 ( const char *  input,
size_t  len,
const char *  charset 
)

Convert the len characters long character sequence given in input that is in the given charset to UTF-8.

Returns:
the converted string (0-terminated), if conversion fails, a copy of the orignal string is returned.

Definition at line 34 of file convert.c.

References free, and malloc.

Referenced by charsetDecode(), get_id3(), history_extract(), libextractor_filename_extract(), libextractor_html_extract(), libextractor_id3v23_extract(), libextractor_id3v24_extract(), libextractor_id3v2_extract(), processtEXt(), and processzTXt().

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 }


Generated on Fri Jan 9 16:44:53 2009 for libextractor by  doxygen 1.5.1