changeset 86:de8a5329b069

fix of base64
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 26 Sep 2012 11:21:05 +0200
parents ebce15865cce
children 8517e2c44283
files Core/Toolbox.cpp Resources/base64/base64.cpp Resources/base64/base64.h
diffstat 3 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Toolbox.cpp	Wed Sep 26 09:26:50 2012 +0200
+++ b/Core/Toolbox.cpp	Wed Sep 26 11:21:05 2012 +0200
@@ -343,7 +343,7 @@
 
   std::string Toolbox::EncodeBase64(const std::string& data)
   {
-    return base64_encode(data.c_str());
+    return base64_encode(data);
   }
 
 }
--- a/Resources/base64/base64.cpp	Wed Sep 26 09:26:50 2012 +0200
+++ b/Resources/base64/base64.cpp	Wed Sep 26 11:21:05 2012 +0200
@@ -38,9 +38,11 @@
   return (isalnum(c) || (c == '+') || (c == '/'));
 }
 
-std::string base64_encode(const char* stringToEncode) {
-  unsigned char const* bytes_to_encode = reinterpret_cast<unsigned char const*>(stringToEncode);
-  unsigned int in_len = strlen(stringToEncode);
+std::string base64_encode(const std::string& stringToEncode) 
+{
+  const unsigned char* bytes_to_encode = reinterpret_cast<const unsigned char*>
+    (stringToEncode.size() > 0 ? &stringToEncode[0] : NULL);
+  unsigned int in_len = stringToEncode.size();
   
   std::string ret;
   int i = 0;
@@ -81,8 +83,8 @@
   }
 
   return ret;
+}
 
-}
 
 std::string base64_decode(const std::string& encoded_string) {
   int in_len = encoded_string.size();
--- a/Resources/base64/base64.h	Wed Sep 26 09:26:50 2012 +0200
+++ b/Resources/base64/base64.h	Wed Sep 26 11:21:05 2012 +0200
@@ -1,4 +1,4 @@
 #include <string>
 
-std::string base64_encode(const char* stringToEncode);
+std::string base64_encode(const std::string& stringToEncode);
 std::string base64_decode(const std::string& s);