1 /* Character set conversion with error handling and autodetection.
2 Copyright (C) 2002, 2005, 2007 Free Software Foundation, Inc.
3 Written by Bruno Haible.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 #ifndef _STRICONVEHA_H
20 #define _STRICONVEHA_H
22 #include "striconveh.h"
30 /* Convert an entire string from one encoding to another, using iconv.
31 The original string is at [SRC,...,SRC+SRCLEN-1].
32 The "from" encoding can also be a name defined for autodetection.
33 *RESULTP and *LENGTH should initially be a scratch buffer and its size,
34 or *RESULTP can initially be NULL.
35 May erase the contents of the memory at *RESULTP.
36 Return value: 0 if successful, otherwise -1 and errno set.
37 If successful: The resulting string is stored in *RESULTP and its length
38 in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is
39 unchanged if no dynamic memory allocation was necessary. */
41 mem_iconveha (const char *src, size_t srclen,
42 const char *from_codeset, const char *to_codeset,
43 enum iconv_ilseq_handler handler,
44 char **resultp, size_t *lengthp);
46 /* Convert an entire string from one encoding to another, using iconv.
47 The original string is the NUL-terminated string starting at SRC.
48 Both the "from" and the "to" encoding must use a single NUL byte at the
49 end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
50 The "from" encoding can also be a name defined for autodetection.
51 Allocate a malloced memory block for the result.
52 Return value: the freshly allocated resulting NUL-terminated string if
53 successful, otherwise NULL and errno set. */
55 str_iconveha (const char *src,
56 const char *from_codeset, const char *to_codeset,
57 enum iconv_ilseq_handler handler);
60 /* In the above, FROM_CODESET can also be one of the following values:
61 "autodetect_utf8" supports ISO-8859-1 and UTF-8
62 "autodetect_jp" supports EUC-JP, ISO-2022-JP-2 and SHIFT_JIS
63 "autodetect_kr" supports EUC-KR and ISO-2022-KR
64 More names can be defined for autodetection. */
66 /* Registers an encoding name for autodetection.
67 TRY_IN_ORDER is a NULL terminated list of encodings to be tried.
68 Returns 0 upon success, or -1 (with errno set) in case of error.
69 Particular errno values: ENOMEM. */
71 iconv_register_autodetect (const char *name,
72 const char * const *try_in_order);
80 #endif /* _STRICONVEHA_H */