Przeglądaj źródła

added helper functions for upper/lowercase strings

bunnei 12 lat temu
rodzic
commit
cb504e236b
2 zmienionych plików z 22 dodań i 0 usunięć
  1. 16 0
      src/common/string_util.cpp
  2. 6 0
      src/common/string_util.h

+ 16 - 0
src/common/string_util.cpp

@@ -17,6 +17,22 @@
     #include <errno.h>
 #endif
 
+/// Make a string lowercase
+void LowerStr(char* str) {
+    for (int i = 0; str[i]; i++) {
+        str[i] = tolower(str[ i ]);
+    }
+}
+
+/// Make a string uppercase
+void UpperStr(char* str) {
+    for (int i=0; i < strlen(str); i++) {
+        if(str[i] >= 'a' && str[i] <= 'z') {
+            str[i] &= 0xDF;
+        }
+    }
+}
+
 // faster than sscanf
 bool AsciiToHex(const char* _szValue, u32& result)
 {

+ 6 - 0
src/common/string_util.h

@@ -14,6 +14,12 @@
 
 #include "common/common.h"
 
+/// Make a string lowercase
+void LowerStr(char* str);
+
+/// Make a string uppercase
+void UpperStr(char* str);
+
 std::string StringFromFormat(const char* format, ...);
 // Cheap!
 bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args);