[Libreoffice-commits] libvisio.git: configure.ac src/lib

Fridrich Å trba fridrich.strba at bluewin.ch
Tue Jun 25 00:38:00 PDT 2013


 configure.ac               |    7 +++++
 src/lib/libvisio_utils.cpp |   54 ++++++++-------------------------------------
 2 files changed, 16 insertions(+), 45 deletions(-)

New commits:
commit b7b4e9cad38aaeb1fb5f27d1bdb6875f9c2661bc
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Tue Jun 25 09:37:35 2013 +0200

    Use boost for base64 decoding

diff --git a/configure.ac b/configure.ac
index 4cf1ac2..50de8ab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -108,7 +108,12 @@ AC_SUBST(ZLIB_LIBS)
 # ===========================
 
 AC_CHECK_HEADERS(
-	boost/algorithm/string.hpp boost/optional.hpp boost/spirit/include/classic.hpp,
+	boost/algorithm/string.hpp \
+	boost/optional.hpp \
+	boost/spirit/include/classic.hpp \
+	boost/archive/iterators/binary_from_base64.hpp \
+	boost/archive/iterators/remove_whitespace.hpp \
+	boost/archive/iterators/transform_width.hpp,
 	[],
 	[AC_MSG_ERROR(Required boost headers not found. install boost >= 1.36)],
 	[]
diff --git a/src/lib/libvisio_utils.cpp b/src/lib/libvisio_utils.cpp
index 48ae1e7..42e2adc 100644
--- a/src/lib/libvisio_utils.cpp
+++ b/src/lib/libvisio_utils.cpp
@@ -32,7 +32,9 @@
 #include "VSDInternalStream.h"
 #include "libvisio_utils.h"
 
-#define VSD_NUM_ELEMENTS(array) sizeof(array)/sizeof(array[0])
+#include <boost/archive/iterators/binary_from_base64.hpp>
+#include <boost/archive/iterators/remove_whitespace.hpp>
+#include <boost/archive/iterators/transform_width.hpp>
 
 uint8_t libvisio::readU8(WPXInputStream *input)
 {
@@ -123,51 +125,15 @@ double libvisio::readDouble(WPXInputStream *input)
 
 void libvisio::appendFromBase64(WPXBinaryData &data, const unsigned char *base64String, size_t base64StringLength)
 {
-  static const std::string base64Chars =
-    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-    "abcdefghijklmnopqrstuvwxyz"
-    "0123456789+/";
+  typedef boost::archive::iterators::transform_width<
+  boost::archive::iterators::binary_from_base64<
+  boost::archive::iterators::remove_whitespace< const char * > >, 8, 6 > base64_decoder;
 
+  std::vector<unsigned char> buffer;
+  std::copy(base64_decoder(base64String), base64_decoder(base64String + base64StringLength), std::back_inserter(buffer));
 
-  VSDInternalStream tmpStream(base64String, base64StringLength);
-
-  unsigned i = 0;
-  char tmpCharsToDecode[4];
-  while (!tmpStream.atEOS())
-  {
-    const char tmpChar = (char)readU8(&tmpStream);
-    if (std::string::npos == base64Chars.find(tmpChar) && (tmpChar != '='))
-      continue;
-    if (tmpChar == '=')
-      break;
-    tmpCharsToDecode[i++] = tmpChar;
-    i %= 4;
-    if (!i)
-    {
-      for (unsigned k = 0; k < 4; k++)
-        tmpCharsToDecode[k] = base64Chars.find(tmpCharsToDecode[k]);
-
-      data.append((unsigned char)((tmpCharsToDecode[0] << 2) | ((tmpCharsToDecode[1] & 0x30) >> 4)));
-      data.append((unsigned char)(((tmpCharsToDecode[1] & 0xf) << 4) | ((tmpCharsToDecode[2] & 0x3c) >> 2)));
-      data.append((unsigned char)(((tmpCharsToDecode[2] & 0x3) << 6) | tmpCharsToDecode[3]));
-    }
-  }
-
-  if (i)
-  {
-    for (unsigned j = i; j < 4; j++)
-      tmpCharsToDecode[j] = 0;
-    for (unsigned k = 0; k < 4; k++)
-      tmpCharsToDecode[k] = base64Chars.find(tmpCharsToDecode[k]);
-
-    data.append((unsigned char)((tmpCharsToDecode[0] << 2) | ((tmpCharsToDecode[1] & 0x30) >> 4)));
-    if (i > 1)
-    {
-      data.append((unsigned char)(((tmpCharsToDecode[1] & 0xf) << 4) | ((tmpCharsToDecode[2] & 0x3c) >> 2)));
-      if (i > 2)
-        data.append((unsigned char)(((tmpCharsToDecode[2] & 0x3) << 6) | tmpCharsToDecode[3]));
-    }
-  }
+  if (!buffer.empty())
+    data.append(&buffer[0], buffer.size());
 }
 
 const ::WPXString libvisio::getColourString(const Colour &c)


More information about the Libreoffice-commits mailing list