Common: Simplify uppercase/lowercase string functions.

Also changed it to not modify the given string, but rather return a copy of it.
This commit is contained in:
Lioncash 2014-09-08 14:38:26 -04:00
parent 335082e74e
commit 2ff6c6fbf8
2 changed files with 9 additions and 12 deletions

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <cstdio>
@ -18,19 +19,15 @@
#endif
/// Make a string lowercase
void LowerStr(char* str) {
for (int i = 0; str[i]; i++) {
str[i] = tolower(str[ i ]);
}
std::string ToLowerCaseString(std::string input) {
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
return input;
}
/// 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;
}
}
std::string ToUpperCaseString(std::string input) {
std::transform(input.begin(), input.end(), input.begin(), ::toupper);
return input;
}
// faster than sscanf

View File

@ -13,10 +13,10 @@
#include "common/common.h"
/// Make a string lowercase
void LowerStr(char* str);
std::string ToLowerCaseString(std::string input);
/// Make a string uppercase
void UpperStr(char* str);
std::string ToUpperCaseString(std::string input);
std::string StringFromFormat(const char* format, ...);
// Cheap!