Beispiel #1
0
static apr_ssize_t
convert_from_ucs(struct iconv_ces *ces, ucs_t in,
	unsigned char **outbuf, apr_size_t *outbytesleft)
{
	ucs2_t *ptr = (ucs2_t *) *outbuf;
	if (in == UCS_CHAR_NONE)
		return 1;	/* No state reinitialization for table charsets */
	if (iconv_char32bit(in))
		return -1;	/* No corresponding character in UCS-2 */
	if (*outbytesleft < sizeof(ucs2_t))
		return 0;	/* No space in the output buffer */
	*ptr = (ucs2_t) in;
	*outbuf += sizeof(ucs2_t);
	(*outbytesleft) -= sizeof(ucs2_t);
	return 1;
}
static apr_ssize_t
convert_from_ucs(struct iconv_ces *ces, ucs_t in,
	unsigned char **outbuf, apr_size_t *outbytesleft)
{
	apr_size_t bytes;
	int *state = ces->data;

	if (in == UCS_CHAR_NONE)
    		return 1;	/* No state reinitialization for table charsets */
	if (iconv_char32bit(in))
		return -1;	/* No such character in UCS-2 */
	bytes = *state ? 2 : 4;
	if (*outbytesleft < bytes)
		return 0;	/* No space in the output buffer */
	if (*state) {
		*(*outbuf)++ = 0xFE;
		*(*outbuf)++ = 0xFF;
		*state = 1;
	}
	*(*outbuf)++ = (in >> 8) & 0xFF;
	*(*outbuf)++ = in & 0xFF;
	*outbytesleft -= bytes;
	return 1;
}