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
20 static unsigned long read_UCS4(yaz_iconv_t cd, yaz_iconv_decoder_t d,
22 size_t inbytesleft, size_t *no_read)
28 yaz_iconv_set_errno(cd, YAZ_ICONV_EINVAL); /* incomplete input */
33 x = (inp[0]<<24) | (inp[1]<<16) | (inp[2]<<8) | inp[3];
39 static unsigned long read_UCS4LE(yaz_iconv_t cd, yaz_iconv_decoder_t d,
41 size_t inbytesleft, size_t *no_read)
47 yaz_iconv_set_errno(cd, YAZ_ICONV_EINVAL); /* incomplete input */
52 x = (inp[3]<<24) | (inp[2]<<16) | (inp[1]<<8) | inp[0];
58 static size_t write_UCS4(yaz_iconv_t cd, yaz_iconv_encoder_t en,
60 char **outbuf, size_t *outbytesleft)
62 unsigned char *outp = (unsigned char *) *outbuf;
63 if (*outbytesleft >= 4)
65 *outp++ = (unsigned char) (x>>24);
66 *outp++ = (unsigned char) (x>>16);
67 *outp++ = (unsigned char) (x>>8);
68 *outp++ = (unsigned char) x;
73 yaz_iconv_set_errno(cd, YAZ_ICONV_E2BIG);
76 *outbuf = (char *) outp;
80 static size_t write_UCS4LE(yaz_iconv_t cd, yaz_iconv_encoder_t en,
82 char **outbuf, size_t *outbytesleft)
84 unsigned char *outp = (unsigned char *) *outbuf;
85 if (*outbytesleft >= 4)
87 *outp++ = (unsigned char) x;
88 *outp++ = (unsigned char) (x>>8);
89 *outp++ = (unsigned char) (x>>16);
90 *outp++ = (unsigned char) (x>>24);
95 yaz_iconv_set_errno(cd, YAZ_ICONV_E2BIG);
98 *outbuf = (char *) outp;
103 yaz_iconv_encoder_t yaz_ucs4_encoder(const char *tocode,
104 yaz_iconv_encoder_t e)
107 if (!yaz_matchstr(tocode, "UCS4"))
108 e->write_handle = write_UCS4;
109 else if (!yaz_matchstr(tocode, "UCS4LE"))
110 e->write_handle = write_UCS4LE;
116 yaz_iconv_decoder_t yaz_ucs4_decoder(const char *tocode,
117 yaz_iconv_decoder_t d)
120 if (!yaz_matchstr(tocode, "UCS4"))
121 d->read_handle = read_UCS4;
122 else if (!yaz_matchstr(tocode, "UCS4LE"))
123 d->read_handle = read_UCS4LE;
134 * c-file-style: "Stroustrup"
135 * indent-tabs-mode: nil
137 * vim: shiftwidth=4 tabstop=8 expandtab