static convert_t locale_conv = NULL;
-void convert_set_unknown(const char* unknown)
-{
- conversion_set_unknown(locale_conv, unknown);
-}
-
void close_conversion_contexts()
{
cleanup_utf8_conversion(locale_conv);
int open_conversion_contexts()
{
assert (locale_conv == NULL);
- locale_conv = initialize_utf8_conversion(locale_charset());
+ locale_conv = initialize_utf8_conversion(locale_charset(), 0);
if (locale_conv) {
atexit(close_conversion_contexts);
}
}
+void convert_set_unknown(const char* unknown)
+{
+ if (!locale_conv)
+ open_conversion_contexts();
+ conversion_set_unknown(locale_conv, unknown);
+}
+
char* convert_utf8_to_locale(const char* input, int *conv_fails)
{
if (!locale_conv)
struct conv_buffer {
char* buffer;
size_t size;
+ int type; /* For internal use */
};
struct convert {
iconv_t from_utf8;
iconv_t to_utf8;
+ struct conv_buffer* inbuf;
+ size_t insize;
struct conv_buffer* outbuf;
char* unknown;
};
/* Returns 1 if string is valid UTF-8 string, 0 otherwise */
int is_utf8_string(const char* input);
+ /* Functions for creating and freeing conversion buffers yourself */
+struct conv_buffer* create_conv_buffer(int size);
+void free_conv_buffer(struct conv_buffer* buf);
+
/* General conversion interface (is bidirectional) */
-convert_t initialize_utf8_conversion(const char* charset);
+ /* Pass 0 for external_outbuf unless you want to control the
+ output buffer yourself */
+convert_t initialize_utf8_conversion(const char* charset, int external_outbuf);
int conversion_set_unknown(convert_t conv, const char* unknown);
+int conversion_set_output_buffer(convert_t conv, struct conv_buffer* buf);
void cleanup_utf8_conversion(convert_t conv);
char* convert_from_utf8(convert_t conv, const char* input, int* conv_fails);
char* convert_to_utf8(convert_t conv, const char* input);
+char* convert_to_utf8_incremental(convert_t conv,
+ const char* input, size_t input_len);
- /* Specific locale conversion interface */
+ /* Specific locale conversion interface (initializes a convert_t structure
+ implicitly */
void convert_set_unknown(const char* unknown);
char* convert_utf8_to_locale(const char* input, int *conv_fails);
char* convert_locale_to_utf8(const char* input);