Debian Codegraph @

src/xh_encoder.h

raw
1 #ifndef _XH_ENCODER_H_
2 #define _XH_ENCODER_H_
3
4 #include "xh_config.h"
5 #include "xh_core.h"
6
7 #ifdef XH_HAVE_ENCODER
8
9 #ifdef XH_HAVE_ICONV
10 #if defined(__MINGW32__) || defined(_WIN32)
11 #define LIBICONV_STATIC
12 #endif
13 #include <iconv.h>
14 /* POSIX declares the input buffer of iconv() as "char **", but Solaris and
15 * illumos declare it as "const char **". A direct cast to either type is
16 * rejected by the other platform, so the cast goes through void *, which
17 * implicitly converts to whichever pointer type is expected.
18 *
19 * Do not replace this with a platform test such as #ifdef __sun: which
20 * prototype applies depends on the header that is actually included, not on
21 * the operating system. GNU libiconv, which uses "char **", is commonly
22 * installed on Solaris and illumos alongside the iconv in libc. */
23 #define XH_ICONV_INBUF_CAST (void *)
24 #endif
25 #ifdef XH_HAVE_ICU
26 #include <unicode/utypes.h>
27 #include <unicode/ucnv.h>
28 #endif
29
30 typedef enum {
31 XH_ENC_ICONV,
32 XH_ENC_ICU
33 } xh_encoder_type_t;
34
35 typedef enum {
36 XH_ENC_OK = 0,
37 XH_ENC_BUFFER_OVERFLOW,
38 XH_ENC_TRUNCATED_CHAR_FOUND
39 } xh_encoder_state_t;
40
41 typedef struct _xh_encoder_t xh_encoder_t;
42 struct _xh_encoder_t {
43 xh_encoder_type_t type;
44 xh_encoder_state_t state;
45 xh_char_t fromcode[XH_PARAM_LEN];
46 xh_char_t tocode[XH_PARAM_LEN];
47 #ifdef XH_HAVE_ICONV
48 iconv_t iconv;
49 #endif
50 #ifdef XH_HAVE_ICU
51 UConverter *uconv_from;
52 UConverter *uconv_to;
53 UChar pivotBuffer[1024];
54 const UChar *pivotLimit;
55 UChar *pivotSource, *pivotTarget, *pivotStart;
56 #endif
57 };
58
59 void xh_encoder_destroy(xh_encoder_t *encoder);
60 xh_encoder_t *xh_encoder_create(xh_char_t *tocode, xh_char_t *fromcode);
61 void xh_encoder_encode_perl_buffer(xh_encoder_t *encoder, xh_perl_buffer_t *main_buf, xh_perl_buffer_t *enc_buf);
62 void xh_encoder_encode_string(xh_encoder_t *encoder, xh_char_t **src, size_t *src_left, xh_char_t **dst, size_t *dst_left);
63
64 #endif /* XH_HAVE_ENCODER */
65
66 #endif /* _XH_ENCODER_H_ */