Add:Core:New module linguistics to cope with language specialities
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 23 Jun 2009 19:10:31 +0000 (19:10 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 23 Jun 2009 19:10:31 +0000 (19:10 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@2359 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/Makefile.am
navit/linguistics.c [new file with mode: 0644]
navit/linguistics.h [new file with mode: 0644]

index 7e87c96..2212de4 100644 (file)
@@ -24,11 +24,11 @@ EXTRA_DIST = navit.xml
 noinst_LTLIBRARIES        = libnavit.la
 libnavit_la_SOURCES = announcement.c atom.c attr.c cache.c callback.c command.c compass.c coord.c country.c cursor.c data_window.c debug.c \
        event.c event_glib.h file.c graphics.c gui.c item.c layout.c log.c main.c map.c \
-       mapset.c maptype.c menu.c messages.c navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \
+       linguistics.c mapset.c maptype.c menu.c messages.c navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \
        profile.c projection.c roadprofile.c route.c search.c speech.c transform.c track.c \
        util.c vehicle.c vehicleprofile.c xmlconfig.c announcement.h atom.h attr.h attr_def.h cache.h callback.h color.h command.h compass.h coord.h country.h \
        cursor.h data.h data_window.h data_window_int.h debug.h destination.h draw_info.h endianess.h event.h \
-       file.h graphics.h gtkext.h gui.h item.h item_def.h keys.h log.h layer.h layout.h main.h map-share.h map.h\
+       file.h graphics.h gtkext.h gui.h item.h item_def.h keys.h log.h layer.h layout.h linguistics.h main.h map-share.h map.h\
        map_data.h mapset.h maptype.h menu.h messages.h navigation.h navit.h osd.h \
        param.h phrase.h plugin.h point.h plugin_def.h projection.h popup.h route.h profile.h roadprofile.h search.h speech.h \
        transform.h track.h util.h vehicle.h vehicleprofile.h window.h xmlconfig.h zipfile.h \
diff --git a/navit/linguistics.c b/navit/linguistics.c
new file mode 100644 (file)
index 0000000..0fb11c0
--- /dev/null
@@ -0,0 +1,74 @@
+#include <string.h>
+#include <stdio.h>
+#include <glib.h>
+#include "debug.h"
+#include "linguistics.h"
+
+static const char *special[][3]={
+{"Ä","A","AE"},
+{"Ö","O","OE"},
+{"Ü","U","UE"},
+{"Ő","O"},
+{"Ű","U"},
+{"Á","A"},
+{"É","E"},
+{"Í","I"},
+{"Ó","O"},
+{"Ú","U"},
+{"ä","a","ae"},
+{"ö","o","oe"},
+{"ü","u","ue"},
+{"ő","o"},
+{"ű","u"},
+{"á","a"},
+{"é","e"},
+{"í","i"},
+{"ó","o"},
+{"ú","u"},
+{"ß","s","ss"},
+};
+
+char *
+linguistics_expand_special(char *str, int mode)
+{
+       char *in=str;
+       char *out,*ret;
+       int found=0;
+       out=ret=g_strdup(str);
+       mode++;
+       while (*in) {
+               char *next=g_utf8_find_next_char(in, NULL);
+               int i,len=next-in;
+               int match=0;
+               if (len > 1) {
+                       for (i = 0 ; i < sizeof(special)/sizeof(special[0]); i++) {
+                               const char *search=special[i][0];
+                               if (!strncmp(in,search,len)) {
+                                       const char *replace=special[i][mode];
+                                       if (replace) {
+                                               int replace_len=strlen(replace);
+                                               dbg_assert(replace_len <= len);
+                                               dbg(1,"found %s %s %s\n",in,search,replace);
+                                               strcpy(out, replace);
+                                               out+=replace_len;
+                                               match=1;
+                                               break;
+                                       }
+                               }
+                       }
+                       in=next;
+               }
+               if (match) 
+                       found=1;
+               else {  
+                       while (len-- > 0) 
+                               *out++=*in++;
+               }
+       }
+       *out++='\0';
+       if (!found) {
+               g_free(ret);
+               ret=NULL;
+       }
+       return ret;
+}
diff --git a/navit/linguistics.h b/navit/linguistics.h
new file mode 100644 (file)
index 0000000..abd23d3
--- /dev/null
@@ -0,0 +1 @@
+char *linguistics_expand_special(char *str, int mode);