Skip to content

Commit

Permalink
crnlib: introduce crnlib_strnlwr and crnlib_strnupr
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Jun 25, 2024
1 parent 7f45eb9 commit af3fe18
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
12 changes: 2 additions & 10 deletions crnlib/crn_dynamic_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,14 @@ dynamic_string& dynamic_string::truncate(uint new_len) {

dynamic_string& dynamic_string::tolower() {
if (m_len) {
#if defined(_WIN32)
_strlwr_s(get_ptr_priv(), m_buf_size);
#else
strlwr(get_ptr_priv());
#endif
crnlib_strnlwr(get_ptr_priv(), m_buf_size);
}
return *this;
}

dynamic_string& dynamic_string::toupper() {
if (m_len) {
#if defined(_WIN32)
_strupr_s(get_ptr_priv(), m_buf_size);
#else
strupr(get_ptr_priv());
#endif
crnlib_strnupr(get_ptr_priv(), m_buf_size);
}
return *this;
}
Expand Down
8 changes: 4 additions & 4 deletions crnlib/crn_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
#endif

#if !defined(_WIN32)
char* strlwr(char* p) {
char* crnlib_strnlwr(char* p, size_t n) {
char* q = p;
while (*q) {
for (size_t i = 0; i < n && *q; i++) {
char c = *q;
*q++ = tolower(c);
}
return p;
}

char* strupr(char* p) {
char* crnlib_strnupr(char* p, size_t n) {
char* q = p;
while (*q) {
for (size_t i = 0; i < n && *q; i++) {
char c = *q;
*q++ = toupper(c);
}
Expand Down
10 changes: 8 additions & 2 deletions crnlib/crn_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@ const bool c_crnlib_big_endian_platform = !c_crnlib_little_endian_platform;
#define crnlib_vsnprintf vsnprintf
#endif

#if defined(_WIN32)
#define crnlib_strnlwr _strlwr_s
#define crnlib_strnupr _strupr_s
#else
char* crnlib_strnlwr(char* p, size_t n);
char* crnlib_strnupr(char* p, size_t n);
#endif

#if !defined(_WIN32)
char* strlwr(char* p);
char* strupr(char* p);
#define _stricmp strcasecmp
#define _strnicmp strncasecmp
#endif
Expand Down

0 comments on commit af3fe18

Please sign in to comment.