aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2002-09-26 11:44:02 +0000
committerMax Horn2002-09-26 11:44:02 +0000
commit58e5e0069f82c9319fd9c6f6987f98886c3b9f67 (patch)
tree06b5cecf9be064323abd796ceac093b5b996a7aa /common
parent522ee88b62206fabb18ce5e4f9221da89b766663 (diff)
downloadscummvm-rg350-58e5e0069f82c9319fd9c6f6987f98886c3b9f67.tar.gz
scummvm-rg350-58e5e0069f82c9319fd9c6f6987f98886c3b9f67.tar.bz2
scummvm-rg350-58e5e0069f82c9319fd9c6f6987f98886c3b9f67.zip
added simple message dialog
svn-id: r5020
Diffstat (limited to 'common')
-rw-r--r--common/str.cpp16
-rw-r--r--common/str.h43
2 files changed, 50 insertions, 9 deletions
diff --git a/common/str.cpp b/common/str.cpp
index 9390f6ff47..6a2333d39c 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -22,19 +22,27 @@
#include "str.h"
#include "util.h"
+
#ifdef _MSC_VER
+
# pragma warning( disable : 4068 ) // unknown pragmas
+
#endif
+
namespace ScummVM {
-String::String(const char *str)
+String::String(const char *str, int len)
{
_refCount = new int(1);
- if (str) {
- _capacity = _len = resStrLen(str);
+ if (str) {
+ if (len)
+ _capacity = _len = len;
+ else
+ _capacity = _len = resStrLen(str);
_str = (char *)calloc(1, _capacity+1);
- memcpy(_str, str, _len+1);
+ memcpy(_str, str, _len);
+ _str[_len] = 0;
} else {
_capacity = _len = 0;
_str = 0;
diff --git a/common/str.h b/common/str.h
index b35c42d0e5..3776ab64c3 100644
--- a/common/str.h
+++ b/common/str.h
@@ -33,7 +33,7 @@ namespace ScummVM {
Only constructor: ConstString(const char *ptr)
Then whenever you now use "const String &" in a parameter, use "const ConstString &"
instead (mayhaps make a typedef even). Thus, parameters are passed w/o
- causing a free/malloc. Then only for permenant storage, when we assign it to a
+ causing a free/malloc. Then only for permanent storage, when we assign it to a
real String object, will a malloc be issued (to this end, make String aware of
ConstString ?!?
*/
@@ -46,7 +46,7 @@ protected:
public:
ConstString() : _str(0), _len(0) {}
- ConstString(const char *str) : _str((char*)str) { _len = str ? strlen(str) : 0; }
+ ConstString(const char *str, int len = 0) : _str((char*)str) { _len = str ? (len ? len : strlen(str)) : 0; }
virtual ~ConstString() {}
bool operator ==(const ConstString& x) const;
@@ -58,6 +58,12 @@ public:
bool operator >(const ConstString& x) const;
bool operator >=(const ConstString& x) const;
+ char operator [](int idx) const
+ {
+ assert(_str && idx >= 0 && idx < _len);
+ return _str[idx];
+ }
+
const char *c_str() const { return _str; }
int size() const { return _len; }
@@ -71,17 +77,33 @@ protected:
public:
String() : _capacity(0) { _refCount = new int(1); }
- String(const char *str);
+ String(const char *str, int len = 0);
String(const ConstString &str);
String(const String &str);
virtual ~String();
String& operator =(const char* str);
+// TODO - We should use RTTI here - that is, not real C++ RTTI but 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
String& operator =(const String& str);
String& operator +=(const char* str);
String& operator +=(const String& str);
String& operator +=(char c);
+ char operator [](int idx) const
+ {
+ assert(_str && idx >= 0 && idx < _len);
+ return _str[idx];
+ }
+
+ char &operator [](int idx)
+ {
+ assert(_str && idx >= 0 && idx < _len);
+ return _str[idx];
+ }
+
void deleteLastChar();
void clear();
@@ -99,8 +121,19 @@ public:
void push_back(const char* str)
{
ensureCapacity(_size + 1);
- _data[_size] = str;
- _size++;
+ _data[_size++] = str;
+ }
+
+ void push_back(const ConstString& str)
+ {
+ ensureCapacity(_size + 1);
+ _data[_size++] = str;
+ }
+
+ void push_back(const String& str)
+ {
+ ensureCapacity(_size + 1);
+ _data[_size++] = str;
}
};