diff options
author | Max Horn | 2002-07-13 11:59:39 +0000 |
---|---|---|
committer | Max Horn | 2002-07-13 11:59:39 +0000 |
commit | 198d667d1ede63580ba38b5f2084bc5c85c01ee8 (patch) | |
tree | bf96c8fdb218718bc30a6d0beac25638d85b8222 | |
parent | 43b8300eb29c1fadd147ba5325e703f88ed3a8bd (diff) | |
download | scummvm-rg350-198d667d1ede63580ba38b5f2084bc5c85c01ee8.tar.gz scummvm-rg350-198d667d1ede63580ba38b5f2084bc5c85c01ee8.tar.bz2 scummvm-rg350-198d667d1ede63580ba38b5f2084bc5c85c01ee8.zip |
added clear() methods to String and StringList; StringList destructor now doesn't leak anymore
svn-id: r4533
-rw-r--r-- | gui/util.cpp | 19 | ||||
-rw-r--r-- | gui/util.h | 4 |
2 files changed, 21 insertions, 2 deletions
diff --git a/gui/util.cpp b/gui/util.cpp index 27e672b472..96476c8423 100644 --- a/gui/util.cpp +++ b/gui/util.cpp @@ -159,6 +159,13 @@ String& String::operator +=(char c) return *this; } +void String::clear() +{ + _len = 0; + if (_str) + _str[0] = 0; +} + void String::ensureCapacity(int new_len, bool keep_old) { if (new_len <= _capacity) @@ -188,8 +195,12 @@ StringList::StringList(const StringList& list) StringList::~StringList() { - if (_data) + if (_data) { + for (int i = 0; i < _capacity; i++) + if (_data[_size]) + delete _data[_size]; free(_data); + } } @@ -217,7 +228,6 @@ void StringList::push_back(const String& str) _size++; } - String& StringList::operator [](int idx) { assert(idx >= 0 && idx < _size); @@ -230,6 +240,11 @@ const String& StringList::operator [](int idx) const return *_data[idx]; } +void String::clear() +{ + _len = 0; +} + void StringList::ensureCapacity(int new_len) { if (new_len <= _capacity) diff --git a/gui/util.h b/gui/util.h index 91cab2d262..0d2a9560d7 100644 --- a/gui/util.h +++ b/gui/util.h @@ -50,6 +50,8 @@ public: operator const char *() const { return _str; } const char *c_str() const { return _str; } int size() const { return _len; } + + void clear(); protected: void ensureCapacity(int new_len, bool keep_old); @@ -75,6 +77,8 @@ public: int size() const { return _size; } + void clear(); + protected: void ensureCapacity(int new_len); }; |