1 /* Encoding utility from UTF-8 to locale and vice versa
2 Copyright (C) 2001, 2002 Peter Verthez
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.
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.
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
23 #include "utf8tools.h"
27 #include "libcharset.h"
29 static convert_t locale_conv = NULL;
31 static void close_conversion_contexts()
33 cleanup_utf8_conversion(locale_conv);
36 static int open_conversion_contexts()
38 assert (locale_conv == NULL);
39 locale_conv = initialize_utf8_conversion(locale_charset(), 0);
42 atexit(close_conversion_contexts);
50 void convert_set_unknown(const char* unknown)
53 open_conversion_contexts();
54 conversion_set_unknown(locale_conv, unknown);
57 char* convert_utf8_to_locale(const char* input, int *conv_fails)
60 open_conversion_contexts();
62 return convert_from_utf8(locale_conv, input, conv_fails, NULL);
65 char* convert_locale_to_utf8(const char* input)
68 open_conversion_contexts();
70 return convert_to_utf8(locale_conv, input, strlen(input));