aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2002-10-08 00:11:41 +0000
committerMax Horn2002-10-08 00:11:41 +0000
commit8a7637cfc1c6f21ee11a8504b18ad5a64426dd81 (patch)
treeed87c6fb6ed1565ca8bb76f452e5f4f6e6f8407d /common
parent82f3e17cb5cbf7b533b4979d80fff4ed783b9032 (diff)
downloadscummvm-rg350-8a7637cfc1c6f21ee11a8504b18ad5a64426dd81.tar.gz
scummvm-rg350-8a7637cfc1c6f21ee11a8504b18ad5a64426dd81.tar.bz2
scummvm-rg350-8a7637cfc1c6f21ee11a8504b18ad5a64426dd81.zip
added methods to String class that convert a string to upper/lower case; changed config class to keep all domains as lower case (fixes bug #scummvm)
svn-id: r5104
Diffstat (limited to 'common')
-rw-r--r--common/config-file.cpp1
-rw-r--r--common/str.cpp19
-rw-r--r--common/str.h9
3 files changed, 27 insertions, 2 deletions
diff --git a/common/config-file.cpp b/common/config-file.cpp
index bcc7537741..5ac3988e13 100644
--- a/common/config-file.cpp
+++ b/common/config-file.cpp
@@ -164,6 +164,7 @@ void Config::setBool(const String &key, bool value_b, const String &d)
void Config::set_domain(const String &d)
{
defaultDomain = d;
+ defaultDomain.toLowercase();
}
bool Config::has_domain(const String &d) const
diff --git a/common/str.cpp b/common/str.cpp
index 7b33b29c30..ea35b665af 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -21,6 +21,7 @@
#include "stdafx.h"
#include "str.h"
+#include <ctype.h>
#ifdef _MSC_VER
# pragma warning( disable : 4068 ) // unknown pragmas
@@ -171,6 +172,24 @@ void String::clear()
}
}
+void String::toLowercase()
+{
+ if (_str == 0 || _len == 0)
+ return;
+
+ for (int i = 0; i < _len; ++i)
+ _str[i] = tolower(_str[i]);
+}
+
+void String::toUppercase()
+{
+ if (_str == 0 || _len == 0)
+ return;
+
+ for (int i = 0; i < _len; ++i)
+ _str[i] = toupper(_str[i]);
+}
+
void String::ensureCapacity(int new_len, bool keep_old)
{
// If there is not enough space, or if we are not the only owner
diff --git a/common/str.h b/common/str.h
index c7c533d952..41227192b0 100644
--- a/common/str.h
+++ b/common/str.h
@@ -83,10 +83,12 @@ public:
virtual ~String();
String& operator =(const char* str);
-// TODO - We should use RTTI here - that is, not real C++ RTTI but some magic
+// TODO - We should use RTTI here - that is, not real C++ RTTI but maybe some magic
// constant in each string object. We want to be able to optimize the case when
// a real 'String' object is passed to a function as a ConstString obj and then
-// assigned to a 'String' object
+// assigned to a 'String' object.
+// An alternative would be to add private clone() and cloneMutable methods that
+// would do the right thing.
String& operator =(const String& str);
String& operator +=(const char* str);
String& operator +=(const String& str);
@@ -106,6 +108,9 @@ public:
void deleteLastChar();
void clear();
+
+ void toLowercase();
+ void toUppercase();
protected:
void ensureCapacity(int new_len, bool keep_old);