}
d->footer.setItemCount(itemCount);
- d->footer.setTagSize(data.size()+Footer::size());
+ d->footer.setTagSize(data.size() + Footer::size());
d->footer.setHeaderPresent(true);
return d->footer.renderHeader() + data + d->footer.renderFooter();
if(d->hasAPE)
insert(APETag()->render(), d->APELocation, d->APEOriginalSize);
else {
- if(d->hasID3v1) {
+ if(d->hasID3v1) {
+ debug("inserting ape tag before id3v1 tag");
insert(APETag()->render(), d->ID3v1Location, 0);
d->APEOriginalSize = APETag()->footer()->completeTagSize();
d->hasAPE = true;
long MPEG::File::findAPE()
{
if(isValid()) {
- if (d->hasID3v1)
- seek(-160, End);
- else
- seek(-32, End);
-
+ seek(d->hasID3v1 ? -160 : -32, End);
long p = tell();
- if(readBlock(8) == APE::Tag::fileIdentifier())
+ if(readBlock(8) == APE::Tag::fileIdentifier()) {
+ debug("found ape at " + String::number(int(p)));
return p;
+ }
}
return -1;
}
};
/*!
- * A templatized find that works both with a ByteVector and a ByteVectorMirror.
+ * A templatized KMP find that works both with a ByteVector and a ByteVectorMirror.
*/
template <class Vector>
{
public:
ByteVectorMirror(const ByteVector &source) : v(source) {}
+
const char operator[](int index) const
{
return v[v.size() - index - 1];
{
ByteVectorMirror v(*this);
+ if(offset > 0) {
+ offset = size() - offset - pattern.size();
+ if(offset >= size())
+ offset = 0;
+ }
+
const int pos = vectorFind<ByteVectorMirror>(v, pattern, offset, byteAlign);
// If the offset is zero then we need to adjust the location in the search
if(pos == -1)
return -1;
- if(offset == 0)
- return size() - pos - pattern.size();
- else
- return pos - offset;
+ return size() - pos - pattern.size();
}
private:
- const ByteVector v;
+ const ByteVector &v;
};
template <class T>
void testRfind1()
{
- CPPUNIT_ASSERT_EQUAL(-1, ByteVector(".OggS....").rfind("OggS", 0));
+ CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 0));
CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 1));
CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 2));
CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 3));
CPPUNIT_ASSERT_EQUAL(0, r3.find("OggS"));
CPPUNIT_ASSERT_EQUAL(10, r3.rfind("OggS"));
CPPUNIT_ASSERT_EQUAL(10, r4.rfind("OggS"));
- CPPUNIT_ASSERT_EQUAL(0, r4.rfind("OggS", 0));
+ CPPUNIT_ASSERT_EQUAL(10, r4.rfind("OggS", 0));
CPPUNIT_ASSERT_EQUAL(5, r4.rfind("OggS", 7));
CPPUNIT_ASSERT_EQUAL(10, r4.rfind("OggS", 12));
}