iconv_string.h
Upload User: yingmei828
Upload Date: 2007-01-01
Package Size: 1646k
Code Size: 2k
Development Platform:

Unix_Linux

  1. /*
  2.  * This C function converts an entire string from one encoding to another,
  3.  * using iconv. Easier to use than iconv() itself, and supports autodetect
  4.  * encodings on input.
  5.  *
  6.  *   int iconv_string (const char* tocode, const char* fromcode,
  7.  *                     const char* start, const char* end,
  8.  *                     char** resultp, size_t* lengthp)
  9.  *
  10.  * Converts a memory region given in encoding FROMCODE to a new memory
  11.  * region in encoding TOCODE. FROMCODE and TOCODE are as for iconv_open(3),
  12.  * except that FROMCODE may be one of the values
  13.  *    "autodetect_utf8"          supports ISO-8859-1 and UTF-8
  14.  *    "autodetect_jp"            supports EUC-JP, ISO-2022-JP-2 and SHIFT_JIS
  15.  *    "autodetect_kr"            supports EUC-KR and ISO-2022-KR
  16.  * The input is in the memory region between start (inclusive) and end
  17.  * (exclusive). If resultp is not NULL, the output string is stored in
  18.  * *resultp; malloc/realloc is used to allocate the result.
  19.  *
  20.  * This function does not treat zero characters specially.
  21.  *
  22.  * Return value: 0 if successful, otherwise -1 and errno set. Particular
  23.  * errno values: EILSEQ and ENOMEM.
  24.  *
  25.  * Example:
  26.  *   const char* s = ...;
  27.  *   char* result = NULL;
  28.  *   if (iconv_string("UCS-4-INTERNAL", "autodetect_utf8",
  29.  *                    s, s+strlen(s)+1, &result, NULL) < 0)
  30.  *     perror("iconv_string");
  31.  *
  32.  */
  33. #include <stddef.h>
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. extern int iconv_string (const char* tocode, const char* fromcode, const char* start, const char* end, char** resultp, size_t* lengthp);
  38. #ifdef __cplusplus
  39. }
  40. #endif