22 size_t inbytesleft,
size_t *no_read)
24 if (!inp || inp[0] != 0xef)
34 if (inp[1] != 0xbb && inp[2] == 0xbf)
42 size_t inbytesleft,
size_t *no_read,
52 else if (inp[0] <= 0x7f)
57 else if (inp[0] < 0xc2 || inp[0] > 0xf4)
61 else if (inp[0] <= 0xdf && inbytesleft >= 2)
63 if ((inp[1] & 0xc0) == 0x80)
65 x = ((inp[0] & 0x1f) << 6) | (inp[1] & 0x3f);
71 else if (inp[0] <= 0xef && inbytesleft >= 3)
73 if ((inp[1] & 0xc0) == 0x80 && (inp[2] & 0xc0) == 0x80)
75 x = ((inp[0] & 0x0f) << 12) | ((inp[1] & 0x3f) << 6) |
77 if (x >= 0x800 && (x < 0xd800 || x > 0xdfff))
85 else if (inp[0] <= 0xf4 && inbytesleft >= 4)
87 if ((inp[1] & 0xc0) == 0x80 && (inp[2] & 0xc0) == 0x80
88 && (inp[3] & 0xc0) == 0x80)
90 x = ((inp[0] & 0x07) << 18) | ((inp[1] & 0x3f) << 12) |
91 ((inp[2] & 0x3f) << 6) | (inp[3] & 0x3f);
92 if (x >= 0x10000 && x <= 0x10ffff)
108 size_t inbytesleft,
size_t *no_read)
119 char **outbuf,
size_t *outbytesleft)
128 char **outbuf,
size_t *outbytesleft,
131 unsigned char *outp = (
unsigned char *) *outbuf;
133 if ((x >= 0xd800 && x <= 0xdfff) || x > 0x10ffff)
138 if (x <= 0x7f && *outbytesleft >= 1)
140 *outp++ = (
unsigned char) x;
143 else if (x <= 0x7ff && *outbytesleft >= 2)
145 *outp++ = (
unsigned char) ((x >> 6) | 0xc0);
146 *outp++ = (
unsigned char) ((x & 0x3f) | 0x80);
147 (*outbytesleft) -= 2;
149 else if (x <= 0xffff && *outbytesleft >= 3)
151 *outp++ = (
unsigned char) ((x >> 12) | 0xe0);
152 *outp++ = (
unsigned char) (((x >> 6) & 0x3f) | 0x80);
153 *outp++ = (
unsigned char) ((x & 0x3f) | 0x80);
154 (*outbytesleft) -= 3;
156 else if (x <= 0x10ffff && *outbytesleft >= 4)
158 *outp++ = (
unsigned char) ((x >> 18) | 0xf0);
159 *outp++ = (
unsigned char) (((x >> 12) & 0x3f) | 0x80);
160 *outp++ = (
unsigned char) (((x >> 6) & 0x3f) | 0x80);
161 *outp++ = (
unsigned char) ((x & 0x3f) | 0x80);
162 (*outbytesleft) -= 4;
169 *outbuf = (
char *) outp;
200 unsigned char *inp = (
unsigned char *) str;
201 size_t inbytesleft = strlen(str);
211 inbytesleft -= no_read;
Header for errno utilities.
Internal header for iconv.
struct yaz_iconv_decoder_s * yaz_iconv_decoder_t
struct yaz_iconv_encoder_s * yaz_iconv_encoder_t
yaz_iconv_encoder_t yaz_utf8_encoder(const char *name, yaz_iconv_encoder_t e)
yaz_iconv_decoder_t yaz_utf8_decoder(const char *fromcode, yaz_iconv_decoder_t d)
void yaz_iconv_set_errno(yaz_iconv_t cd, int no)
int yaz_matchstr(const char *s1, const char *s2)
match strings - independent of case and '-'
unsigned long(*) read_handle(yaz_iconv_t cd, yaz_iconv_decoder_t d, unsigned char *inbuf, size_t inbytesleft, size_t *no_read)
size_t(*) init_handle(yaz_iconv_t cd, yaz_iconv_decoder_t d, unsigned char *inbuf, size_t inbytesleft, size_t *no_read)
size_t(*) write_handle(yaz_iconv_t cd, yaz_iconv_encoder_t e, unsigned long x, char **outbuf, size_t *outbytesleft)
static size_t write_UTF8(yaz_iconv_t cd, yaz_iconv_encoder_t en, unsigned long x, char **outbuf, size_t *outbytesleft)
static unsigned long read_utf8(yaz_iconv_t cd, yaz_iconv_decoder_t d, unsigned char *inp, size_t inbytesleft, size_t *no_read)
size_t yaz_write_UTF8_char(unsigned long x, char **outbuf, size_t *outbytesleft, int *error)
encodes UTF-8 sequence
int yaz_utf8_check(const char *str)
check whether string apppers to be UTF-8 encoded
static size_t init_utf8(yaz_iconv_t cd, yaz_iconv_decoder_t d, unsigned char *inp, size_t inbytesleft, size_t *no_read)
unsigned long yaz_read_UTF8_char(const unsigned char *inp, size_t inbytesleft, size_t *no_read, int *error)
#define YAZ_ICONV_EILSEQ
error code: Invalid sequence
#define YAZ_ICONV_E2BIG
error code: Not sufficient room for output buffer
#define YAZ_ICONV_EINVAL
error code: An incomplete multibyte sequence is in input buffer
struct yaz_iconv_struct * yaz_iconv_t
yaz_iconv handle (similar to iconv_t)