diff --git a/include/bx/string.h b/include/bx/string.h index 21ec6ea..ab1b5d8 100644 --- a/include/bx/string.h +++ b/include/bx/string.h @@ -110,12 +110,18 @@ namespace bx /// char toLower(char _ch); + /// + void toLowerUnsafe(char* _inOutStr, size_t _len); + /// void toLower(char* _inOutStr, size_t _max = INT32_MAX); /// char toUpper(char _ch); + /// + void toUpperUnsafe(char* _inOutStr, size_t _len); + /// void toUpper(char* _inOutStr, size_t _max = INT32_MAX); diff --git a/src/crt.cpp b/src/crt.cpp index 00e9f2f..d363897 100644 --- a/src/crt.cpp +++ b/src/crt.cpp @@ -288,7 +288,7 @@ namespace bx if (_param.upper) { - toUpper(str, len); + toUpperUnsafe(str, len); } const char* dot = strnchr(str, '.'); diff --git a/src/string.cpp b/src/string.cpp index 4093e4e..9e81450 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -60,31 +60,39 @@ namespace bx return _ch + (isUpper(_ch) ? 0x20 : 0); } - void toLower(char* _inOutStr, size_t _max) + void toLowerUnsafe(char* _inOutStr, size_t _len) { - size_t len = strnlen(_inOutStr, _max); - - for (size_t ii = 0; ii < len; ++ii) + for (size_t ii = 0; ii < _len; ++ii) { *_inOutStr = toLower(*_inOutStr); } } + void toLower(char* _inOutStr, size_t _max) + { + const size_t len = strnlen(_inOutStr, _max); + toLowerUnsafe(_inOutStr, len); + } + char toUpper(char _ch) { return _ch - (isLower(_ch) ? 0x20 : 0); } - void toUpper(char* _inOutStr, size_t _max) + void toUpperUnsafe(char* _inOutStr, size_t _len) { - size_t len = strnlen(_inOutStr, _max); - - for (size_t ii = 0; ii < len; ++ii) + for (size_t ii = 0; ii < _len; ++ii) { *_inOutStr = toUpper(*_inOutStr); } } + void toUpper(char* _inOutStr, size_t _max) + { + const size_t len = strnlen(_inOutStr, _max); + toUpperUnsafe(_inOutStr, len); + } + bool toBool(const char* _str) { char ch = toLower(_str[0]);