diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index 0edcd714..5d8c25de 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -88,7 +88,7 @@ namespace #endif const size_t pos = s.rfind("."); - if(pos != String::npos) + if(pos != String::npos()) ext = s.substr(pos + 1).upper(); } diff --git a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp index 13059732..d32ecc5f 100644 --- a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp +++ b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp @@ -168,7 +168,7 @@ PropertyMap TextIdentificationFrame::asProperties() const // ID3v2 specifies ISO8601 timestamps which contain a 'T' as separator between date and time. // Since this is unusual in other formats, the T is removed. const size_t tpos = it->find("T"); - if(tpos != String::npos) + if(tpos != String::npos()) (*it)[tpos] = ' '; } } diff --git a/taglib/mpeg/id3v2/id3v2framefactory.cpp b/taglib/mpeg/id3v2/id3v2framefactory.cpp index 3426f30a..44da49c1 100644 --- a/taglib/mpeg/id3v2/id3v2framefactory.cpp +++ b/taglib/mpeg/id3v2/id3v2framefactory.cpp @@ -487,7 +487,7 @@ void FrameFactory::updateGenre(TextIdentificationFrame *frame) const String s = *it; const size_t end = s.find(")"); - if(s.startsWith("(") && end != String::npos) { + if(s.startsWith("(") && end != String::npos()) { // "(12)Genre" String text = s.substr(end + 1); bool ok; diff --git a/taglib/ogg/xiphcomment.cpp b/taglib/ogg/xiphcomment.cpp index 5fb90c13..64e05ac0 100644 --- a/taglib/ogg/xiphcomment.cpp +++ b/taglib/ogg/xiphcomment.cpp @@ -376,7 +376,7 @@ void Ogg::XiphComment::parse(const ByteVector &data) } const size_t commentSeparatorPosition = comment.find("="); - if(commentSeparatorPosition == String::npos) { + if(commentSeparatorPosition == String::npos()) { break; } diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index f9aea6f2..d4bff7b9 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -139,9 +139,17 @@ public: const String String::null; -// Actual value is -1. -const size_t String::npos = std::wstring::npos; +//////////////////////////////////////////////////////////////////////////////// +// static members +//////////////////////////////////////////////////////////////////////////////// +size_t String::npos() +{ + return std::wstring::npos; +} + +//////////////////////////////////////////////////////////////////////////////// +// public members //////////////////////////////////////////////////////////////////////////////// String::String() : @@ -303,7 +311,7 @@ StringList String::split(const String &separator) const StringList list; for(size_t index = 0;;) { const size_t sep = find(separator, index); - if(sep == npos) { + if(sep == npos()) { list.append(substr(index, size() - index)); break; } diff --git a/taglib/toolkit/tstring.h b/taglib/toolkit/tstring.h index 6a8f0f69..4fe1cbea 100644 --- a/taglib/toolkit/tstring.h +++ b/taglib/toolkit/tstring.h @@ -277,7 +277,7 @@ namespace TagLib { * either from the end of the string or starting from \a offset. If the pattern * is not found, \a npos is returned. */ - size_t rfind(const String &s, size_t offset = npos) const; + size_t rfind(const String &s, size_t offset = npos()) const; /*! * Splits the string on each occurrence of \a separator. @@ -293,7 +293,7 @@ namespace TagLib { * Extract a substring from this string starting at \a position and * continuing for \a n characters. */ - String substr(size_t position, size_t n = npos) const; + String substr(size_t position, size_t n = npos()) const; /*! * Append \a s to the current string and return a reference to the current @@ -515,11 +515,11 @@ namespace TagLib { static const String null; /*! - * When used as the value for a \a length parameter in String's member + * Returns a special value used for \a length parameter in String's member * functions, means "until the end of the string". * As a return value, it is usually used to indicate no matches. */ - static const size_t npos; + static size_t npos(); protected: /*! diff --git a/taglib/toolkit/tstringlist.cpp b/taglib/toolkit/tstringlist.cpp index 19fd082f..32584730 100644 --- a/taglib/toolkit/tstringlist.cpp +++ b/taglib/toolkit/tstringlist.cpp @@ -37,7 +37,7 @@ StringList StringList::split(const String &s, const String &pattern) size_t previousOffset = 0; for(size_t offset = s.find(pattern); - offset != String::npos; + offset != String::npos(); offset = s.find(pattern, offset + 1)) { l.append(s.substr(previousOffset, offset - previousOffset)); diff --git a/tests/test_string.cpp b/tests/test_string.cpp index 29923a35..5afc32e5 100644 --- a/tests/test_string.cpp +++ b/tests/test_string.cpp @@ -218,9 +218,9 @@ public: void testRfind() { - CPPUNIT_ASSERT_EQUAL(String::npos, String("foo.bar").rfind(".", 0)); - CPPUNIT_ASSERT_EQUAL(String::npos, String("foo.bar").rfind(".", 1)); - CPPUNIT_ASSERT_EQUAL(String::npos, String("foo.bar").rfind(".", 2)); + CPPUNIT_ASSERT_EQUAL(String::npos(), String("foo.bar").rfind(".", 0)); + CPPUNIT_ASSERT_EQUAL(String::npos(), String("foo.bar").rfind(".", 1)); + CPPUNIT_ASSERT_EQUAL(String::npos(), String("foo.bar").rfind(".", 2)); CPPUNIT_ASSERT_EQUAL((size_t)3, String("foo.bar").rfind(".", 3)); CPPUNIT_ASSERT_EQUAL((size_t)3, String("foo.bar").rfind(".", 4)); CPPUNIT_ASSERT_EQUAL((size_t)3, String("foo.bar").rfind(".", 5));