summarylogtreecommitdiffstats
path: root/compare-in-utf-8.diff
blob: 2b65b178460d9094318231518ead63dd9d579c7d (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
Correctly order the names in the index when they contain UTF-8
characters.  Use libunac for converting the accented characters in
UTF-8 into plain ASCII.

 -- Rafael Laboissiere <rafael@debian.org>  Sat, 21 Feb 2009 19:18:36 +0100

--- a/configure.ac
+++ b/configure.ac
@@ -22,6 +22,10 @@
 LIBS="$LIBS $(pkg-config glib-2.0 --libs)"
 CFLAGS="$CFLAGS $(pkg-config glib-2.0 --cflags)"
 
+# Libunac settings
+LIBS="$LIBS $(pkg-config unac --libs)"
+CFLAGS="$CFLAGS $(pkg-config unac --cflags)"
+
 # Checks for header files.
 AC_HEADER_STDC
 
--- a/src/entry.c
+++ b/src/entry.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <vc.h>
 #include <glib/gunicode.h>
+#include <unac.h>
 
 #define MENU_PRINT_FORMAT_SIZE 80
 
@@ -175,15 +176,43 @@
   entry_node **ena = NULL;
   entry_node **enb = NULL;
 
+  char* ena_desc = NULL;
+  char* enb_desc = NULL;
+  char* pure_a = NULL;
+  char* pure_b = NULL;
+  int length[1] = {0};
+  int a_alloc = 1;
+  int b_alloc = 1;
+
   ena = (entry_node **) a;
   enb = (entry_node **) b;
 
-  ret_val = cmp_given_n ((*ena)->description, (*enb)->description);
+  ena_desc = (*ena)->description;
+  enb_desc = (*enb)->description;
+
+  /* Try to convert the strings from UTF-8 and fall back to the original
+     strings if it fails */
+  if (unac_string ("UTF-8", ena_desc, strlen (ena_desc), &pure_a, length)) {
+    pure_a = ena_desc;
+    a_alloc = 0;
+  }
+
+  if (unac_string ("UTF-8", enb_desc, strlen (enb_desc), &pure_b, length)) {
+    pure_b = enb_desc;
+    b_alloc = 0;
+  }
+
+  ret_val = cmp_given_n (pure_a, pure_b);
   if (0 == ret_val)
     {
-      ret_val = strcmp ((*ena)->description, (*enb)->description);
+      ret_val = strcmp (pure_a, pure_b);
     }
 
+  if (a_alloc)
+    free (pure_a);
+  if (b_alloc)
+    free (pure_b);
+
   return ret_val;
 }
 
@@ -197,10 +226,38 @@
   entry_node **ena = NULL;
   entry_node **enb = NULL;
 
+  char* ena_desc = NULL;
+  char* enb_desc = NULL;
+  char* pure_a = NULL;
+  char* pure_b = NULL;
+  int length[1] = {0};
+  int a_alloc = 1;
+  int b_alloc = 1;
+
   ena = (entry_node **) a;
   enb = (entry_node **) b;
 
-  ret_val = strcmp ((*ena)->description, (*enb)->description);
+  ena_desc = (*ena)->description;
+  enb_desc = (*enb)->description;
+
+  /* Try to convert the strings from UTF-8 and fall back to the original
+     strings if it fails */
+  if (unac_string ("UTF-8", ena_desc, strlen (ena_desc), &pure_a, length)) {
+    pure_a = ena_desc;
+    a_alloc = 0;
+  }
+
+  if (unac_string ("UTF-8", enb_desc, strlen (enb_desc), &pure_b, length)) {
+    pure_b = enb_desc;
+    b_alloc = 0;
+  }
+
+  ret_val = strcmp (pure_a, pure_b);
+
+  if (a_alloc)
+    free (pure_a);
+  if (b_alloc)
+    free (pure_b);
 
   return ret_val;
 }