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 If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
34 array is filled with offsets into the result, i.e. the character starting
35 at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
36 and other offsets are set to (size_t)(-1).
37 *RESULTP and *LENGTH should initially be a scratch buffer and its size,
38 or *RESULTP can initially be NULL.
39 May erase the contents of the memory at *RESULTP.
40 Return value: 0 if successful, otherwise -1 and errno set.
41 If successful: The resulting string is stored in *RESULTP and its length
42 in *LENGTHP. *RESULTP is set to a freshly allocated memory block, or is
43 unchanged if no dynamic memory allocation was necessary. */
45 mem_iconveha (const char *src, size_t srclen,
46 const char *from_codeset, const char *to_codeset,
47 enum iconv_ilseq_handler handler,
49 char **resultp, size_t *lengthp);
51 /* Convert an entire string from one encoding to another, using iconv.
52 The original string is the NUL-terminated string starting at SRC.
53 Both the "from" and the "to" encoding must use a single NUL byte at the
54 end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
55 The "from" encoding can also be a name defined for autodetection.
56 Allocate a malloced memory block for the result.
57 Return value: the freshly allocated resulting NUL-terminated string if
58 successful, otherwise NULL and errno set. */
60 str_iconveha (const char *src,
61 const char *from_codeset, const char *to_codeset,
62 enum iconv_ilseq_handler handler);
65 /* In the above, FROM_CODESET can also be one of the following values:
66 "autodetect_utf8" supports ISO-8859-1 and UTF-8
67 "autodetect_jp" supports EUC-JP, ISO-2022-JP-2 and SHIFT_JIS
68 "autodetect_kr" supports EUC-KR and ISO-2022-KR
69 More names can be defined for autodetection. */
71 /* Registers an encoding name for autodetection.
72 TRY_IN_ORDER is a NULL terminated list of encodings to be tried.
73 Returns 0 upon success, or -1 (with errno set) in case of error.
74 Particular errno values: ENOMEM. */
76 iconv_register_autodetect (const char *name,
77 const char * const *try_in_order);
85 #endif /* _STRICONVEHA_H */