]> granicus.if.org Git - taglib/commitdiff
Make ByteVector::fromBase64 as static member function
authorSander Jansen <s.jansen@gmail.com>
Sat, 16 May 2015 19:51:10 +0000 (14:51 -0500)
committerSander Jansen <s.jansen@gmail.com>
Thu, 12 Nov 2015 14:50:34 +0000 (08:50 -0600)
taglib/ogg/xiphcomment.cpp
taglib/toolkit/tbytevector.cpp
taglib/toolkit/tbytevector.h
tests/test_bytevector.cpp

index 2783d922213d44d82ccddc1751b248d8d72dfe09..15f8cbafa5213c8cf93f0f5306d4acebe749c2cd 100644 (file)
@@ -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");
index eb559390e9b4ed34f540edc1116f15a87973f26f..f18d23295bb0e4900427f37252500390ae915c9c 100644 (file)
@@ -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;
 }
 
 
index 0f96c77f181c41b09bcfbb334ed2777650815953..4b669b9ee939d671594784d9cd3caa91b7624727 100644 (file)
@@ -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:
     /*
index 19f5151845e88631487433c3f9837a6317b55143..18097adf99e1262df07d558937bcbb7bf175376a 100644 (file)
@@ -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(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(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, 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()));
 
   }