summaryrefslogtreecommitdiff
path: root/navit/search.c
diff options
context:
space:
mode:
authorJoseph Herlant <aerostitch@users.noreply.github.com>2019-10-27 10:04:00 -0700
committerGitHub <noreply@github.com>2019-10-27 10:04:00 -0700
commita0ea905c28b2e9df4984a263bdef213203c36d80 (patch)
treec45a5935a5055e040818ed9a531e86d150bc189c /navit/search.c
parent7021575af7578fc54c46c61e13835941183b652f (diff)
downloadnavit-a0ea905c28b2e9df4984a263bdef213203c36d80.tar.gz
cleanup:search:Remove duplicate code for search_fix_spaces (#917)
* cleanup:search:Remove duplicate code for search_fix_spaces * Remove the static modifier to allow its usage in multiple files * Avoid discards const qualifier from pointer target type warning * Fix the bad redirect and force const in signature * Add doc for search_fix_spaces * Update description * Handle case when the string will only contain chars that will be discarded
Diffstat (limited to 'navit/search.c')
-rw-r--r--navit/search.c14
1 files changed, 12 insertions, 2 deletions
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;
}