From 2ee50d030178cede83eb9d0005fbc19f819d30fe Mon Sep 17 00:00:00 2001 From: Graham Inggs Date: Mon, 5 Feb 2018 14:48:51 +0200 Subject: Imported Upstream version 2.1.0 --- StringUtils.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'StringUtils.c') diff --git a/StringUtils.c b/StringUtils.c index b53f5ee..0578cde 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -17,10 +17,15 @@ in the source distribution for its full text. /*{ #include -#define String_startsWith(s, match) (strstr((s), (match)) == (s)) +#define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0) #define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL) }*/ +/* + * String_startsWith gives better performance if strlen(match) can be computed + * at compile time (e.g. when they are immutable string literals). :) + */ + char* String_cat(const char* s1, const char* s2) { int l1 = strlen(s1); int l2 = strlen(s2); @@ -88,6 +93,9 @@ char** String_split(const char* s, char sep, int* n) { } void String_freeArray(char** s) { + if (!s) { + return; + } for (int i = 0; s[i] != NULL; i++) { free(s[i]); } -- cgit v1.2.3