Finishing up for release.
[gedcom-parse.git] / utf8 / utf8tools.h
1 /* Header file for UTF-8 functions
2    Copyright (C) 2001, 2002 Peter Verthez
3
4    The UTF8 tools library is free software; you can redistribute it
5    and/or modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The Gedcom parser library is distributed in the hope that it will be
10    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the Gedcom parser library; if not, write to the
16    Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.
18 */
19
20 /* $Id$ */
21 /* $Name$ */
22
23 #ifndef __UTF8TOOLS_H
24 #define __UTF8TOOLS_H
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include <sys/types.h>
31
32 struct conv_buffer;
33 struct convert;
34 typedef struct conv_buffer *conv_buffer_t;
35 typedef struct convert *convert_t;
36
37   /* Returns -1 if the string is not a valid UTF-8 string, returns its
38      string length otherwise */
39 int   utf8_strlen(const char* input);
40
41   /* Returns 1 if string is valid UTF-8 string, 0 otherwise */
42 int   is_utf8_string(const char* input);
43
44   /* Functions for creating and freeing conversion buffers yourself */
45 conv_buffer_t create_conv_buffer(int size);
46 void free_conv_buffer(conv_buffer_t buf);
47   
48   /* General conversion interface (is bidirectional) */
49   /* Pass 0 for external_outbuf unless you want to control the
50      output buffer yourself */
51 convert_t initialize_utf8_conversion(const char* charset, int external_outbuf);
52 int   conversion_set_unknown(convert_t conv, const char* unknown);
53 int   conversion_set_output_buffer(convert_t conv, conv_buffer_t buf);
54 void  cleanup_utf8_conversion(convert_t conv);
55 char* convert_from_utf8(convert_t conv, const char* input, int* conv_fails,
56                         size_t* output_len);
57 char* convert_to_utf8(convert_t conv, const char* input, size_t input_len);
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 /* __UTF8TOOLS_H */