Explorar o código

Added toLower/UpperUnsafe.

Branimir Karadžić %!s(int64=8) %!d(string=hai) anos
pai
achega
0ecb9af21f
Modificáronse 3 ficheiros con 23 adicións e 9 borrados
  1. 6 0
      include/bx/string.h
  2. 1 1
      src/crt.cpp
  3. 16 8
      src/string.cpp

+ 6 - 0
include/bx/string.h

@@ -110,12 +110,18 @@ namespace bx
 	///
 	///
 	char toLower(char _ch);
 	char toLower(char _ch);
 
 
+	///
+	void toLowerUnsafe(char* _inOutStr, size_t _len);
+
 	///
 	///
 	void toLower(char* _inOutStr, size_t _max = INT32_MAX);
 	void toLower(char* _inOutStr, size_t _max = INT32_MAX);
 
 
 	///
 	///
 	char toUpper(char _ch);
 	char toUpper(char _ch);
 
 
+	///
+	void toUpperUnsafe(char* _inOutStr, size_t _len);
+
 	///
 	///
 	void toUpper(char* _inOutStr, size_t _max = INT32_MAX);
 	void toUpper(char* _inOutStr, size_t _max = INT32_MAX);
 
 

+ 1 - 1
src/crt.cpp

@@ -288,7 +288,7 @@ namespace bx
 
 
 			if (_param.upper)
 			if (_param.upper)
 			{
 			{
-				toUpper(str, len);
+				toUpperUnsafe(str, len);
 			}
 			}
 
 
 			const char* dot = strnchr(str, '.');
 			const char* dot = strnchr(str, '.');

+ 16 - 8
src/string.cpp

@@ -60,31 +60,39 @@ namespace bx
 		return _ch + (isUpper(_ch) ? 0x20 : 0);
 		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);
 			*_inOutStr = toLower(*_inOutStr);
 		}
 		}
 	}
 	}
 
 
+	void toLower(char* _inOutStr, size_t _max)
+	{
+		const size_t len = strnlen(_inOutStr, _max);
+		toLowerUnsafe(_inOutStr, len);
+	}
+
 	char toUpper(char _ch)
 	char toUpper(char _ch)
 	{
 	{
 		return _ch - (isLower(_ch) ? 0x20 : 0);
 		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);
 			*_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)
 	bool toBool(const char* _str)
 	{
 	{
 		char ch = toLower(_str[0]);
 		char ch = toLower(_str[0]);