diff options
author | Howaner <franzi.moos@googlemail.com> | 2014-08-04 12:11:38 +0200 |
---|---|---|
committer | Howaner <franzi.moos@googlemail.com> | 2014-08-04 12:11:38 +0200 |
commit | 7bd414e9edf432641c30448c3fc0ff04d91ad3ab (patch) | |
tree | 93cb320e9911343f052b722278231c8b9dd79a1a /src/StringUtils.cpp | |
parent | Changed /** to /* (diff) | |
parent | Merge pull request #1285 from mc-server/StrCaseRefactor (diff) | |
download | cuberite-7bd414e9edf432641c30448c3fc0ff04d91ad3ab.tar cuberite-7bd414e9edf432641c30448c3fc0ff04d91ad3ab.tar.gz cuberite-7bd414e9edf432641c30448c3fc0ff04d91ad3ab.tar.bz2 cuberite-7bd414e9edf432641c30448c3fc0ff04d91ad3ab.tar.lz cuberite-7bd414e9edf432641c30448c3fc0ff04d91ad3ab.tar.xz cuberite-7bd414e9edf432641c30448c3fc0ff04d91ad3ab.tar.zst cuberite-7bd414e9edf432641c30448c3fc0ff04d91ad3ab.zip |
Diffstat (limited to 'src/StringUtils.cpp')
-rw-r--r-- | src/StringUtils.cpp | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index decce8065..5f88cbf64 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -196,16 +196,9 @@ AString TrimString(const AString & str) -AString & StrToUpper(AString & s) +AString & InPlaceLowercase(AString & s) { - AString::iterator i = s.begin(); - AString::iterator end = s.end(); - - while (i != end) - { - *i = (char)toupper(*i); - ++i; - } + std::transform(s.begin(), s.end(), s.begin(), ::tolower); return s; } @@ -213,16 +206,9 @@ AString & StrToUpper(AString & s) -AString & StrToLower(AString & s) +AString & InPlaceUppercase(AString & s) { - AString::iterator i = s.begin(); - AString::iterator end = s.end(); - - while (i != end) - { - *i = (char)tolower(*i); - ++i; - } + std::transform(s.begin(), s.end(), s.begin(), ::toupper); return s; } @@ -232,12 +218,19 @@ AString & StrToLower(AString & s) AString StrToLower(const AString & s) { - AString res; - res.resize(s.size()); - for (AString::iterator itr = res.begin(), end = res.end(); itr != end; ++itr) - { - *itr = (char)tolower(*itr); - } + AString res(s); + std::transform(res.begin(), res.end(), res.begin(), ::tolower); + return res; +} + + + + + +AString StrToUpper(const AString & s) +{ + AString res(s); + std::transform(res.begin(), res.end(), res.begin(), ::toupper); return res; } @@ -251,10 +244,8 @@ int NoCaseCompare(const AString & s1, const AString & s2) // MSVC has stricmp that compares case-insensitive: return _stricmp(s1.c_str(), s2.c_str()); #else - // Do it the hard way: - AString s1Copy(s1); - AString s2Copy(s2); - return StrToUpper(s1Copy).compare(StrToUpper(s2Copy)); + // Do it the hard way - convert both strings to lowercase: + return StrToLower(s1).compare(StrToLower(s2)); #endif // else _MSC_VER } |