Add:Tools:Added multiple index entries for special chars
[navit-package] / navit / linguistics.c
1 #include <string.h>
2 #include <stdio.h>
3 #include <glib.h>
4 #include "debug.h"
5 #include "linguistics.h"
6
7 static const char *special[][3]={
8 {"Ä","A","AE"},
9 {"Ö","O","OE"},
10 {"Ü","U","UE"},
11 {"Ő","O"},
12 {"Ű","U"},
13 {"Á","A"},
14 {"É","E"},
15 {"Í","I"},
16 {"Ó","O"},
17 {"Ú","U"},
18 {"ä","a","ae"},
19 {"ö","o","oe"},
20 {"ü","u","ue"},
21 {"ő","o"},
22 {"ű","u"},
23 {"á","a"},
24 {"é","e"},
25 {"í","i"},
26 {"ó","o"},
27 {"ú","u"},
28 {"ß","s","ss"},
29 };
30
31 char *
32 linguistics_expand_special(char *str, int mode)
33 {
34         char *in=str;
35         char *out,*ret;
36         int found=0;
37         out=ret=g_strdup(str);
38         if (!mode) 
39                 return ret;
40         while (*in) {
41                 char *next=g_utf8_find_next_char(in, NULL);
42                 int i,len=next-in;
43                 int match=0;
44                 if (len > 1) {
45                         for (i = 0 ; i < sizeof(special)/sizeof(special[0]); i++) {
46                                 const char *search=special[i][0];
47                                 if (!strncmp(in,search,len)) {
48                                         const char *replace=special[i][mode];
49                                         if (replace) {
50                                                 int replace_len=strlen(replace);
51                                                 dbg_assert(replace_len <= len);
52                                                 dbg(1,"found %s %s %s\n",in,search,replace);
53                                                 strcpy(out, replace);
54                                                 out+=replace_len;
55                                                 match=1;
56                                                 break;
57                                         }
58                                 }
59                         }
60                         in=next;
61                 }
62                 if (match) 
63                         found=1;
64                 else {  
65                         while (len-- > 0) 
66                                 *out++=*in++;
67                 }
68         }
69         *out++='\0';
70         if (!found) {
71                 g_free(ret);
72                 ret=NULL;
73         }
74         return ret;
75 }