20051
|
1 |
--- evolution-2.30.2/widgets/table/e-table-extras.c.orig 2010-09-13 10:32:58.597227009 +0800
|
|
2 |
+++ evolution-2.30.2/widgets/table/e-table-extras.c 2010-09-13 10:33:05.421403470 +0800
|
|
3 |
@@ -156,6 +156,129 @@
|
|
4 |
return FALSE;
|
|
5 |
}
|
|
6 |
|
|
7 |
+
|
|
8 |
+/**
|
|
9 |
+ * g_utf8_collate_key_1:
|
|
10 |
+ * @str: a UTF-8 encoded string.
|
|
11 |
+ * @len: length of @str, in bytes, or -1 if @str is nul-terminated.
|
|
12 |
+ *
|
|
13 |
+ * Converts a string into a collation key that can be compared
|
|
14 |
+ * with other collation keys produced by the same function using
|
|
15 |
+ * strcmp().
|
|
16 |
+ *
|
|
17 |
+ * The results of comparing the collation keys of two strings
|
|
18 |
+ * with strcmp() will always be the same as comparing the two
|
|
19 |
+ * original keys with g_utf8_collate().
|
|
20 |
+ *
|
|
21 |
+ * Note that this function depends on the
|
|
22 |
+ * <link linkend="setlocale">current locale</link>.
|
|
23 |
+ *
|
|
24 |
+ * Return value: a newly allocated string. This string should
|
|
25 |
+ * be freed with g_free() when you are done with it.
|
|
26 |
+ **/
|
|
27 |
+gchar *
|
|
28 |
+g_utf8_collate_key_1 (const gchar *str,
|
|
29 |
+ gssize len)
|
|
30 |
+{
|
|
31 |
+ gchar *result;
|
|
32 |
+
|
|
33 |
+#ifdef HAVE_CARBON
|
|
34 |
+
|
|
35 |
+ g_return_val_if_fail (str != NULL, NULL);
|
|
36 |
+ result = carbon_collate_key (str, len);
|
|
37 |
+
|
|
38 |
+#elif defined(__STDC_ISO_10646__)
|
|
39 |
+
|
|
40 |
+ gsize xfrm_len;
|
|
41 |
+ gunichar *str_norm;
|
|
42 |
+ wchar_t *result_wc;
|
|
43 |
+ gsize i;
|
|
44 |
+ gsize result_len = 0;
|
|
45 |
+
|
|
46 |
+ g_return_val_if_fail (str != NULL, NULL);
|
|
47 |
+
|
|
48 |
+ str_norm = _g_utf8_normalize_wc (str, len, G_NORMALIZE_ALL_COMPOSE);
|
|
49 |
+
|
|
50 |
+ xfrm_len = wcsxfrm (NULL, (wchar_t *)str_norm, 0);
|
|
51 |
+ result_wc = g_new (wchar_t, xfrm_len + 1);
|
|
52 |
+ wcsxfrm (result_wc, (wchar_t *)str_norm, xfrm_len + 1);
|
|
53 |
+
|
|
54 |
+ for (i=0; i < xfrm_len; i++)
|
|
55 |
+ result_len += utf8_encode (NULL, result_wc[i]);
|
|
56 |
+
|
|
57 |
+ result = g_malloc (result_len + 1);
|
|
58 |
+ result_len = 0;
|
|
59 |
+ for (i=0; i < xfrm_len; i++)
|
|
60 |
+ result_len += utf8_encode (result + result_len, result_wc[i]);
|
|
61 |
+
|
|
62 |
+ result[result_len] = '\0';
|
|
63 |
+
|
|
64 |
+ g_free (result_wc);
|
|
65 |
+ g_free (str_norm);
|
|
66 |
+
|
|
67 |
+ return result;
|
|
68 |
+#else /* !__STDC_ISO_10646__ */
|
|
69 |
+
|
|
70 |
+ gsize xfrm_len;
|
|
71 |
+ const gchar *charset;
|
|
72 |
+ gchar *str_norm;
|
|
73 |
+
|
|
74 |
+ g_return_val_if_fail (str != NULL, NULL);
|
|
75 |
+
|
|
76 |
+ str_norm = g_utf8_normalize (str, len, G_NORMALIZE_ALL_COMPOSE);
|
|
77 |
+
|
|
78 |
+ result = NULL;
|
|
79 |
+
|
|
80 |
+ if (g_get_charset (&charset))
|
|
81 |
+ {
|
|
82 |
+ if (str_norm)
|
|
83 |
+ xfrm_len = strxfrm (NULL, str_norm, 0);
|
|
84 |
+ else xfrm_len = 0;
|
|
85 |
+ if (xfrm_len >= 0 && xfrm_len < G_MAXINT - 2)
|
|
86 |
+ {
|
|
87 |
+ result = g_malloc (xfrm_len + 1);
|
|
88 |
+ if (str_norm)
|
|
89 |
+ strxfrm (result, str_norm, xfrm_len + 1);
|
|
90 |
+ }
|
|
91 |
+ }
|
|
92 |
+ else
|
|
93 |
+ {
|
|
94 |
+ gchar *str_locale = g_convert (str_norm, -1, charset, "UTF-8", NULL, NULL, NULL);
|
|
95 |
+
|
|
96 |
+ if (str_locale)
|
|
97 |
+ {
|
|
98 |
+ xfrm_len = strxfrm (NULL, str_locale, 0);
|
|
99 |
+ if (xfrm_len < 0 || xfrm_len >= G_MAXINT - 2)
|
|
100 |
+ {
|
|
101 |
+ g_free (str_locale);
|
|
102 |
+ str_locale = NULL;
|
|
103 |
+ }
|
|
104 |
+ }
|
|
105 |
+ if (str_locale)
|
|
106 |
+ {
|
|
107 |
+ result = g_malloc (xfrm_len + 2);
|
|
108 |
+ result[0] = 'A';
|
|
109 |
+ strxfrm (result + 1, str_locale, xfrm_len + 1);
|
|
110 |
+
|
|
111 |
+ g_free (str_locale);
|
|
112 |
+ }
|
|
113 |
+ }
|
|
114 |
+
|
|
115 |
+ if (!result)
|
|
116 |
+ {
|
|
117 |
+ xfrm_len = strlen (str_norm);
|
|
118 |
+ result = g_malloc (xfrm_len + 2);
|
|
119 |
+ result[0] = 'B';
|
|
120 |
+ memcpy (result + 1, str_norm, xfrm_len);
|
|
121 |
+ result[xfrm_len+1] = '\0';
|
|
122 |
+ }
|
|
123 |
+
|
|
124 |
+ g_free (str_norm);
|
|
125 |
+#endif /* __STDC_ISO_10646__ */
|
|
126 |
+
|
|
127 |
+ return result;
|
|
128 |
+}
|
|
129 |
+
|
|
130 |
static gint
|
|
131 |
e_table_str_case_compare (gconstpointer x, gconstpointer y, gpointer cmp_cache)
|
|
132 |
{
|
|
133 |
@@ -175,7 +298,7 @@
|
|
134 |
_cz = e_table_sorting_utils_lookup_cmp_cache (cmp_cache, _z); \
|
|
135 |
if (!_cz) { \
|
|
136 |
gchar *tmp = g_utf8_casefold (_z, -1); \
|
|
137 |
- _cz = g_utf8_collate_key (tmp, -1); \
|
|
138 |
+ _cz = g_utf8_collate_key_1 (tmp, -1); \
|
|
139 |
g_free (tmp); \
|
|
140 |
\
|
|
141 |
e_table_sorting_utils_add_to_cmp_cache ( \
|