From 0ecb9af21fc81e41b18358152b12adcbb05d64ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 12 Feb 2017 21:59:55 -0800 Subject: [PATCH] Added toLower/UpperUnsafe. --- include/bx/string.h | 6 ++++++ src/crt.cpp | 2 +- src/string.cpp | 24 ++++++++++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) 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]);