3cfb1c13be35ba51a41679bdabc86b78c878eae4
[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 <sys/types.h>
20
21 struct conv_buffer;
22 struct convert;
23 typedef struct conv_buffer *conv_buffer_t;
24 typedef struct convert *convert_t;
25
26   /* Returns -1 if the string is not a valid UTF-8 string, returns its
27      string length otherwise */
28 int   utf8_strlen(const char* input);
29
30   /* Returns 1 if string is valid UTF-8 string, 0 otherwise */
31 int   is_utf8_string(const char* input);
32
33   /* Functions for creating and freeing conversion buffers yourself */
34 conv_buffer_t create_conv_buffer(int size);
35 void free_conv_buffer(conv_buffer_t buf);
36   
37   /* General conversion interface (is bidirectional) */
38   /* Pass 0 for external_outbuf unless you want to control the
39      output buffer yourself */
40 convert_t initialize_utf8_conversion(const char* charset, int external_outbuf);
41 int   conversion_set_unknown(convert_t conv, const char* unknown);
42 int   conversion_set_output_buffer(convert_t conv, conv_buffer_t buf);
43 void  cleanup_utf8_conversion(convert_t conv);
44 char* convert_from_utf8(convert_t conv, const char* input, int* conv_fails,
45                         size_t* output_len);
46 char* convert_to_utf8(convert_t conv, const char* input, size_t input_len);
47 char* convert_to_utf8_incremental(convert_t conv,
48                                   const char* input, size_t input_len);
49
50   /* Specific locale conversion interface (initializes a convert_t structure
51      implicitly */
52 void  convert_set_unknown(const char* unknown);
53 char* convert_utf8_to_locale(const char* input, int *conv_fails);
54 char* convert_locale_to_utf8(const char* input);
55
56 #ifdef __cplusplus
57 }
58 #endif
59
60 #endif /* __UTF8_H */