From: Peter Verthez Date: Sun, 1 Dec 2002 09:11:40 +0000 (+0000) Subject: Some changes in interface. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=dbe61389396a4fb8ee50f6a5bd5fe4219ed43290;p=gedcom-parse.git Some changes in interface. --- diff --git a/utf8/utf8-locale.c b/utf8/utf8-locale.c index 115c66e..9ede577 100644 --- a/utf8/utf8-locale.c +++ b/utf8/utf8-locale.c @@ -16,11 +16,6 @@ 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); @@ -29,7 +24,7 @@ void close_conversion_contexts() 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); @@ -40,6 +35,13 @@ int open_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) diff --git a/utf8/utf8.h b/utf8/utf8.h index 425b7a4..e2a6f3b 100644 --- a/utf8/utf8.h +++ b/utf8/utf8.h @@ -21,11 +21,14 @@ extern "C" { 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; }; @@ -39,14 +42,24 @@ int utf8_strlen(const char* input); /* 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);