aboutsummaryrefslogtreecommitdiff
path: root/common/util.cpp
diff options
context:
space:
mode:
authorMax Horn2002-09-08 01:08:12 +0000
committerMax Horn2002-09-08 01:08:12 +0000
commit523d8e64c0bc66b75cdd7f12fc9d9d87b28a8c36 (patch)
tree01c96c7b834d32b05cf33b15b6631614d22da187 /common/util.cpp
parent943de561bf51d4e553be44fe612eab94e5c00391 (diff)
downloadscummvm-rg350-523d8e64c0bc66b75cdd7f12fc9d9d87b28a8c36.tar.gz
scummvm-rg350-523d8e64c0bc66b75cdd7f12fc9d9d87b28a8c36.tar.bz2
scummvm-rg350-523d8e64c0bc66b75cdd7f12fc9d9d87b28a8c36.zip
rewrote config class; cleanup; code restructuring
svn-id: r4903
Diffstat (limited to 'common/util.cpp')
-rw-r--r--common/util.cpp190
1 files changed, 0 insertions, 190 deletions
diff --git a/common/util.cpp b/common/util.cpp
index 6f55014ef9..7ff4a9e032 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -80,8 +80,6 @@ void ClearBlendCache(byte *palette, int weight)
}
-#pragma mark -
-
/*
* Print hexdump of the data passed in, 8 bytes a row
*/
@@ -122,191 +120,3 @@ void hexdump(const byte * data, int len)
printf(" ");
printf("|\n");
}
-
-
-#pragma mark -
-
-
-namespace ScummVM {
-
-String::String(const char *str)
-{
- _refCount = new int(1);
- _capacity = _len = strlen(str);
- _str = (char *)calloc(1, _capacity+1);
- memcpy(_str, str, _len+1);
-}
-
-String::String(const String &str)
-{
- ++(*str._refCount);
-
- _refCount = str._refCount;
- _capacity = str._capacity;
- _len = str._capacity;
- _str = str._str;
-}
-
-String::~String()
-{
- decRefCount();
-}
-
-void String::decRefCount()
-{
- --(*_refCount);
- if (*_refCount <= 0) {
- delete _refCount;
- if (_str)
- free(_str);
- }
-}
-
-String& String::operator =(const char* str)
-{
- int len = strlen(str);
- if (len > 0) {
- ensureCapacity(len, false);
-
- _len = len;
- memcpy(_str, str, _len + 1);
- } else if (_len > 0) {
- decRefCount();
-
- _refCount = new int(1);
- _capacity = 0;
- _len = 0;
- _str = 0;
- }
- return *this;
-}
-
-String& String::operator =(const String& str)
-{
- ++(*str._refCount);
-
- decRefCount();
-
- _refCount = str._refCount;
- _capacity = str._capacity;
- _len = str._len;
- _str = str._str;
-
- return *this;
-}
-
-String& String::operator +=(const char* str)
-{
- int len = strlen(str);
- if (len > 0) {
- ensureCapacity(_len + len, true);
-
- memcpy(_str + _len, str, len + 1);
- _len += len;
- }
- return *this;
-}
-
-String& String::operator +=(const String& str)
-{
- int len = str._len;
- if (len > 0) {
- ensureCapacity(_len + len, true);
-
- memcpy(_str + _len, str._str, len + 1);
- _len += len;
- }
- return *this;
-}
-
-String& String::operator +=(char c)
-{
- ensureCapacity(_len + 1, true);
-
- _str[_len++] = c;
- _str[_len] = 0;
-
- return *this;
-}
-
-bool String::operator ==(const String& x)
-{
- return (_len == x._len) && ((_len == 0) || (0 == strcmp(_str, x._str)));
-}
-
-bool String::operator ==(const char* x)
-{
- if (_str == 0)
- return (x == 0) || (*x == 0);
- if (x == 0)
- return (_len == 0);
- return (0 != strcmp(_str, x));
-}
-
-bool String::operator !=(const String& x)
-{
- return (_len != x._len) || ((_len != 0) && (0 != strcmp(_str, x._str)));
-}
-
-bool String::operator !=(const char* x)
-{
- if (_str == 0)
- return (x != 0) && (*x != 0);
- if (x == 0)
- return (_len != 0);
- return (0 == strcmp(_str, x));
-}
-
-
-void String::deleteLastChar() {
- if (_len > 0) {
- ensureCapacity(_len - 1, true);
- _str[--_len] = 0;
- }
-}
-
-void String::clear()
-{
- if (_capacity) {
- decRefCount();
-
- _refCount = new int(1);
- _capacity = 0;
- _len = 0;
- _str = 0;
- }
-}
-
-void String::ensureCapacity(int new_len, bool keep_old)
-{
- // If there is not enough space, or if we are not the only owner
- // of the current data, then we have to reallocate it.
- if (new_len <= _capacity && *_refCount == 1)
- return;
-
- int newCapacity = (new_len <= _capacity) ? _capacity : new_len + 32;
- char *newStr = (char *)calloc(1, newCapacity+1);
-
- if (keep_old && _str)
- memcpy(newStr, _str, _len + 1);
- else
- _len = 0;
-
- decRefCount();
-
- _refCount = new int(1);
- _capacity = newCapacity;
- _str = newStr;
-}
-
-bool operator == (const char* y, const String& x)
-{
- return x == y;
-}
-
-bool operator != (const char* y, const String& x)
-{
- return x != y;
-}
-
-}; // End of namespace ScummVM