mirror of
https://github.com/taglib/taglib.git
synced 2025-06-04 01:28:21 -04:00
Make ByteVector::fromBase64 as static member function
This commit is contained in:
parent
d3351a0012
commit
62bb3c95c8
@ -419,7 +419,7 @@ void Ogg::XiphComment::parse(const ByteVector &data)
|
||||
if(entry.startsWith("METADATA_BLOCK_PICTURE=")) {
|
||||
|
||||
// Decode base64 picture data
|
||||
ByteVector picturedata = entry.mid(23, entry.size()-23).fromBase64();
|
||||
ByteVector picturedata = ByteVector::fromBase64(entry.mid(23));
|
||||
|
||||
if(picturedata.size()==0) {
|
||||
debug("Empty picture data. Discarding content");
|
||||
|
@ -954,7 +954,7 @@ ByteVector ByteVector::toHex() const
|
||||
|
||||
|
||||
|
||||
ByteVector & ByteVector::fromBase64()
|
||||
ByteVector ByteVector::fromBase64(const ByteVector & input)
|
||||
{
|
||||
static const unsigned char base64[256]={
|
||||
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
|
||||
@ -975,10 +975,12 @@ ByteVector & ByteVector::fromBase64()
|
||||
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80
|
||||
};
|
||||
|
||||
detach();
|
||||
uint len = size();
|
||||
const unsigned char * src = (unsigned char*) data();
|
||||
unsigned char * dst = (unsigned char*) data();
|
||||
uint len = input.size();
|
||||
|
||||
ByteVector output(len);
|
||||
|
||||
const unsigned char * src = (unsigned char*) input.data();
|
||||
unsigned char * dst = (unsigned char*)output.data();
|
||||
while(4<=len) {
|
||||
if(base64[src[0]]==0x80) break;
|
||||
if(base64[src[1]]==0x80) break;
|
||||
@ -1000,8 +1002,8 @@ ByteVector & ByteVector::fromBase64()
|
||||
src+=4;
|
||||
len-=4;
|
||||
}
|
||||
resize(dst-(unsigned char*)data());
|
||||
return *this;
|
||||
output.resize(dst-(unsigned char*)output.data());
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
|
@ -579,12 +579,9 @@ namespace TagLib {
|
||||
ByteVector toBase64() const;
|
||||
|
||||
/*!
|
||||
* Decodes the base64 encoded byte vector in-memory. Returns a reference
|
||||
* to this vector. Calls detach before decoding.
|
||||
* Decodes the base64 encoded byte vector.
|
||||
*/
|
||||
ByteVector & fromBase64();
|
||||
|
||||
|
||||
static ByteVector fromBase64(const ByteVector &);
|
||||
|
||||
protected:
|
||||
/*
|
||||
|
@ -406,15 +406,15 @@ public:
|
||||
|
||||
// Decode
|
||||
CPPUNIT_ASSERT_EQUAL(sempty, eempty.toBase64());
|
||||
CPPUNIT_ASSERT_EQUAL(s0, e0.fromBase64());
|
||||
CPPUNIT_ASSERT_EQUAL(s1, e1.fromBase64());
|
||||
CPPUNIT_ASSERT_EQUAL(s2, e2.fromBase64());
|
||||
CPPUNIT_ASSERT_EQUAL(s3, e3.fromBase64());
|
||||
CPPUNIT_ASSERT_EQUAL(s0, ByteVector::fromBase64(e0));
|
||||
CPPUNIT_ASSERT_EQUAL(s1, ByteVector::fromBase64(e1));
|
||||
CPPUNIT_ASSERT_EQUAL(s2, ByteVector::fromBase64(e2));
|
||||
CPPUNIT_ASSERT_EQUAL(s3, ByteVector::fromBase64(e3));
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(t0, s0.toBase64().fromBase64());
|
||||
CPPUNIT_ASSERT_EQUAL(t1, s1.toBase64().fromBase64());
|
||||
CPPUNIT_ASSERT_EQUAL(t2, s2.toBase64().fromBase64());
|
||||
CPPUNIT_ASSERT_EQUAL(t3, s3.toBase64().fromBase64());
|
||||
CPPUNIT_ASSERT_EQUAL(t0, ByteVector::fromBase64(s0.toBase64()));
|
||||
CPPUNIT_ASSERT_EQUAL(t1, ByteVector::fromBase64(s1.toBase64()));
|
||||
CPPUNIT_ASSERT_EQUAL(t2, ByteVector::fromBase64(s2.toBase64()));
|
||||
CPPUNIT_ASSERT_EQUAL(t3, ByteVector::fromBase64(s3.toBase64()));
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user