e2a6f3b61ff2acc75c0c019eb333d799fa179738
[gedcom-parse.git] / utf8 / utf8.h
1 /* Header file for UTF-8 functions
2    Copyright (C) 2001, 2002 Peter Verthez
3
4    Permission granted to do anything with this file that you want, as long
5    as the above copyright is retained in all copies.
6    THERE IS NO WARRANTY - USE AT YOUR OWN RISK
7 */
8
9 /* $Id$ */
10 /* $Name$ */
11
12 #ifndef __UTF8_H
13 #define __UTF8_H
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 #include "iconv.h"
20
21 struct conv_buffer {
22   char*   buffer;
23   size_t  size;
24   int     type;  /* For internal use */
25 };
26
27 struct convert {
28   iconv_t from_utf8;
29   iconv_t to_utf8;
30   struct conv_buffer* inbuf;
31   size_t  insize;
32   struct conv_buffer* outbuf;
33   char*   unknown;
34 };
35
36 typedef struct convert *convert_t;
37
38   /* Returns -1 if the string is not a valid UTF-8 string, returns its
39      string length otherwise */
40 int   utf8_strlen(const char* input);
41
42   /* Returns 1 if string is valid UTF-8 string, 0 otherwise */
43 int   is_utf8_string(const char* input);
44
45   /* Functions for creating and freeing conversion buffers yourself */
46 struct conv_buffer* create_conv_buffer(int size);
47 void free_conv_buffer(struct conv_buffer* buf);
48   
49   /* General conversion interface (is bidirectional) */
50   /* Pass 0 for external_outbuf unless you want to control the
51      output buffer yourself */
52 convert_t initialize_utf8_conversion(const char* charset, int external_outbuf);
53 int   conversion_set_unknown(convert_t conv, const char* unknown);
54 int   conversion_set_output_buffer(convert_t conv, struct conv_buffer* buf);
55 void  cleanup_utf8_conversion(convert_t conv);
56 char* convert_from_utf8(convert_t conv, const char* input, int* conv_fails);
57 char* convert_to_utf8(convert_t conv, const char* input);
58 char* convert_to_utf8_incremental(convert_t conv,
59                                   const char* input, size_t input_len);
60
61   /* Specific locale conversion interface (initializes a convert_t structure
62      implicitly */
63 void  convert_set_unknown(const char* unknown);
64 char* convert_utf8_to_locale(const char* input, int *conv_fails);
65 char* convert_locale_to_utf8(const char* input);
66
67 #ifdef __cplusplus
68 }
69 #endif
70
71 #endif /* __UTF8_H */