mirror of
https://github.com/troglobit/libite.git
synced 2026-11-06 15:50:57 +00:00
lite.h: Add some helper string comparison methods.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
80c2a132cd
commit
36d24ce366
1 file changed
+30
@@ -29,6 +29,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int fexist (char *file);
|
int fexist (char *file);
|
||||||
@@ -60,6 +61,35 @@ static inline int fisslashdir(char *dir)
|
|||||||
return 0;
|
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_ */
|
#endif /* FINIT_LITE_H_ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user