aboutsummaryrefslogtreecommitdiffstats
path: root/StringUtils.c
diff options
context:
space:
mode:
authorGraham Inggs <ginggs@debian.org>2018-02-05 14:48:51 +0200
committerGraham Inggs <ginggs@debian.org>2018-02-05 14:48:51 +0200
commit2ee50d030178cede83eb9d0005fbc19f819d30fe (patch)
tree67d75c0a7c47e15bed9d0735ecf12abec4f8157b /StringUtils.c
parent31b71b67011fa52f091df6fe536a11d6d0bfb256 (diff)
downloaddebian_htop-2ee50d030178cede83eb9d0005fbc19f819d30fe.tar.gz
debian_htop-2ee50d030178cede83eb9d0005fbc19f819d30fe.tar.bz2
debian_htop-2ee50d030178cede83eb9d0005fbc19f819d30fe.zip
Imported Upstream version 2.1.0upstream/2.1.0
Diffstat (limited to 'StringUtils.c')
-rw-r--r--StringUtils.c10
1 files changed, 9 insertions, 1 deletions
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 <stdio.h>
-#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]);
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy