util/str.c: Add string equality wrappers

This commit is contained in:
Tau 2019-05-13 16:48:34 -04:00
parent 9e3c70ad6b
commit a96e625a36
3 changed files with 54 additions and 0 deletions

View File

@ -25,5 +25,7 @@ util_lib = static_library(
'setupapi.h',
'spike.c',
'spike.h',
'str.c',
'str.h',
],
)

11
util/str.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <wchar.h>
#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);

41
util/str.h Normal file
View File

@ -0,0 +1,41 @@
#pragma once
#include <stdbool.h>
#include <string.h>
#include <wchar.h>
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;
}