lite.h: Add some helper string comparison methods.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2014-04-21 15:45:23 +02:00
parent 80c2a132cd
commit 36d24ce366
+30
View File
@@ -29,6 +29,7 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
#include <unistd.h>
int fexist (char *file);
@@ -60,6 +61,35 @@ static inline int fisslashdir(char *dir)
return 0;
}
/* Validate string, non NULL and not zero length */
static inline int string_valid (const char *s)
{
return s && strlen (s);
}
/* Relaxed comparison, e.g., sys_string_match("small", "smaller") => TRUE */
static inline int string_match (const char *a, const char *b)
{
size_t min = MIN(strlen (a), strlen (b));
return !strncasecmp (a, b, min);
}
/* Strict comparison, e.g., sys_string_match("small", "smaller") => FALSE */
static inline int string_compare (const char *a, const char *b)
{
return strlen (a) == strlen (b) && !strcmp (a, b);
}
/* Strict comparison, like sys_string_compare(), but case insensitive,
* e.g., sys_string_match("small", "SmAlL") => TRUE
*/
static inline int string_case_compare (const char *a, const char *b)
{
return strlen (a) == strlen (b) && !strcasecmp (a, b);
}
#endif /* FINIT_LITE_H_ */
/**