aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2008-03-30 18:37:09 +0000
committerMax Horn2008-03-30 18:37:09 +0000
commit57ad73faeec62f304f257433659ab9b8f559ecb0 (patch)
tree21f682a1920d79d9047ef4e4c8cc6b077d8bd17f /common
parent351851971bc8d254dddfdfbb1fda3bcffdedcf2c (diff)
downloadscummvm-rg350-57ad73faeec62f304f257433659ab9b8f559ecb0.tar.gz
scummvm-rg350-57ad73faeec62f304f257433659ab9b8f559ecb0.tar.bz2
scummvm-rg350-57ad73faeec62f304f257433659ab9b8f559ecb0.zip
Removed char &operator [] from class String -- it had the potential to wreak havoc when used on shared strings (thanks to tramboi for pointing this out)
svn-id: r31334
Diffstat (limited to 'common')
-rw-r--r--common/file.cpp37
-rw-r--r--common/str.cpp7
-rw-r--r--common/str.h16
3 files changed, 35 insertions, 25 deletions
diff --git a/common/file.cpp b/common/file.cpp
index ccfeb5f322..7fe2e1b655 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -146,54 +146,53 @@ static StringMap *_filesMap;
static FILE *fopenNoCase(const String &filename, const String &directory, const char *mode) {
FILE *file;
- String buf(directory);
- uint i;
+ String dirBuf(directory);
+ String fileBuf(filename);
#if !defined(__GP32__) && !defined(PALMOS_MODE)
// Add a trailing slash, if necessary.
- if (!buf.empty()) {
- const char c = buf.lastChar();
+ if (!dirBuf.empty()) {
+ const char c = dirBuf.lastChar();
if (c != ':' && c != '/' && c != '\\')
- buf += '/';
+ dirBuf += '/';
}
#endif
// Append the filename to the path string
- const int offsetToFileName = buf.size();
- buf += filename;
+ String pathBuf(dirBuf);
+ pathBuf += fileBuf;
//
// Try to open the file normally
//
- file = fopen(buf.c_str(), mode);
+ file = fopen(pathBuf.c_str(), mode);
//
// Try again, with file name converted to upper case
//
if (!file) {
- for (i = offsetToFileName; i < buf.size(); ++i) {
- buf[i] = toupper(buf[i]);
- }
- file = fopen(buf.c_str(), mode);
+ fileBuf.toUppercase();
+ pathBuf += fileBuf;
+ file = fopen(pathBuf.c_str(), mode);
}
//
// Try again, with file name converted to lower case
//
if (!file) {
- for (i = offsetToFileName; i < buf.size(); ++i) {
- buf[i] = tolower(buf[i]);
- }
- file = fopen(buf.c_str(), mode);
+ fileBuf.toLowercase();
+ pathBuf += fileBuf;
+ file = fopen(pathBuf.c_str(), mode);
}
//
// Try again, with file name capitalized
//
if (!file) {
- i = offsetToFileName;
- buf[i] = toupper(buf[i]);
- file = fopen(buf.c_str(), mode);
+ fileBuf.toLowercase();
+ fileBuf.setChar(toupper(fileBuf[0]),0);
+ pathBuf += fileBuf;
+ file = fopen(pathBuf.c_str(), mode);
}
#ifdef __amigaos4__
diff --git a/common/str.cpp b/common/str.cpp
index 9e94d240d7..ad48ef6087 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -254,6 +254,13 @@ void String::clear() {
_storage[0] = 0;
}
+void String::setChar(char c, uint32 p) {
+ assert(p <= _len);
+
+ ensureCapacity(_len, true);
+ _str[p] = c;
+}
+
void String::insertChar(char c, uint32 p) {
assert(p <= _len);
diff --git a/common/str.h b/common/str.h
index e85213b561..a92ec34fff 100644
--- a/common/str.h
+++ b/common/str.h
@@ -146,16 +146,20 @@ public:
return _str[idx];
}
- char &operator [](int idx) {
- assert(_str && idx >= 0 && idx < (int)_len);
- return _str[idx];
- }
-
+ /** Remove the last character from the string. */
void deleteLastChar();
+
+ /** Remove the character at position p from the string. */
void deleteChar(uint32 p);
- void clear();
+
+ /** Set character c at position p, replacing the previous character there. */
+ void setChar(char c, uint32 p);
+
+ /** Set character c at position p. */
void insertChar(char c, uint32 p);
+ void clear();
+
void toLowercase();
void toUppercase();