aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/str.cpp14
-rw-r--r--common/str.h4
2 files changed, 17 insertions, 1 deletions
diff --git a/common/str.cpp b/common/str.cpp
index 8612a02ed3..1229c14566 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -37,6 +37,20 @@ String::String(const char *str)
}
}
+String::String(const ConstString &str)
+{
+ printf("String::String(const ConstString &str)\n");
+ _refCount = new int(1);
+ if (str._str) {
+ _capacity = _len = strlen(str._str);
+ _str = (char *)calloc(1, _capacity+1);
+ memcpy(_str, str._str, _len+1);
+ } else {
+ _capacity = _len = 0;
+ _str = 0;
+ }
+}
+
String::String(const String &str)
{
++(*str._refCount);
diff --git a/common/str.h b/common/str.h
index fdcd70a154..b35c42d0e5 100644
--- a/common/str.h
+++ b/common/str.h
@@ -39,13 +39,14 @@ namespace ScummVM {
*/
class ConstString {
+ friend class String;
protected:
char *_str;
int _len;
public:
ConstString() : _str(0), _len(0) {}
- ConstString(const char *str) : _str((char*)str) { _len = str ? strlen(str) : 0;}
+ ConstString(const char *str) : _str((char*)str) { _len = str ? strlen(str) : 0; }
virtual ~ConstString() {}
bool operator ==(const ConstString& x) const;
@@ -71,6 +72,7 @@ protected:
public:
String() : _capacity(0) { _refCount = new int(1); }
String(const char *str);
+ String(const ConstString &str);
String(const String &str);
virtual ~String();