summaryrefslogtreecommitdiff
path: root/lib/striconveh.h
diff options
context:
space:
mode:
authorAndreas Rottmann <a.rottmann@gmx.at>2010-05-27 18:23:15 +0200
committerAndreas Rottmann <a.rottmann@gmx.at>2010-05-27 18:23:15 +0200
commit3e0814cd9862b89c7a39672672937477bd87ddfb (patch)
tree159134a624e51509f40ed8823249f09a70d1dda3 /lib/striconveh.h
parent3bebb94360f1c2333feb8d504a9fa4f96984d8b7 (diff)
Imported Upstream version 0.9.3upstream/0.9.3
Diffstat (limited to 'lib/striconveh.h')
-rw-r--r--lib/striconveh.h70
1 files changed, 45 insertions, 25 deletions
diff --git a/lib/striconveh.h b/lib/striconveh.h
index 98b4d0c5..dc92ceac 100644
--- a/lib/striconveh.h
+++ b/lib/striconveh.h
@@ -1,5 +1,5 @@
/* Character set conversion with error handling.
- Copyright (C) 2001-2007, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2001-2007, 2009-2010 Free Software Foundation, Inc.
Written by Bruno Haible and Simon Josefsson.
This program is free software: you can redistribute it and/or modify
@@ -33,14 +33,38 @@ extern "C" {
#if HAVE_ICONV
+/* An conversion descriptor for use by the iconveh functions. */
+typedef struct
+ {
+ /* Conversion descriptor from FROM_CODESET to TO_CODESET, or (iconv_t)(-1)
+ if the system does not support a direct conversion from FROM_CODESET to
+ TO_CODESET. */
+ iconv_t cd;
+ /* Conversion descriptor from FROM_CODESET to UTF-8 (or (iconv_t)(-1) if
+ FROM_CODESET is UTF-8). */
+ iconv_t cd1;
+ /* Conversion descriptor from UTF-8 to TO_CODESET (or (iconv_t)(-1) if
+ TO_CODESET is UTF-8). */
+ iconv_t cd2;
+ }
+ iconveh_t;
+
+/* Open a conversion descriptor for use by the iconveh functions.
+ If successful, fills *CDP and returns 0. Upon failure, return -1 with errno
+ set. */
+extern int
+ iconveh_open (const char *to_codeset, const char *from_codeset,
+ iconveh_t *cdp);
+
+/* Close a conversion descriptor created by iconveh_open().
+ Return value: 0 if successful, otherwise -1 and errno set. */
+extern int
+ iconveh_close (const iconveh_t *cd);
+
/* Convert an entire string from one encoding to another, using iconv.
The original string is at [SRC,...,SRC+SRCLEN-1].
- CD is the conversion descriptor from FROMCODE to TOCODE, or (iconv_t)(-1) if
- the system does not support a direct conversion from FROMCODE to TOCODE.
- CD1 is the conversion descriptor from FROM_CODESET to UTF-8 (or
- (iconv_t)(-1) if FROM_CODESET is UTF-8).
- CD2 is the conversion descriptor from UTF-8 to TO_CODESET (or (iconv_t)(-1)
- if TO_CODESET is UTF-8).
+ CD points to the conversion descriptor from FROMCODE to TOCODE, created by
+ the function iconveh_open().
If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this
array is filled with offsets into the result, i.e. the character starting
at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]],
@@ -54,28 +78,24 @@ extern "C" {
unchanged if no dynamic memory allocation was necessary. */
extern int
mem_cd_iconveh (const char *src, size_t srclen,
- iconv_t cd, iconv_t cd1, iconv_t cd2,
- enum iconv_ilseq_handler handler,
- size_t *offsets,
- char **resultp, size_t *lengthp);
+ const iconveh_t *cd,
+ enum iconv_ilseq_handler handler,
+ size_t *offsets,
+ char **resultp, size_t *lengthp);
/* Convert an entire string from one encoding to another, using iconv.
The original string is the NUL-terminated string starting at SRC.
- CD is the conversion descriptor from FROMCODE to TOCODE, or (iconv_t)(-1) if
- the system does not support a direct conversion from FROMCODE to TOCODE.
+ CD points to the conversion descriptor from FROMCODE to TOCODE, created by
+ the function iconveh_open().
Both the "from" and the "to" encoding must use a single NUL byte at the end
of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32).
- CD1 is the conversion descriptor from FROM_CODESET to UTF-8 (or
- (iconv_t)(-1) if FROM_CODESET is UTF-8).
- CD2 is the conversion descriptor from UTF-8 to TO_CODESET (or (iconv_t)(-1)
- if TO_CODESET is UTF-8).
Allocate a malloced memory block for the result.
Return value: the freshly allocated resulting NUL-terminated string if
successful, otherwise NULL and errno set. */
extern char *
str_cd_iconveh (const char *src,
- iconv_t cd, iconv_t cd1, iconv_t cd2,
- enum iconv_ilseq_handler handler);
+ const iconveh_t *cd,
+ enum iconv_ilseq_handler handler);
#endif
@@ -94,10 +114,10 @@ extern char *
unchanged if no dynamic memory allocation was necessary. */
extern int
mem_iconveh (const char *src, size_t srclen,
- const char *from_codeset, const char *to_codeset,
- enum iconv_ilseq_handler handler,
- size_t *offsets,
- char **resultp, size_t *lengthp);
+ const char *from_codeset, const char *to_codeset,
+ enum iconv_ilseq_handler handler,
+ size_t *offsets,
+ char **resultp, size_t *lengthp);
/* Convert an entire string from one encoding to another, using iconv.
The original string is the NUL-terminated string starting at SRC.
@@ -108,8 +128,8 @@ extern int
successful, otherwise NULL and errno set. */
extern char *
str_iconveh (const char *src,
- const char *from_codeset, const char *to_codeset,
- enum iconv_ilseq_handler handler);
+ const char *from_codeset, const char *to_codeset,
+ enum iconv_ilseq_handler handler);
#ifdef __cplusplus