mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-23 08:20:09 +00:00
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:
parent
335082e74e
commit
2ff6c6fbf8
@ -3,6 +3,7 @@
|
|||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
@ -18,19 +19,15 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Make a string lowercase
|
/// Make a string lowercase
|
||||||
void LowerStr(char* str) {
|
std::string ToLowerCaseString(std::string input) {
|
||||||
for (int i = 0; str[i]; i++) {
|
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
|
||||||
str[i] = tolower(str[ i ]);
|
return input;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make a string uppercase
|
/// Make a string uppercase
|
||||||
void UpperStr(char* str) {
|
std::string ToUpperCaseString(std::string input) {
|
||||||
for (int i=0; i < strlen(str); i++) {
|
std::transform(input.begin(), input.end(), input.begin(), ::toupper);
|
||||||
if(str[i] >= 'a' && str[i] <= 'z') {
|
return input;
|
||||||
str[i] &= 0xDF;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// faster than sscanf
|
// faster than sscanf
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
|
|
||||||
/// Make a string lowercase
|
/// Make a string lowercase
|
||||||
void LowerStr(char* str);
|
std::string ToLowerCaseString(std::string input);
|
||||||
|
|
||||||
/// Make a string uppercase
|
/// Make a string uppercase
|
||||||
void UpperStr(char* str);
|
std::string ToUpperCaseString(std::string input);
|
||||||
|
|
||||||
std::string StringFromFormat(const char* format, ...);
|
std::string StringFromFormat(const char* format, ...);
|
||||||
// Cheap!
|
// Cheap!
|
||||||
|
Loading…
Reference in New Issue
Block a user