From ba32a34c92e7b36fe7e923e2af8d7e0f93e3fb56 Mon Sep 17 00:00:00 2001 From: martin-s Date: Tue, 23 Jun 2009 19:10:31 +0000 Subject: Add:Core:New module linguistics to cope with language specialities git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@2359 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/Makefile.am | 4 +-- navit/linguistics.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ navit/linguistics.h | 1 + 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 navit/linguistics.c create mode 100644 navit/linguistics.h diff --git a/navit/Makefile.am b/navit/Makefile.am index 7e87c9635..2212de4fd 100644 --- a/navit/Makefile.am +++ b/navit/Makefile.am @@ -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 index 000000000..0fb11c081 --- /dev/null +++ b/navit/linguistics.c @@ -0,0 +1,74 @@ +#include +#include +#include +#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 index 000000000..abd23d379 --- /dev/null +++ b/navit/linguistics.h @@ -0,0 +1 @@ +char *linguistics_expand_special(char *str, int mode); -- cgit v1.2.1