Avoid using ByteVector::null where an empty vector is required.

ByteVector::null is not necessarily be empty or remains the same instance.
Using it in a public header may lead to a linkage error.
This commit is contained in:
Tsuda Kageyu 2015-11-19 10:52:46 +09:00
parent 21788f4a26
commit 539d951277
16 changed files with 32 additions and 31 deletions

View File

@ -196,7 +196,7 @@ void ASF::File::FilePrivate::BaseObject::parse(ASF::File *file, unsigned int siz
if(size > 24 && size <= (unsigned int)(file->length()))
data = file->readBlock(size - 24);
else
data = ByteVector::null;
data = ByteVector();
}
ByteVector ASF::File::FilePrivate::BaseObject::render(ASF::File * /*file*/)
@ -312,7 +312,7 @@ ByteVector ASF::File::FilePrivate::ExtendedContentDescriptionObject::render(ASF:
{
data.clear();
data.append(ByteVector::fromShort(attributeData.size(), false));
data.append(attributeData.toByteVector(ByteVector::null));
data.append(attributeData.toByteVector(""));
return BaseObject::render(file);
}
@ -336,7 +336,7 @@ ByteVector ASF::File::FilePrivate::MetadataObject::render(ASF::File *file)
{
data.clear();
data.append(ByteVector::fromShort(attributeData.size(), false));
data.append(attributeData.toByteVector(ByteVector::null));
data.append(attributeData.toByteVector(""));
return BaseObject::render(file);
}
@ -360,7 +360,7 @@ ByteVector ASF::File::FilePrivate::MetadataLibraryObject::render(ASF::File *file
{
data.clear();
data.append(ByteVector::fromShort(attributeData.size(), false));
data.append(attributeData.toByteVector(ByteVector::null));
data.append(attributeData.toByteVector(""));
return BaseObject::render(file);
}

View File

@ -132,7 +132,8 @@ ASF::Picture& ASF::Picture::operator=(const ASF::Picture& other)
ByteVector ASF::Picture::render() const
{
if(!isValid())
return ByteVector::null;
return ByteVector();
return
ByteVector((char)d->type) +
ByteVector::fromUInt(d->picture.size(), false) +

View File

@ -428,7 +428,7 @@ MP4::Tag::renderFreeForm(const String &name, const MP4::Item &item) const
StringList header = StringList::split(name, ":");
if(header.size() != 3) {
debug("MP4: Invalid free-form item name \"" + name + "\"");
return ByteVector::null;
return ByteVector();
}
ByteVector data;
data.append(renderAtom("mean", ByteVector::fromUInt(0) + header[1].data(String::UTF8)));

View File

@ -170,7 +170,7 @@ ByteVector Frame::frameID() const
if(d->header)
return d->header->frameID();
else
return ByteVector::null;
return ByteVector();
}
TagLib::uint Frame::size() const

View File

@ -92,7 +92,7 @@ ByteVector Ogg::File::packet(uint i)
while(d->packetToPageMap.size() <= i) {
if(!nextPage()) {
debug("Ogg::File::packet() -- Could not find the requested packet.");
return ByteVector::null;
return ByteVector();
}
}
@ -125,7 +125,7 @@ ByteVector Ogg::File::packet(uint i)
if(pageIndex == d->pages.size()) {
if(!nextPage()) {
debug("Ogg::File::packet() -- Could not find the requested packet.");
return ByteVector::null;
return ByteVector();
}
}
d->currentPacketPage = d->pages[pageIndex];

View File

@ -117,7 +117,7 @@ TagLib::uint RIFF::File::chunkPadding(uint i) const
ByteVector RIFF::File::chunkName(uint i) const
{
if(i >= chunkCount())
return ByteVector::null;
return ByteVector();
return d->chunks[i].name;
}
@ -125,7 +125,7 @@ ByteVector RIFF::File::chunkName(uint i) const
ByteVector RIFF::File::chunkData(uint i)
{
if(i >= chunkCount())
return ByteVector::null;
return ByteVector();
seek(d->chunks[i].offset);
return readBlock(d->chunks[i].size);

View File

@ -55,7 +55,7 @@ ByteVectorList ByteVectorList::split(const ByteVector &v, const ByteVector &patt
if(offset - previousOffset >= 1)
l.append(v.mid(previousOffset, offset - previousOffset));
else
l.append(ByteVector::null);
l.append(ByteVector());
previousOffset = offset + pattern.size();
}

View File

@ -71,7 +71,7 @@ FileName ByteVectorStream::name() const
ByteVector ByteVectorStream::readBlock(ulong length)
{
if(length == 0)
return ByteVector::null;
return ByteVector();
ByteVector v = d->data.mid(d->position, length);
d->position += v.size();

View File

@ -289,7 +289,7 @@ long File::find(const ByteVector &pattern, long fromOffset, const ByteVector &be
}
}
if(!before.isNull() && beforePreviousPartialMatch >= 0 && int(bufferSize()) > beforePreviousPartialMatch) {
if(!before.isEmpty() && beforePreviousPartialMatch >= 0 && int(bufferSize()) > beforePreviousPartialMatch) {
const int beforeOffset = (bufferSize() - beforePreviousPartialMatch);
if(buffer.containsAt(before, 0, beforeOffset)) {
seek(originalPosition);
@ -305,7 +305,7 @@ long File::find(const ByteVector &pattern, long fromOffset, const ByteVector &be
return bufferOffset + location;
}
if(!before.isNull() && buffer.find(before) >= 0) {
if(!before.isEmpty() && buffer.find(before) >= 0) {
seek(originalPosition);
return -1;
}
@ -314,7 +314,7 @@ long File::find(const ByteVector &pattern, long fromOffset, const ByteVector &be
previousPartialMatch = buffer.endsWithPartialMatch(pattern);
if(!before.isNull())
if(!before.isEmpty())
beforePreviousPartialMatch = buffer.endsWithPartialMatch(before);
bufferOffset += bufferSize();
@ -387,7 +387,7 @@ long File::rfind(const ByteVector &pattern, long fromOffset, const ByteVector &b
return bufferOffset + location;
}
if(!before.isNull() && buffer.find(before) >= 0) {
if(!before.isEmpty() && buffer.find(before) >= 0) {
seek(originalPosition);
return -1;
}

View File

@ -165,7 +165,7 @@ namespace TagLib {
*/
long find(const ByteVector &pattern,
long fromOffset = 0,
const ByteVector &before = ByteVector::null);
const ByteVector &before = ByteVector());
/*!
* Returns the offset in the file that \a pattern occurs at or -1 if it can
@ -181,7 +181,7 @@ namespace TagLib {
*/
long rfind(const ByteVector &pattern,
long fromOffset = 0,
const ByteVector &before = ByteVector::null);
const ByteVector &before = ByteVector());
/*!
* Insert \a data at position \a start in the file overwriting \a replace

View File

@ -176,11 +176,11 @@ ByteVector FileStream::readBlock(ulong length)
{
if(!isOpen()) {
debug("FileStream::readBlock() -- invalid file.");
return ByteVector::null;
return ByteVector();
}
if(length == 0)
return ByteVector::null;
return ByteVector();
const ulong streamLength = static_cast<ulong>(FileStream::length());
if(length > bufferSize() && length > streamLength)

View File

@ -426,7 +426,7 @@ ByteVector String::data(Type t) const
return v;
}
else {
return ByteVector::null;
return ByteVector();
}
case UTF16:
{
@ -472,7 +472,7 @@ ByteVector String::data(Type t) const
default:
{
debug("String::data() - Invalid Type value.");
return ByteVector::null;
return ByteVector();
}
}
}

View File

@ -98,22 +98,22 @@ public:
CPPUNIT_ASSERT(unsuccessful.contains("A"));
CPPUNIT_ASSERT(unsuccessful.contains("MP+"));
}
void testTextBinary()
{
APE::Item item = APE::Item("DUMMY", "Test Text");
CPPUNIT_ASSERT_EQUAL(String("Test Text"), item.toString());
CPPUNIT_ASSERT_EQUAL(ByteVector::null, item.binaryData());
CPPUNIT_ASSERT_EQUAL(ByteVector(), item.binaryData());
ByteVector data("Test Data");
item.setBinaryData(data);
CPPUNIT_ASSERT(item.values().isEmpty());
CPPUNIT_ASSERT_EQUAL(String::null, item.toString());
CPPUNIT_ASSERT_EQUAL(data, item.binaryData());
item.setValue("Test Text 2");
CPPUNIT_ASSERT_EQUAL(String("Test Text 2"), item.toString());
CPPUNIT_ASSERT_EQUAL(ByteVector::null, item.binaryData());
CPPUNIT_ASSERT_EQUAL(ByteVector(), item.binaryData());
}
};

View File

@ -128,7 +128,7 @@ public:
i.clear();
CPPUNIT_ASSERT(i.isEmpty());
CPPUNIT_ASSERT(!i.isNull());
CPPUNIT_ASSERT(!i.isNull()); // deprecated, but worth it to check.
}
void testFind1()

View File

@ -56,7 +56,7 @@ public:
CPPUNIT_ASSERT_EQUAL(ByteVector("a"), stream.readBlock(1));
CPPUNIT_ASSERT_EQUAL(ByteVector("bc"), stream.readBlock(2));
CPPUNIT_ASSERT_EQUAL(ByteVector("d"), stream.readBlock(3));
CPPUNIT_ASSERT_EQUAL(ByteVector::null, stream.readBlock(3));
CPPUNIT_ASSERT_EQUAL(ByteVector(""), stream.readBlock(3));
}
void testRemoveBlock()

View File

@ -38,7 +38,7 @@ class PublicFrame : public ID3v2::Frame
{ return ID3v2::Frame::readStringField(data, encoding, positon); }
virtual String toString() const { return String::null; }
virtual void parseFields(const ByteVector &) {}
virtual ByteVector renderFields() const { return ByteVector::null; }
virtual ByteVector renderFields() const { return ByteVector(); }
};
class TestID3v2 : public CppUnit::TestFixture