From a96e625a3640d3633c80b0d2c0648f965a9e6c8c Mon Sep 17 00:00:00 2001 From: Tau Date: Mon, 13 May 2019 16:48:34 -0400 Subject: [PATCH] util/str.c: Add string equality wrappers --- util/meson.build | 2 ++ util/str.c | 11 +++++++++++ util/str.h | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 util/str.c create mode 100644 util/str.h 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; +}