view src/lib-charset/charset-utf8.h @ 765:553f050c8313 HEAD

Added buffer API. Point is to hide all buffer writing behind this API which verifies that nothing overflows. Much better than doing the same checks all around the code, even if it is slightly slower. Buffer reading is still mostly done directly, that isn't such a big security risk and I can't think of a reasonable API for it anyway.
author Timo Sirainen <tss@iki.fi>
date Sun, 08 Dec 2002 07:23:07 +0200
parents debb8468514e
children 03832c7f389b
line wrap: on
line source

#ifndef __CHARSET_UTF8_H
#define __CHARSET_UTF8_H

typedef enum {
	CHARSET_RET_OK = 1,
	CHARSET_RET_OUTPUT_FULL = 0,
	CHARSET_RET_INCOMPLETE_INPUT = -1,
	CHARSET_RET_INVALID_INPUT = -2
} CharsetResult;

typedef struct _CharsetTranslation CharsetTranslation;

/* Begin translation to UTF-8. */
CharsetTranslation *charset_to_utf8_begin(const char *charset,
					  int *unknown_charset);

void charset_to_utf8_end(CharsetTranslation *t);

void charset_to_utf8_reset(CharsetTranslation *t);

/* Translate src to UTF-8. If src_pos is non-NULL, it's updated to first
   non-translated character in src. */
CharsetResult
charset_to_ucase_utf8(CharsetTranslation *t,
		      const Buffer *src, size_t *src_pos, Buffer *dest);

/* Simple wrapper for above functions. If utf8_size is non-NULL, it's set
   to same as strlen(returned data). */
const char *
charset_to_ucase_utf8_string(const char *charset, int *unknown_charset,
			     const Buffer *data, size_t *utf8_size);

#endif