Skip to content

Commit

Permalink
crnlib: introduce crnlib_stricmp and crnlib_strnicmp
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Jun 25, 2024
1 parent af3fe18 commit 68cbbee
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 17 deletions.
6 changes: 3 additions & 3 deletions crnlib/crn_dynamic_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void dynamic_string::optimize() {
int dynamic_string::compare(const char* p, bool case_sensitive) const {
CRNLIB_ASSERT(p);

const int result = (case_sensitive ? strcmp : crn_stricmp)(get_ptr_priv(), p);
const int result = (case_sensitive ? strcmp : crnlib_stricmp)(get_ptr_priv(), p);

if (result < 0)
return -1;
Expand Down Expand Up @@ -379,7 +379,7 @@ int dynamic_string::find_left(const char* p, bool case_sensitive) const {
const int p_len = (int)strlen(p);

for (int i = 0; i <= (m_len - p_len); i++)
if ((case_sensitive ? strncmp : _strnicmp)(p, &m_pStr[i], p_len) == 0)
if ((case_sensitive ? strncmp : crnlib_strnicmp)(p, &m_pStr[i], p_len) == 0)
return i;

return -1;
Expand Down Expand Up @@ -416,7 +416,7 @@ int dynamic_string::find_right(const char* p, bool case_sensitive) const {
const int p_len = (int)strlen(p);

for (int i = m_len - p_len; i >= 0; i--)
if ((case_sensitive ? strncmp : _strnicmp)(p, &m_pStr[i], p_len) == 0)
if ((case_sensitive ? strncmp : crnlib_strnicmp)(p, &m_pStr[i], p_len) == 0)
return i;

return -1;
Expand Down
9 changes: 6 additions & 3 deletions crnlib/crn_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ char* crnlib_strnlwr(char* p, size_t n);
char* crnlib_strnupr(char* p, size_t n);
#endif

#if !defined(_WIN32)
#define _stricmp strcasecmp
#define _strnicmp strncasecmp
#if defined(_WIN32)
#define crnlib_stricmp _stricmp
#define crnlib_strnicmp _strnicmp
#else
#define crnlib_stricmp strcasecmp
#define crnlib_strnicmp strncasecmp
#endif

inline bool crnlib_is_little_endian() {
Expand Down
2 changes: 1 addition & 1 deletion crnlib/crn_resample_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ const int g_num_resample_filters = sizeof(g_resample_filters) / sizeof(g_resampl

int find_resample_filter(const char* pName) {
for (int i = 0; i < g_num_resample_filters; i++)
if (_stricmp(pName, g_resample_filters[i].name) == 0)
if (crnlib_stricmp(pName, g_resample_filters[i].name) == 0)
return i;
return cInvalidIndex;
}
Expand Down
8 changes: 2 additions & 6 deletions crnlib/crn_strutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ char* crn_strdup(const char* pStr) {
return p;
}

int crn_stricmp(const char* p, const char* q) {
return _stricmp(p, q);
}

char* strcpy_safe(char* pDst, uint dst_len, const char* pSrc) {
CRNLIB_ASSERT(pDst && pSrc && dst_len);
if (!dst_len)
Expand Down Expand Up @@ -310,10 +306,10 @@ bool string_to_bool(const char* p, bool& value) {

value = false;

if (_stricmp(p, "false") == 0)
if (crnlib_stricmp(p, "false") == 0)
return true;

if (_stricmp(p, "true") == 0) {
if (crnlib_stricmp(p, "true") == 0) {
value = true;
return true;
}
Expand Down
1 change: 0 additions & 1 deletion crnlib/crn_strutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace crnlib {
char* crn_strdup(const char* pStr);
int crn_stricmp(const char* p, const char* q);

char* strcpy_safe(char* pDst, uint dst_len, const char* pSrc);

Expand Down
4 changes: 2 additions & 2 deletions crnlib/crn_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ class value {
return false;
}

if (_stricmp(p, "false") == 0) {
if (crnlib_stricmp(p, "false") == 0) {
set_bool(false);
return true;
} else if (_stricmp(p, "true") == 0) {
} else if (crnlib_stricmp(p, "true") == 0) {
set_bool(true);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion crunch/crunch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ class crunch {
static bool check_for_option(int argc, char* argv[], const char* pOption) {
for (int i = 1; i < argc; i++) {
if ((argv[i][0] == '/') || (argv[i][0] == '-')) {
if (crn_stricmp(&argv[i][1], pOption) == 0)
if (crnlib_stricmp(&argv[i][1], pOption) == 0)
return true;
}
}
Expand Down

0 comments on commit 68cbbee

Please sign in to comment.