[Scummvm-cvs-logs] CVS: scummvm/common str.cpp,1.2,1.3 str.h,1.2,1.3

Max Horn fingolfin at users.sourceforge.net
Mon Sep 9 04:43:01 CEST 2002


Update of /cvsroot/scummvm/scummvm/common
In directory usw-pr-cvs1:/tmp/cvs-serv2391

Modified Files:
	str.cpp str.h 
Log Message:
added String constructor which takes (and clones) a ConstString

Index: str.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/str.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- str.cpp	8 Sep 2002 11:46:42 -0000	1.2
+++ str.cpp	9 Sep 2002 11:42:24 -0000	1.3
@@ -37,6 +37,20 @@
 	}
 }
 
+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);

Index: str.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/str.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- str.h	8 Sep 2002 11:46:42 -0000	1.2
+++ str.h	9 Sep 2002 11:42:24 -0000	1.3
@@ -39,13 +39,14 @@
 */
 
 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 @@
 public:
 	String() : _capacity(0) { _refCount = new int(1); }
 	String(const char *str);
+	String(const ConstString &str);
 	String(const String &str);
 	virtual ~String();
 	





More information about the Scummvm-git-logs mailing list