mirror of
https://github.com/troglobit/libite.git
synced 2026-10-02 05:42:49 +07:00
lite.h: Add some helper string comparison methods.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -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_ */
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user