aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2002-09-09 11:42:24 +0000
committerMax Horn2002-09-09 11:42:24 +0000
commit22e2df20c2aeb78c9b7bac513aa0d45e75faa433 (patch)
treed1c77230407c7f4a537321ce6509f26638f9cafe /common
parentf277bb9fcd853dc1d647467a38bc49fc51d28543 (diff)
downloadscummvm-rg350-22e2df20c2aeb78c9b7bac513aa0d45e75faa433.tar.gz
scummvm-rg350-22e2df20c2aeb78c9b7bac513aa0d45e75faa433.tar.bz2
scummvm-rg350-22e2df20c2aeb78c9b7bac513aa0d45e75faa433.zip
added String constructor which takes (and clones) a ConstString
svn-id: r4918
Diffstat (limited to 'common')
-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();