1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 Index Data
3 * See the file LICENSE for details.
7 * \brief UCS4 decoding and encoding
21 static unsigned long read_UCS4(yaz_iconv_t cd, yaz_iconv_decoder_t d,
23 size_t inbytesleft, size_t *no_read)
29 yaz_iconv_set_errno(cd, YAZ_ICONV_EINVAL); /* incomplete input */
34 x = (inp[0]<<24) | (inp[1]<<16) | (inp[2]<<8) | inp[3];
40 static unsigned long read_UCS4LE(yaz_iconv_t cd, yaz_iconv_decoder_t d,
42 size_t inbytesleft, size_t *no_read)
48 yaz_iconv_set_errno(cd, YAZ_ICONV_EINVAL); /* incomplete input */
53 x = (inp[3]<<24) | (inp[2]<<16) | (inp[1]<<8) | inp[0];
59 static size_t write_UCS4(yaz_iconv_t cd, yaz_iconv_encoder_t en,
61 char **outbuf, size_t *outbytesleft)
63 unsigned char *outp = (unsigned char *) *outbuf;
64 if (*outbytesleft >= 4)
66 *outp++ = (unsigned char) (x>>24);
67 *outp++ = (unsigned char) (x>>16);
68 *outp++ = (unsigned char) (x>>8);
69 *outp++ = (unsigned char) x;
74 yaz_iconv_set_errno(cd, YAZ_ICONV_E2BIG);
77 *outbuf = (char *) outp;
81 static size_t write_UCS4LE(yaz_iconv_t cd, yaz_iconv_encoder_t en,
83 char **outbuf, size_t *outbytesleft)
85 unsigned char *outp = (unsigned char *) *outbuf;
86 if (*outbytesleft >= 4)
88 *outp++ = (unsigned char) x;
89 *outp++ = (unsigned char) (x>>8);
90 *outp++ = (unsigned char) (x>>16);
91 *outp++ = (unsigned char) (x>>24);
96 yaz_iconv_set_errno(cd, YAZ_ICONV_E2BIG);
99 *outbuf = (char *) outp;
104 yaz_iconv_encoder_t yaz_ucs4_encoder(const char *tocode,
105 yaz_iconv_encoder_t e)
108 if (!yaz_matchstr(tocode, "UCS4"))
109 e->write_handle = write_UCS4;
110 else if (!yaz_matchstr(tocode, "UCS4LE"))
111 e->write_handle = write_UCS4LE;
117 yaz_iconv_decoder_t yaz_ucs4_decoder(const char *tocode,
118 yaz_iconv_decoder_t d)
121 if (!yaz_matchstr(tocode, "UCS4"))
122 d->read_handle = read_UCS4;
123 else if (!yaz_matchstr(tocode, "UCS4LE"))
124 d->read_handle = read_UCS4LE;
135 * c-file-style: "Stroustrup"
136 * indent-tabs-mode: nil
138 * vim: shiftwidth=4 tabstop=8 expandtab