stringop: lenient_strcmp: Add.

This commit is contained in:
S. Christoffer Eliesen 2015-11-19 11:52:58 +01:00
parent a33e3badad
commit d0af224e6d
2 changed files with 16 additions and 0 deletions

View File

@ -14,6 +14,9 @@ char *strip_whitespace(char *str);
char *strip_comments(char *str);
void strip_quotes(char *str);
// strcmp that also handles null pointers.
int lenient_strcmp(char *a, char *b);
// Simply split a string with delims, free with `free_flat_list`
list_t *split_string(const char *str, const char *delims);
void free_flat_list(list_t *list);

View File

@ -74,6 +74,19 @@ void strip_quotes(char *str) {
*end = '\0';
}
// strcmp that also handles null pointers.
int lenient_strcmp(char *a, char *b) {
if (a == b) {
return 0;
} else if (!a) {
return -1;
} else if (!b) {
return 1;
} else {
return strcmp(a, b);
}
}
list_t *split_string(const char *str, const char *delims) {
list_t *res = create_list();
char *copy = strdup(str);