From 1a942627bfd6f619262fa51944fcd429c507c6c5 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 17 Nov 2015 11:29:52 +0900 Subject: [PATCH] Add String::clear() method to clear the string. --- taglib/toolkit/tstring.cpp | 6 ++++++ taglib/toolkit/tstring.h | 5 +++++ tests/test_string.cpp | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index e21316b2..d623d237 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -358,6 +358,12 @@ String &String::append(const String &s) return *this; } +String & String::clear() +{ + *this = String(); + return *this; +} + String String::upper() const { String s; diff --git a/taglib/toolkit/tstring.h b/taglib/toolkit/tstring.h index 8b739882..68592f40 100644 --- a/taglib/toolkit/tstring.h +++ b/taglib/toolkit/tstring.h @@ -299,6 +299,11 @@ namespace TagLib { */ String &append(const String &s); + /*! + * Clears the string. + */ + String &clear(); + /*! * Returns an upper case version of the string. * diff --git a/tests/test_string.cpp b/tests/test_string.cpp index afb2aa23..24816af9 100644 --- a/tests/test_string.cpp +++ b/tests/test_string.cpp @@ -67,6 +67,10 @@ public: CPPUNIT_ASSERT(s != L"taglib"); CPPUNIT_ASSERT(s != L"taglib string taglib"); + s.clear(); + CPPUNIT_ASSERT(s.isEmpty()); + CPPUNIT_ASSERT(!s.isNull()); + String unicode("José Carlos", String::UTF8); CPPUNIT_ASSERT(strcmp(unicode.toCString(), "Jos\xe9 Carlos") == 0);