summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Wildemann <metalstrolch@users.noreply.github.com>2019-10-28 11:12:54 +0100
committerGitHub <noreply@github.com>2019-10-28 11:12:54 +0100
commit396efc75fe22ca48c0a603c287b7147c5592f782 (patch)
tree1e5de4eaac72c6042c07c35e9d1a3b0bbd6d733a
parentadbc2f0bcb783363ae4ff7c7ebe62b9b2a9b0995 (diff)
parenta0ea905c28b2e9df4984a263bdef213203c36d80 (diff)
downloadnavit-tile_cutter.tar.gz
Merge branch 'trunk' into tile_cuttertile_cutter
-rw-r--r--navit/android.c29
-rw-r--r--navit/search.c14
-rw-r--r--navit/search.h1
3 files changed, 13 insertions, 31 deletions
diff --git a/navit/android.c b/navit/android.c
index def3a6f22..4b73b3f5e 100644
--- a/navit/android.c
+++ b/navit/android.c
@@ -681,35 +681,6 @@ static void android_search_idle(struct android_search_priv *search_priv) {
dbg(lvl_info, "leave");
}
-static char *search_fix_spaces(const char *str) {
- int i;
- int len=strlen(str);
- char c,*s,*d,*ret=g_strdup(str);
-
- for (i = 0 ; i < len ; i++) {
- if (ret[i] == ',' || ret[i] == '/')
- ret[i]=' ';
- }
- s=ret;
- d=ret;
- len=0;
- do {
- c=*s++;
- if (c != ' ' || len != 0) {
- *d++=c;
- len++;
- }
- while (c == ' ' && *s == ' ')
- s++;
- if (c == ' ' && *s == '\0') {
- d--;
- len--;
- }
- } while (c);
-
- return ret;
-}
-
static void start_search(struct android_search_priv *search_priv, const char *search_string) {
dbg(lvl_debug,"enter %s", search_string);
char *str=search_fix_spaces(search_string);
diff --git a/navit/search.c b/navit/search.c
index 06afcbfe6..e700f4355 100644
--- a/navit/search.c
+++ b/navit/search.c
@@ -135,13 +135,20 @@ int search_list_level(enum attr_type attr_type) {
}
}
-static char *search_fix_spaces(char *str) {
+/**
+ * @brief Replaces ',' and '/' by ' ', deduplicates spaces within the string
+ * and strips spaces from both ends of the string
+ *
+ * @param pointer to the string to cleanup
+ * @return pointer to the cleaned up string
+ */
+char *search_fix_spaces(const char *str) {
int i;
int len=strlen(str);
char c,*s,*d,*ret=g_strdup(str);
for (i = 0 ; i < len ; i++) {
- if (ret[i] == ',' || ret[i] == ',' || ret[i] == '/')
+ if (ret[i] == ',' || ret[i] == '/')
ret[i]=' ';
}
s=ret;
@@ -160,6 +167,9 @@ static char *search_fix_spaces(char *str) {
len--;
}
} while (c);
+ // Make sure the string is terminated at current position even if nothing has been added to it.
+ // This case happen when you use a string containing only chars that will be discarded.
+ *d='\0';
return ret;
}
diff --git a/navit/search.h b/navit/search.h
index 50756606f..cdf93410e 100644
--- a/navit/search.h
+++ b/navit/search.h
@@ -87,6 +87,7 @@ char *search_list_get_unique(struct search_list *this_, char *unique);
struct search_list_result *search_list_get_result(struct search_list *this_);
void search_list_destroy(struct search_list *this_);
void search_init(void);
+char *search_fix_spaces(const char *str);
/* end of prototypes */
#ifdef __cplusplus
}