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,
53 else if (inp[0] <= 0xbf || inp[0] >= 0xfe)
57 else if (inp[0] <= 0xdf && inbytesleft >= 2)
59 if ((inp[1] & 0xc0) == 0x80)
61 x = ((inp[0] & 0x1f) << 6) | (inp[1] & 0x3f);
70 else if (inp[0] <= 0xef && inbytesleft >= 3)
72 if ((inp[1] & 0xc0) == 0x80 && (inp[2] & 0xc0) == 0x80)
74 x = ((inp[0] & 0x0f) << 12) | ((inp[1] & 0x3f) << 6) |
84 else if (inp[0] <= 0xf7 && inbytesleft >= 4)
86 if ((inp[1] & 0xc0) == 0x80 && (inp[2] & 0xc0) == 0x80
87 && (inp[3] & 0xc0) == 0x80)
89 x = ((inp[0] & 0x07) << 18) | ((inp[1] & 0x3f) << 12) |
90 ((inp[2] & 0x3f) << 6) | (inp[3] & 0x3f);
99 else if (inp[0] <= 0xfb && inbytesleft >= 5)
101 if ((inp[1] & 0xc0) == 0x80 && (inp[2] & 0xc0) == 0x80
102 && (inp[3] & 0xc0) == 0x80 && (inp[4] & 0xc0) == 0x80)
104 x = ((inp[0] & 0x03) << 24) | ((inp[1] & 0x3f) << 18) |
105 ((inp[2] & 0x3f) << 12) | ((inp[3] & 0x3f) << 6) |
115 else if (inp[0] <= 0xfd && inbytesleft >= 6)
117 if ((inp[1] & 0xc0) == 0x80 && (inp[2] & 0xc0) == 0x80
118 && (inp[3] & 0xc0) == 0x80 && (inp[4] & 0xc0) == 0x80
119 && (inp[5] & 0xc0) == 0x80)
121 x = ((inp[0] & 0x01) << 30) | ((inp[1] & 0x3f) << 24) |
122 ((inp[2] & 0x3f) << 18) | ((inp[3] & 0x3f) << 12) |
123 ((inp[4] & 0x3f) << 6) | (inp[5] & 0x3f);
140 size_t inbytesleft,
size_t *no_read)
151 char **outbuf,
size_t *outbytesleft)
160 char **outbuf,
size_t *outbytesleft,
163 unsigned char *outp = (
unsigned char *) *outbuf;
165 if (x <= 0x7f && *outbytesleft >= 1)
167 *outp++ = (
unsigned char) x;
170 else if (x <= 0x7ff && *outbytesleft >= 2)
172 *outp++ = (
unsigned char) ((x >> 6) | 0xc0);
173 *outp++ = (
unsigned char) ((x & 0x3f) | 0x80);
174 (*outbytesleft) -= 2;
176 else if (x <= 0xffff && *outbytesleft >= 3)
178 *outp++ = (
unsigned char) ((x >> 12) | 0xe0);
179 *outp++ = (
unsigned char) (((x >> 6) & 0x3f) | 0x80);
180 *outp++ = (
unsigned char) ((x & 0x3f) | 0x80);
181 (*outbytesleft) -= 3;
183 else if (x <= 0x1fffff && *outbytesleft >= 4)
185 *outp++ = (
unsigned char) ((x >> 18) | 0xf0);
186 *outp++ = (
unsigned char) (((x >> 12) & 0x3f) | 0x80);
187 *outp++ = (
unsigned char) (((x >> 6) & 0x3f) | 0x80);
188 *outp++ = (
unsigned char) ((x & 0x3f) | 0x80);
189 (*outbytesleft) -= 4;
191 else if (x <= 0x3ffffff && *outbytesleft >= 5)
193 *outp++ = (
unsigned char) ((x >> 24) | 0xf8);
194 *outp++ = (
unsigned char) (((x >> 18) & 0x3f) | 0x80);
195 *outp++ = (
unsigned char) (((x >> 12) & 0x3f) | 0x80);
196 *outp++ = (
unsigned char) (((x >> 6) & 0x3f) | 0x80);
197 *outp++ = (
unsigned char) ((x & 0x3f) | 0x80);
198 (*outbytesleft) -= 5;
200 else if (*outbytesleft >= 6)
202 *outp++ = (
unsigned char) ((x >> 30) | 0xfc);
203 *outp++ = (
unsigned char) (((x >> 24) & 0x3f) | 0x80);
204 *outp++ = (
unsigned char) (((x >> 18) & 0x3f) | 0x80);
205 *outp++ = (
unsigned char) (((x >> 12) & 0x3f) | 0x80);
206 *outp++ = (
unsigned char) (((x >> 6) & 0x3f) | 0x80);
207 *outp++ = (
unsigned char) ((x & 0x3f) | 0x80);
208 (*outbytesleft) -= 6;
215 *outbuf = (
char *) outp;
246 unsigned char *inp = (
unsigned char *) str;
247 size_t inbytesleft = strlen(str);
257 inbytesleft -= no_read;
Header for errno utilities.
Internal header for iconv.
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
yaz_iconv_encoder_t yaz_utf8_encoder(const char *tocode, yaz_iconv_encoder_t e)
int yaz_utf8_check(const char *str)
check whether string apppers to be UTF-8 encoded
yaz_iconv_decoder_t yaz_utf8_decoder(const char *fromcode, yaz_iconv_decoder_t d)
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