1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
$NetBSD: patch-ba,v 1.2 2002/12/30 19:19:18 jmcneill Exp $
--- charconv.c.orig Thu May 16 20:06:50 2002
+++ charconv.c Mon Dec 30 15:13:23 2002
@@ -69,6 +69,8 @@
{
static char *this_charset = NULL;
static int local_is_utf8 = 0;
+ unicode_iconv_t t1 = (unicode_iconv_t)(-1);
+ unicode_iconv_t t2 = (unicode_iconv_t)(-1);
if (this_charset) {
*charset = this_charset;
@@ -98,7 +100,8 @@
if ((*charset == NULL) ||
(0==strcmp(*charset,"US-ASCII")) ||
- (0==strcmp(*charset,"ANSI_X3.4-1968"))) {
+ (0==strcmp(*charset,"ANSI_X3.4-1968")) ||
+ (**charset == '\0')) {
/* we got basic stupid ASCII here. We use its sane
superset instead. Especially since libxml2 doesn't like
the pedantic name of ASCII. */
@@ -108,8 +111,25 @@
}
this_charset = *charset;
- local_is_utf8 = (*charset) && (0==strcmp(*charset,"UTF-8"));
-
+ if (*charset) {
+ if (strcmp(*charset, "UTF-8") != 0) {
+ if ((t1 = unicode_iconv_open(*charset, "UTF-8")) == (unicode_iconv_t)(-1)
+ || (t2 = unicode_iconv_open("UTF-8", *charset)) ==
+ (unicode_iconv_t)(-1)) {
+ g_warning("unicode_iconv_open() does not understand your charset %s\n",
+ "Using UTF-8 as local. Set LC_CTYPE or CHARSET.",
+ *charset);
+ local_is_utf8 = 1;
+ *charset = "UTF-8";
+ }
+ } else
+ local_is_utf8 = 1;
+ }
+ if (t1 != (unicode_iconv_t)(-1))
+ unicode_iconv_close(t1);
+ if (t2 != (unicode_iconv_t)(-1))
+ unicode_iconv_close(t2);
+
return local_is_utf8;
}
|