diff options
author | mdankov <mdankov@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2013-05-03 21:36:00 +0000 |
---|---|---|
committer | mdankov <mdankov@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2013-05-03 21:36:00 +0000 |
commit | 72e92d407ba1b5b4ef418cee7526e39b471403d0 (patch) | |
tree | 580ea5efbebdd2af088bce48b2774b616749a758 /navit/map | |
parent | a2fc50574d1c5c850570a636a89d11a66dc3367d (diff) | |
download | navit-72e92d407ba1b5b4ef418cee7526e39b471403d0.tar.gz |
Add:map_binfile:Switch to use new linguistics_compare function.
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@5471 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/map')
-rw-r--r-- | navit/map/binfile/binfile.c | 58 |
1 files changed, 10 insertions, 48 deletions
diff --git a/navit/map/binfile/binfile.c b/navit/map/binfile/binfile.c index 2abecbc73..a42c9ecfd 100644 --- a/navit/map/binfile/binfile.c +++ b/navit/map/binfile/binfile.c @@ -1719,13 +1719,13 @@ map_parse_country_binfile(struct map_rect_priv *mr) if(search->type==attr_town_name || search->type==attr_district_name || search->type==attr_town_or_district_name) { struct attr af, al; if(binfile_attr_get(mr->item.priv_data, attr_first_key, &af)) { - if(case_cmp(af.u.str,search->u.str,1)>0) { + if(linguistics_compare(af.u.str,search->u.str,linguistics_cmp_partial)>0) { dbg(1,"Skipping index item with first_key='%s'\n", af.u.str); return; } } if(binfile_attr_get(mr->item.priv_data, attr_last_key, &al)) { - if(case_cmp(al.u.str,search->u.str,1)<0) { + if(linguistics_compare(al.u.str,search->u.str,linguistics_cmp_partial)<0) { dbg(1,"Skipping index item with first_key='%s', last_key='%s'\n", af.u.str, al.u.str); return; } @@ -2114,25 +2114,6 @@ binmap_search_new(struct map_priv *map, struct item *item, struct attr *search, return NULL; } -/** - * @brief Compare two strings ignoring their case. - * @param name Item name string to compare - * @param match User query string. Should be linguistics_casefold()ed by by the caller - * @return result of comparison, zero if strings are equal - */ - -static int -case_cmp(char *name, char *match, int partial) -{ - int matchlen=strlen(match); - int ret; - char *folded=linguistics_casefold(name); - if (partial && strlen(folded)>matchlen) - folded[matchlen]=0; - ret=strcmp(folded, match); - g_free(folded); - return ret; -} struct duplicate { @@ -2262,6 +2243,7 @@ binmap_search_get_item(struct map_search_priv *map_search) { struct item* it; struct attr at; + enum linguistics_cmp_mode mode=(map_search->partial?linguistics_cmp_partial:0); for (;;) { while ((it = map_rect_get_item_binfile(map_search->mr))) { @@ -2272,13 +2254,13 @@ binmap_search_get_item(struct map_search_priv *map_search) case attr_town_or_district_name: if (map_search->mr->tile_depth > 1 && item_is_town(*it) && map_search->search.type != attr_district_name) { if (binfile_attr_get(it->priv_data, attr_town_name_match, &at) || binfile_attr_get(it->priv_data, attr_town_name, &at)) { - if (!case_cmp(at.u.str, map_search->search.u.str, map_search->partial) && !duplicate(map_search, it, attr_town_name)) + if (!linguistics_compare(at.u.str, map_search->search.u.str, mode) && !duplicate(map_search, it, attr_town_name)) return it; } } if (map_search->mr->tile_depth > 1 && item_is_district(*it) && map_search->search.type != attr_town_name) { if (binfile_attr_get(it->priv_data, attr_district_name_match, &at) || binfile_attr_get(it->priv_data, attr_district_name, &at)) { - if (!case_cmp(at.u.str, map_search->search.u.str, map_search->partial) && !duplicate(map_search, it, attr_town_name)) + if (!linguistics_compare(at.u.str, map_search->search.u.str, mode) && !duplicate(map_search, it, attr_town_name)) return it; } } @@ -2286,7 +2268,7 @@ binmap_search_get_item(struct map_search_priv *map_search) case attr_street_name: if (map_search->mode == 1) { if (binfile_attr_get(it->priv_data, attr_street_name_match, &at) || binfile_attr_get(it->priv_data, attr_street_name, &at)) { - if (!case_cmp(at.u.str, map_search->search.u.str, map_search->partial) && !duplicate(map_search, it, attr_street_name)) { + if (!linguistics_compare(at.u.str, map_search->search.u.str, mode) && !duplicate(map_search, it, attr_street_name)) { return it; } } @@ -2298,9 +2280,6 @@ binmap_search_get_item(struct map_search_priv *map_search) break; if(binfile_attr_get(it->priv_data, attr_label, &at)) { - int i,match=0; - char *str; - char *word; struct coord c[128]; struct duplicate *d; @@ -2310,27 +2289,10 @@ binmap_search_get_item(struct map_search_priv *map_search) d=duplicate_test(map_search, it, attr_label); if(!d) break; - - str=g_strdup(at.u.str); - word=str; - do { - for (i = 0 ; i < 3 ; i++) { - char *name=linguistics_expand_special(word,i); - if (name && !case_cmp(name, map_search->search.u.str, map_search->partial)) - match=1; - g_free(name); - if (match) - break; - } - if (match) - break; - word=linguistics_next_word(word); - } while (word); - g_free(str); - - if(!match) { + + if(linguistics_compare(at.u.str, map_search->search.u.str, mode|linguistics_cmp_expand|linguistics_cmp_words)) { /* Remember this non-matching street name in duplicate hash to skip name - * comparison for its following segments */ + * comparison for its following segments */ duplicate_insert(map_search, d); break; } @@ -2355,7 +2317,7 @@ binmap_search_get_item(struct map_search_priv *map_search) { if (has_house_number) { - if (!case_cmp(at.u.str, map_search->search.u.str, map_search->partial)) + if (!linguistics_compare(at.u.str, map_search->search.u.str, mode)) { if (!duplicate(map_search, it, attr_house_number)) { |