WINTERMUTE: Cleanup and simplify StringUtil a bit.

This commit is contained in:
Einar Johan Trøan Sømåen 2012-07-09 04:17:28 +02:00
parent 7c984d24a8
commit 01d6ff2121
6 changed files with 10 additions and 52 deletions

View File

@ -58,13 +58,13 @@ ERRORCODE CBStringTable::addString(const char *key, const char *val, bool report
return STATUS_OK;
}
Common::String final_key = key;
StringUtil::toLowerCase(final_key);
Common::String finalKey = key;
finalKey.toLowercase();
_stringsIter = _strings.find(final_key);
if (_stringsIter != _strings.end() && reportDuplicities) Game->LOG(0, " Warning: Duplicate definition of string '%s'.", final_key.c_str());
_stringsIter = _strings.find(finalKey);
if (_stringsIter != _strings.end() && reportDuplicities) Game->LOG(0, " Warning: Duplicate definition of string '%s'.", finalKey.c_str());
_strings[final_key] = val;
_strings[finalKey] = val;
return STATUS_OK;
}

View File

@ -181,7 +181,7 @@ ERRORCODE CSXString::scCallMethod(CScScript *script, CScStack *stack, CScStack *
else
str = StringUtil::ansiToWide(_string);
StringUtil::toUpperCase(str);
str.toUppercase();
if (Game->_textEncoding == TEXT_UTF8)
stack->pushString(StringUtil::wideToUtf8(str).c_str());
@ -203,7 +203,7 @@ ERRORCODE CSXString::scCallMethod(CScScript *script, CScStack *stack, CScStack *
else
str = StringUtil::ansiToWide(_string);
StringUtil::toLowerCase(str);
str.toLowercase();
if (Game->_textEncoding == TEXT_UTF8)
stack->pushString(StringUtil::wideToUtf8(str).c_str());

View File

@ -658,7 +658,7 @@ void CScEngine::addScriptTime(const char *filename, uint32 time) {
if (!_isProfiling) return;
AnsiString fileName = filename;
StringUtil::toLowerCase(fileName);
fileName.toLowercase();
_scriptTimes[fileName] += time;
}

View File

@ -47,7 +47,7 @@ AnsiString PathUtil::unifySeparators(const AnsiString &path) {
//////////////////////////////////////////////////////////////////////////
AnsiString PathUtil::normalizeFileName(const AnsiString &path) {
AnsiString newPath = unifySeparators(path);
StringUtil::toLowerCase(newPath);
newPath.toLowercase();
return newPath;
}

View File

@ -33,35 +33,9 @@
namespace WinterMute {
//////////////////////////////////////////////////////////////////////////
void StringUtil::toLowerCase(AnsiString &str) {
str.toLowercase();
}
//////////////////////////////////////////////////////////////////////////
/*void StringUtil::toLowerCase(WideString &str) {
std::transform(str.begin(), str.end(), str.begin(), ::towlower);
}*/
//////////////////////////////////////////////////////////////////////////
void StringUtil::toUpperCase(AnsiString &str) {
str.toUppercase();
}
//////////////////////////////////////////////////////////////////////////
/*void StringUtil::toUpperCase(WideString &str) {
std::transform(str.begin(), str.end(), str.begin(), ::towupper);
}*/
//////////////////////////////////////////////////////////////////////////
bool StringUtil::compareNoCase(const AnsiString &str1, const AnsiString &str2) {
AnsiString str1lc = str1;
AnsiString str2lc = str2;
toLowerCase(str1lc);
toLowerCase(str2lc);
return (str1lc == str2lc);
return (str1.compareToIgnoreCase(str2) == 0);
}
//////////////////////////////////////////////////////////////////////////
@ -369,33 +343,21 @@ int StringUtil::lastIndexOf(const WideString &str, const WideString &toFind, siz
//////////////////////////////////////////////////////////////////////////
AnsiString StringUtil::toString(size_t val) {
/* std::ostringstream str;
str << val;
return str.str();*/
return Common::String::format("%u", (uint32)val);
}
//////////////////////////////////////////////////////////////////////////
AnsiString StringUtil::toString(int val) {
/* std::ostringstream str;
str << val;
return str.str();*/
return Common::String::format("%d", val);
}
//////////////////////////////////////////////////////////////////////////
AnsiString StringUtil::toString(float val) {
/* std::ostringstream str;
str << val;
return str.str();*/
return Common::String::format("%f", val);
}
//////////////////////////////////////////////////////////////////////////
AnsiString StringUtil::toString(double val) {
/* std::ostringstream str;
str << val;
return str.str();*/
return Common::String::format("%f", val);
}

View File

@ -35,10 +35,6 @@ namespace WinterMute {
class StringUtil {
public:
static void toLowerCase(AnsiString &str);
//static void toLowerCase(WideString &str);
static void toUpperCase(AnsiString &str);
//static void toUpperCase(WideString &str);
static bool compareNoCase(const AnsiString &str1, const AnsiString &str2);
//static bool compareNoCase(const WideString &str1, const WideString &str2);
static WideString utf8ToWide(const Utf8String &Utf8Str);