diff --git a/taglib/asf/asfpicture.cpp b/taglib/asf/asfpicture.cpp index d25b9a4d..4c48bb09 100644 --- a/taglib/asf/asfpicture.cpp +++ b/taglib/asf/asfpicture.cpp @@ -159,13 +159,13 @@ void ASF::Picture::parse(const ByteVector& bytes) const ByteVector nullStringTerminator(2, 0); size_t endPos = bytes.find(nullStringTerminator, pos, 2); - if(endPos == ByteVector::npos) + if(endPos == ByteVector::npos()) return; d->data->mimeType = String(bytes.mid(pos, endPos - pos), String::UTF16LE); pos = endPos+2; endPos = bytes.find(nullStringTerminator, pos, 2); - if(endPos == ByteVector::npos) + if(endPos == ByteVector::npos()) return; d->data->description = String(bytes.mid(pos, endPos - pos), String::UTF16LE); pos = endPos+2; diff --git a/taglib/it/itfile.cpp b/taglib/it/itfile.cpp index 9382d64c..e7f89dc2 100644 --- a/taglib/it/itfile.cpp +++ b/taglib/it/itfile.cpp @@ -225,7 +225,7 @@ void IT::File::read(bool) ByteVector messageBytes = readBlock(messageLength); READ_ASSERT(messageBytes.size() == messageLength); const size_t index = messageBytes.find((char) 0); - if(index != ByteVector::npos) + if(index != ByteVector::npos()) messageBytes.resize(index, 0); messageBytes.replace('\r', '\n'); message = messageBytes; diff --git a/taglib/mod/modfilebase.cpp b/taglib/mod/modfilebase.cpp index a277edb7..7f2386e2 100644 --- a/taglib/mod/modfilebase.cpp +++ b/taglib/mod/modfilebase.cpp @@ -45,8 +45,7 @@ bool Mod::FileBase::readString(String &s, uint size) ByteVector data(readBlock(size)); if(data.size() < size) return false; const size_t index = data.find((char) 0); - if(index != ByteVector::npos) - { + if(index != ByteVector::npos()) { data.resize(index); } data.replace((char) 0xff, ' '); diff --git a/taglib/mpeg/id3v2/frames/urllinkframe.cpp b/taglib/mpeg/id3v2/frames/urllinkframe.cpp index 173ca34d..5bf48d5a 100644 --- a/taglib/mpeg/id3v2/frames/urllinkframe.cpp +++ b/taglib/mpeg/id3v2/frames/urllinkframe.cpp @@ -191,7 +191,7 @@ void UserUrlLinkFrame::parseFields(const ByteVector &data) if(d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8) { const size_t offset = data.find(textDelimiter(d->textEncoding), pos); - if(offset == ByteVector::npos || offset < pos) + if(offset == ByteVector::npos() || offset < pos) return; d->description = String(data.mid(pos, offset - pos), d->textEncoding); @@ -199,7 +199,7 @@ void UserUrlLinkFrame::parseFields(const ByteVector &data) } else { const size_t len = data.mid(pos).find(textDelimiter(d->textEncoding), 0, 2); - if(len == ByteVector::npos) + if(len == ByteVector::npos()) return; d->description = String(data.mid(pos, len), d->textEncoding); diff --git a/taglib/mpeg/id3v2/id3v2frame.cpp b/taglib/mpeg/id3v2/id3v2frame.cpp index b3ec3407..9b7cfb19 100644 --- a/taglib/mpeg/id3v2/id3v2frame.cpp +++ b/taglib/mpeg/id3v2/id3v2frame.cpp @@ -310,7 +310,7 @@ String Frame::readStringField(const ByteVector &data, String::Type encoding, siz ByteVector delimiter = textDelimiter(encoding); const size_t end = data.find(delimiter, position, delimiter.size()); - if(end == ByteVector::npos || end < position) + if(end == ByteVector::npos() || end < position) return String::null; String str; diff --git a/taglib/mpeg/mpegfile.cpp b/taglib/mpeg/mpegfile.cpp index 8ede1d67..785dce03 100644 --- a/taglib/mpeg/mpegfile.cpp +++ b/taglib/mpeg/mpegfile.cpp @@ -525,7 +525,7 @@ offset_t MPEG::File::findID3v2(offset_t offset) // These variables are used to keep track of a partial match that happens at // the end of a buffer. - size_t previousPartialMatch = ByteVector::npos; + size_t previousPartialMatch = ByteVector::npos(); bool previousPartialSynchMatch = false; // Save the location of the current read pointer. We will restore the @@ -560,7 +560,7 @@ offset_t MPEG::File::findID3v2(offset_t offset) if(previousPartialSynchMatch && secondSynchByte(buffer[0])) return -1; - if(previousPartialMatch != ByteVector::npos && bufferSize() > previousPartialMatch) { + if(previousPartialMatch != ByteVector::npos() && bufferSize() > previousPartialMatch) { const size_t patternOffset = (bufferSize() - previousPartialMatch); if(buffer.containsAt(ID3v2::Header::fileIdentifier(), 0, patternOffset)) { seek(originalPosition); @@ -571,7 +571,7 @@ offset_t MPEG::File::findID3v2(offset_t offset) // (2) pattern contained in current buffer const size_t location = buffer.find(ID3v2::Header::fileIdentifier()); - if(location != ByteVector::npos) { + if(location != ByteVector::npos()) { seek(originalPosition); return offset + bufferOffset + location; } @@ -582,7 +582,7 @@ offset_t MPEG::File::findID3v2(offset_t offset) // (11111111) byte, and we want to check all such instances until we find // a full match (11111111 111) or hit the end of the buffer. - while(firstSynchByte != ByteVector::npos) { + while(firstSynchByte != ByteVector::npos()) { // if this *is not* at the end of the buffer diff --git a/taglib/mpeg/xingheader.cpp b/taglib/mpeg/xingheader.cpp index 80608f18..1e3f8d56 100644 --- a/taglib/mpeg/xingheader.cpp +++ b/taglib/mpeg/xingheader.cpp @@ -90,10 +90,10 @@ void MPEG::XingHeader::parse(const ByteVector &data) // Look for a Xing header. size_t offset = data.find("Xing"); - if(offset == ByteVector::npos) + if(offset == ByteVector::npos()) offset = data.find("Info"); - if(offset != ByteVector::npos) { + if(offset != ByteVector::npos()) { // Xing header found. @@ -117,7 +117,7 @@ void MPEG::XingHeader::parse(const ByteVector &data) offset = data.find("VBRI"); - if(offset != ByteVector::npos) { + if(offset != ByteVector::npos()) { // VBRI header found. diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index c420ba83..85b86754 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -106,19 +106,19 @@ size_t findChar( { const size_t dataSize = dataEnd - dataBegin; if(offset + 1 > dataSize) - return ByteVector::npos; + return ByteVector::npos(); // n % 0 is invalid if(byteAlign == 0) - return ByteVector::npos; + return ByteVector::npos(); for(TIterator it = dataBegin + offset; it < dataEnd; it += byteAlign) { if(*it == c) return (it - dataBegin); } - return ByteVector::npos; + return ByteVector::npos(); } template @@ -130,7 +130,7 @@ size_t findVector( const size_t dataSize = dataEnd - dataBegin; const size_t patternSize = patternEnd - patternBegin; if(patternSize == 0 || offset + patternSize > dataSize) - return ByteVector::npos; + return ByteVector::npos(); // Special case that pattern contains just single char. @@ -161,7 +161,7 @@ size_t findVector( } } - return ByteVector::npos; + return ByteVector::npos(); } template @@ -327,11 +327,14 @@ public: // static members //////////////////////////////////////////////////////////////////////////////// -const size_t ByteVector::npos = static_cast(-1); +size_t ByteVector::npos() +{ + return static_cast(-1); +} ByteVector ByteVector::fromCString(const char *s, size_t length) { - if(length == npos) + if(length == npos()) return ByteVector(s); else return ByteVector(s, length); @@ -489,8 +492,8 @@ size_t ByteVector::rfind(const ByteVector &pattern, size_t offset, size_t byteAl const size_t pos = findVector( rbegin(), rend(), pattern.rbegin(), pattern.rend(), offset, byteAlign); - if(pos == npos) - return npos; + if(pos == npos()) + return npos(); else return size() - pos - pattern.size(); } @@ -532,7 +535,7 @@ ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &wit while (true) { offset = find(pattern, offset); - if(offset == npos) + if(offset == npos()) break; detach(); @@ -565,7 +568,7 @@ ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &wit size_t ByteVector::endsWithPartialMatch(const ByteVector &pattern) const { if(pattern.size() > size()) - return npos; + return npos(); const size_t startIndex = size() - pattern.size(); @@ -577,7 +580,7 @@ size_t ByteVector::endsWithPartialMatch(const ByteVector &pattern) const return startIndex + i; } - return npos; + return npos(); } ByteVector &ByteVector::append(const ByteVector &v) diff --git a/taglib/toolkit/tbytevector.h b/taglib/toolkit/tbytevector.h index 0427b3fd..ba977743 100644 --- a/taglib/toolkit/tbytevector.h +++ b/taglib/toolkit/tbytevector.h @@ -126,7 +126,7 @@ namespace TagLib { * for \a length bytes. If \a length is not specified it will return the bytes * from \a index to the end of the vector. */ - ByteVector mid(size_t index, size_t length = npos) const; + ByteVector mid(size_t index, size_t length = npos()) const; /*! * This essentially performs the same as operator[](), but instead of causing @@ -136,7 +136,7 @@ namespace TagLib { /*! * Searches the ByteVector for \a pattern starting at \a offset and returns - * the offset. Returns \a npos if the pattern was not found. If \a byteAlign is + * the offset. Returns npos() if the pattern was not found. If \a byteAlign is * specified the pattern will only be matched if it starts on a byte divisible * by \a byteAlign (starting from \a offset). */ @@ -152,7 +152,7 @@ namespace TagLib { /*! * Searches the ByteVector for \a pattern starting from either the end of the - * vector or \a offset and returns the offset. Returns \ npos if the pattern was + * vector or \a offset and returns the offset. Returns npos() if the pattern was * not found. If \a byteAlign is specified the pattern will only be matched * if it starts on a byte divisible by \a byteAlign (starting from \a offset). */ @@ -166,7 +166,7 @@ namespace TagLib { * the \a patternLength argument. */ bool containsAt( - const ByteVector &pattern, size_t offset, size_t patternOffset = 0, size_t patternLength = npos) const; + const ByteVector &pattern, size_t offset, size_t patternOffset = 0, size_t patternLength = npos()) const; /*! * Returns true if the vector starts with \a pattern. @@ -186,7 +186,7 @@ namespace TagLib { /*! * Checks for a partial match of \a pattern at the end of the vector. It - * returns the offset of the partial match within the vector, or \a npos if the + * returns the offset of the partial match within the vector, or npos() if the * pattern is not found. This method is particularly useful when searching for * patterns that start in one vector and end in another. When combined with * startsWith() it can be used to find a pattern that overlaps two buffers. @@ -267,7 +267,6 @@ namespace TagLib { * Returns true if the ByteVector is empty. * * \see size() - * \see isNull() */ bool isEmpty() const; @@ -482,7 +481,7 @@ namespace TagLib { /*! * Returns a ByteVector based on the CString \a s. */ - static ByteVector fromCString(const char *s, size_t length = npos); + static ByteVector fromCString(const char *s, size_t length = npos()); /*! * Returns a const reference to the byte at \a index. @@ -556,11 +555,11 @@ namespace TagLib { void swap(ByteVector &v); /*! - * When used as the value for a \a length or \a patternLength parameter - * in ByteVector's member functions, means "until the end of the data". - * As a return value, it is usually used to indicate no matches. - */ - static const size_t npos; + * Returns a special value used for \a length or \a patternLength parameters + * of ByteVector's member functions, means "until the end of the data". + * As a return value, it is usually used to indicate no matches. + */ + static size_t npos(); /*! * Returns a hex-encoded copy of the byte vector. diff --git a/taglib/toolkit/tbytevectorlist.cpp b/taglib/toolkit/tbytevectorlist.cpp index 5aa47576..93de1edd 100644 --- a/taglib/toolkit/tbytevectorlist.cpp +++ b/taglib/toolkit/tbytevectorlist.cpp @@ -38,7 +38,7 @@ ByteVectorList ByteVectorList::split( size_t previousOffset = 0; for(size_t offset = v.find(pattern, 0, byteAlign); - offset != ByteVector::npos && (max == 0 || max > l.size() + 1); + offset != ByteVector::npos() && (max == 0 || max > l.size() + 1); offset = v.find(pattern, offset + pattern.size(), byteAlign)) { if(offset - previousOffset >= 1) diff --git a/taglib/toolkit/tfile.cpp b/taglib/toolkit/tfile.cpp index 858bbc2e..1096fb84 100644 --- a/taglib/toolkit/tfile.cpp +++ b/taglib/toolkit/tfile.cpp @@ -131,8 +131,8 @@ offset_t File::find(const ByteVector &pattern, offset_t fromOffset, const ByteVe // These variables are used to keep track of a partial match that happens at // the end of a buffer. - size_t previousPartialMatch = ByteVector::npos; - size_t beforePreviousPartialMatch = ByteVector::npos; + size_t previousPartialMatch = ByteVector::npos(); + size_t beforePreviousPartialMatch = ByteVector::npos(); // Save the location of the current read pointer. We will restore the // position using seek() before all returns. @@ -169,7 +169,7 @@ offset_t File::find(const ByteVector &pattern, offset_t fromOffset, const ByteVe // (1) previous partial match - if(previousPartialMatch != ByteVector::npos + if(previousPartialMatch != ByteVector::npos() && bufferSize() > previousPartialMatch) { const size_t patternOffset = (bufferSize() - previousPartialMatch); @@ -180,7 +180,7 @@ offset_t File::find(const ByteVector &pattern, offset_t fromOffset, const ByteVe } if(!before.isEmpty() - && beforePreviousPartialMatch != ByteVector::npos + && beforePreviousPartialMatch != ByteVector::npos() && bufferSize() > beforePreviousPartialMatch) { const size_t beforeOffset = (bufferSize() - beforePreviousPartialMatch); @@ -193,12 +193,12 @@ offset_t File::find(const ByteVector &pattern, offset_t fromOffset, const ByteVe // (2) pattern contained in current buffer size_t location = buffer.find(pattern); - if(location != ByteVector::npos) { + if(location != ByteVector::npos()) { seek(originalPosition); return bufferOffset + location; } - if(!before.isEmpty() && buffer.find(before) != ByteVector::npos) { + if(!before.isEmpty() && buffer.find(before) != ByteVector::npos()) { seek(originalPosition); return -1; } @@ -263,12 +263,12 @@ offset_t File::rfind(const ByteVector &pattern, offset_t fromOffset, const ByteV // (2) pattern contained in current buffer const size_t location = buffer.rfind(pattern); - if(location != ByteVector::npos) { + if(location != ByteVector::npos()) { seek(originalPosition); return bufferOffset + location; } - if(!before.isEmpty() && buffer.find(before) != ByteVector::npos) { + if(!before.isEmpty() && buffer.find(before) != ByteVector::npos()) { seek(originalPosition); return -1; } diff --git a/taglib/xm/xmfile.cpp b/taglib/xm/xmfile.cpp index 7888f872..9cff50d5 100644 --- a/taglib/xm/xmfile.cpp +++ b/taglib/xm/xmfile.cpp @@ -132,7 +132,7 @@ namespace ByteVector data = file.readBlock(std::min(m_size, limit)); size_t count = data.size(); const size_t index = data.find((char) 0); - if(index != ByteVector::npos) { + if(index != ByteVector::npos()) { data.resize(index); } data.replace((char) 0xff, ' '); diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp index 1140082a..6cdfca27 100644 --- a/tests/test_bytevector.cpp +++ b/tests/test_bytevector.cpp @@ -95,24 +95,24 @@ public: CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find("SggO", 2)); CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find("SggO", 3)); CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find("SggO", 4)); - CPPUNIT_ASSERT_EQUAL(ByteVector::npos, ByteVector("....SggO."). find("SggO", 5)); - CPPUNIT_ASSERT_EQUAL(ByteVector::npos, ByteVector("....SggO."). find("SggO", 6)); - CPPUNIT_ASSERT_EQUAL(ByteVector::npos, ByteVector("....SggO."). find("SggO", 7)); - CPPUNIT_ASSERT_EQUAL(ByteVector::npos, ByteVector("....SggO."). find("SggO", 8)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), ByteVector("....SggO."). find("SggO", 5)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), ByteVector("....SggO."). find("SggO", 6)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), ByteVector("....SggO."). find("SggO", 7)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), ByteVector("....SggO."). find("SggO", 8)); // Intentional out-of-bounds access. ByteVector v("0123456789x"); v.resize(10); v.data()[10] = 'x'; - CPPUNIT_ASSERT_EQUAL(ByteVector::npos, v.find("789x", 7)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), v.find("789x", 7)); } void testFind2() { CPPUNIT_ASSERT_EQUAL((size_t)0, ByteVector("\x01", 1).find("\x01")); CPPUNIT_ASSERT_EQUAL((size_t)0, ByteVector("\x01\x02", 2).find("\x01\x02")); - CPPUNIT_ASSERT_EQUAL(ByteVector::npos, ByteVector("\x01", 1).find("\x02")); - CPPUNIT_ASSERT_EQUAL(ByteVector::npos, ByteVector("\x01\x02", 2).find("\x01\x03")); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), ByteVector("\x01", 1).find("\x02")); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), ByteVector("\x01\x02", 2).find("\x01\x03")); } void testRfind1() @@ -137,8 +137,8 @@ public: ByteVector r3("OggS******OggS"); ByteVector r4("OggS*OggS*OggS"); - CPPUNIT_ASSERT_EQUAL(ByteVector::npos, r0.find("OggS")); - CPPUNIT_ASSERT_EQUAL(ByteVector::npos, r0.rfind("OggS")); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), r0.find("OggS")); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), r0.rfind("OggS")); CPPUNIT_ASSERT_EQUAL((size_t)0, r1.find("OggS")); CPPUNIT_ASSERT_EQUAL((size_t)0, r1.rfind("OggS")); CPPUNIT_ASSERT_EQUAL((size_t)10, r2.find("OggS")); @@ -343,7 +343,7 @@ public: CPPUNIT_ASSERT_EQUAL('B', b[9]); b.resize(3, 'C'); CPPUNIT_ASSERT_EQUAL(size_t(3), b.size()); - CPPUNIT_ASSERT_EQUAL(ByteVector::npos, b.find('C')); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), b.find('C')); b.resize(3); CPPUNIT_ASSERT_EQUAL(size_t(3), b.size()); @@ -368,7 +368,7 @@ public: CPPUNIT_ASSERT_EQUAL('B', c[9]); c.resize(3, 'C'); CPPUNIT_ASSERT_EQUAL(size_t(3), c.size()); - CPPUNIT_ASSERT_EQUAL(ByteVector::npos, c.find('C')); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos(), c.find('C')); } void testAppend()