diff --git a/util/meson.build b/util/meson.build index 4077658..6cb0c9f 100644 --- a/util/meson.build +++ b/util/meson.build @@ -25,5 +25,7 @@ util_lib = static_library( 'setupapi.h', 'spike.c', 'spike.h', + 'str.c', + 'str.h', ], ) diff --git a/util/str.c b/util/str.c new file mode 100644 index 0000000..41ea6c2 --- /dev/null +++ b/util/str.c @@ -0,0 +1,11 @@ +#include +#include +#include +#include + +#include "util/str.h" + +extern inline bool str_eq(const char *lhs, const char *rhs); +extern inline bool str_ieq(const char *lhs, const char *rhs); +extern inline bool wstr_eq(const wchar_t *lhs, const wchar_t *rhs); +extern inline bool wstr_ieq(const wchar_t *lhs, const wchar_t *rhs); diff --git a/util/str.h b/util/str.h new file mode 100644 index 0000000..b07948a --- /dev/null +++ b/util/str.h @@ -0,0 +1,41 @@ +#pragma once + +#include +#include +#include + +inline bool str_eq(const char *lhs, const char *rhs) +{ + if (lhs == NULL || rhs == NULL) { + return lhs == rhs; + } + + return strcmp(lhs, rhs) == 0; +} + +inline bool str_ieq(const char *lhs, const char *rhs) +{ + if (lhs == NULL || rhs == NULL) { + return lhs == rhs; + } + + return _stricmp(lhs, rhs) == 0; +} + +inline bool wstr_eq(const wchar_t *lhs, const wchar_t *rhs) +{ + if (lhs == NULL || rhs == NULL) { + return lhs == rhs; + } + + return wcscmp(lhs, rhs) == 0; +} + +inline bool wstr_ieq(const wchar_t *lhs, const wchar_t *rhs) +{ + if (lhs == NULL || rhs == NULL) { + return lhs == rhs; + } + + return _wcsicmp(lhs, rhs) == 0; +}