iconv_string.h 1.7 KB

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