2 * Copyright (c) 2009-2010 Mika Laitio <lamikr@pilppa.org>
4 * This file and library is covered by the LGPL version 3, read LICENSE for details.
7 * - Created charencoding.c on: Nov 25, 2009
18 #include "internal/charencoding_internal.h"
19 #include "internal/utf8.h"
21 #define LOCALE_CHARSET_UTF8 "UTF-8"
23 static bool _locale_charset_utf8_check_initialized = false;
24 static bool _locale_is_utf8 = false;
28 const char *locale_charset;
30 if (_locale_charset_utf8_check_initialized == false) {
31 locale_charset = get_locale_charset_alias();
32 if (strcmp(locale_charset, LOCALE_CHARSET_UTF8) == 0) {
33 _locale_is_utf8 = true;
36 _locale_is_utf8 = false;
38 _locale_charset_utf8_check_initialized = true;
40 return _locale_is_utf8;
43 char *str_encode(const char *src,
44 const char *src_charset,
45 const char *trgt_charset,
48 iconv_t conversion_desc;
57 cmp_res = strcasecmp(src_charset,
61 ret_val = strdup(src);
62 if (ret_val == NULL) {
67 conversion_desc = iconv_open(trgt_charset,
69 if (conversion_desc != (iconv_t)-1) {
70 src_length = strlen(src);
72 ret_val = str_iconv_encode(conversion_desc,
78 *err_flg = iconv_close(conversion_desc);
81 if (ret_val != NULL) {
95 char *utf8_encode(char *src,
103 if (is_utf8_locale() == true) {
104 ret_val = strdup(src);
107 charset = get_locale_charset_alias();
108 ret_val = str_encode(src,
117 int utf8_printf(char *fmt, ...)
124 ret_val = utf8_vprintf(fmt, args);