Don't require users to include a padding byte explicitly

This makes it where the natural construction can be used of something
like:

new ChapterFrame("ID", ... )

Closes #514
This commit is contained in:
Scott Wheeler 2015-05-18 16:41:30 +02:00
parent a9e064c58e
commit fc24b3d22b
2 changed files with 25 additions and 4 deletions

View File

@ -71,7 +71,12 @@ ChapterFrame::ChapterFrame(const ByteVector &elementID,
ID3v2::Frame("CHAP")
{
d = new ChapterFramePrivate;
d->elementID = elementID;
// setElementID has a workaround for a previously silly API where you had to
// specifically include the null byte.
setElementID(elementID);
d->startTime = startTime;
d->endTime = endTime;
d->startOffset = startOffset;
@ -115,8 +120,9 @@ TagLib::uint ChapterFrame::endOffset() const
void ChapterFrame::setElementID(const ByteVector &eID)
{
d->elementID = eID;
if(eID.at(eID.size() - 1) != char(0))
d->elementID.append(char(0));
if(d->elementID.endsWith(char(0)))
d->elementID = d->elementID.mid(0, d->elementID.size() - 1);
}
void ChapterFrame::setStartTime(const TagLib::uint &sT)
@ -256,6 +262,7 @@ ByteVector ChapterFrame::renderFields() const
ByteVector data;
data.append(d->elementID);
data.append('\0');
data.append(ByteVector::fromUInt(d->startTime, true));
data.append(ByteVector::fromUInt(d->endTime, true));
data.append(ByteVector::fromUInt(d->startOffset, true));

View File

@ -965,7 +965,21 @@ public:
ID3v2::ChapterFrame f3(ByteVector("C\x00", 2), 3, 5, 2, 3, frames);
CPPUNIT_ASSERT_EQUAL(expected, f3.render());
}
frames.clear();
eF = new ID3v2::TextIdentificationFrame("TIT2");
eF->setText("CH1");
frames.append(eF);
ID3v2::ChapterFrame f4("C", 3, 5, 2, 3, frames);
CPPUNIT_ASSERT_EQUAL(expected, f4.render());
ID3v2::ChapterFrame f5("C", 3, 5, 2, 3);
eF = new ID3v2::TextIdentificationFrame("TIT2");
eF->setText("CH1");
f5.addEmbeddedFrame(eF);
CPPUNIT_ASSERT_EQUAL(expected, f5.render());
}
void testParseTableOfContentsFrame()
{