diff options
-rw-r--r-- | include/stringop.h | 3 | ||||
-rw-r--r-- | sway/stringop.c | 13 |
2 files changed, 16 insertions, 0 deletions
diff --git a/include/stringop.h b/include/stringop.h index febbbaba..bb681bcd 100644 --- a/include/stringop.h +++ b/include/stringop.h | |||
@@ -14,6 +14,9 @@ char *strip_whitespace(char *str); | |||
14 | char *strip_comments(char *str); | 14 | char *strip_comments(char *str); |
15 | void strip_quotes(char *str); | 15 | void strip_quotes(char *str); |
16 | 16 | ||
17 | // strcmp that also handles null pointers. | ||
18 | int lenient_strcmp(char *a, char *b); | ||
19 | |||
17 | // Simply split a string with delims, free with `free_flat_list` | 20 | // Simply split a string with delims, free with `free_flat_list` |
18 | list_t *split_string(const char *str, const char *delims); | 21 | list_t *split_string(const char *str, const char *delims); |
19 | void free_flat_list(list_t *list); | 22 | void free_flat_list(list_t *list); |
diff --git a/sway/stringop.c b/sway/stringop.c index 8d6cac2f..fe5a97ca 100644 --- a/sway/stringop.c +++ b/sway/stringop.c | |||
@@ -74,6 +74,19 @@ void strip_quotes(char *str) { | |||
74 | *end = '\0'; | 74 | *end = '\0'; |
75 | } | 75 | } |
76 | 76 | ||
77 | // strcmp that also handles null pointers. | ||
78 | int lenient_strcmp(char *a, char *b) { | ||
79 | if (a == b) { | ||
80 | return 0; | ||
81 | } else if (!a) { | ||
82 | return -1; | ||
83 | } else if (!b) { | ||
84 | return 1; | ||
85 | } else { | ||
86 | return strcmp(a, b); | ||
87 | } | ||
88 | } | ||
89 | |||
77 | list_t *split_string(const char *str, const char *delims) { | 90 | list_t *split_string(const char *str, const char *delims) { |
78 | list_t *res = create_list(); | 91 | list_t *res = create_list(); |
79 | char *copy = strdup(str); | 92 | char *copy = strdup(str); |