Loading drivers/base64test.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -42,9 +42,9 @@ int main() const PsimagLite::String s = "ADP GmbH\nAnalyse Design & Programmierung" "\nGesellschaft mit beschränkter Haftung" ; PsimagLite::PsiBase64 base64; PsimagLite::String encoded = base64.encode(s); PsimagLite::PsiBase64::Encode base64encode(s); PsimagLite::String encoded = base64encode(); std::cout<<"encoded: "<<encoded<<"\n"; std::cout<<"decoded: "<<base64.decode(encoded)<<"\n"; std::cout<<"decoded: "<<PsimagLite::PsiBase64::Decode(encoded)()<<"\n"; } src/InputNg.h +3 −3 Original line number Diff line number Diff line Loading @@ -196,7 +196,7 @@ public: continue; } if (str = end) { if (str == end) { mode = 2; break; } Loading @@ -217,8 +217,8 @@ public: assert(mode == 2); PsiBase64 base; data_ = base.decode(buffer); PsiBase64::Decode base64decode(buffer); data_ = base64decode(); check(); if (verbose_) { Loading src/PsiBase64.h +92 −75 Original line number Diff line number Diff line Loading @@ -42,14 +42,29 @@ namespace PsimagLite { class PsiBase64 { static const String base64Chars_; public: class Encode { public: const String& encode(const String& str) Encode(const String& str) { return encode(reinterpret_cast<const unsigned char*>(str.c_str()),str.length()); encode_(reinterpret_cast<const unsigned char*>(str.c_str()),str.length()); } const String& encode(unsigned char const* bytesToEncode, unsigned int inLen) Encode(unsigned char const* bytesToEncode, unsigned int inLen) { encode_(bytesToEncode,inLen); } const String& operator()() const { return buffer_; } private: void encode_(unsigned char const* bytesToEncode, unsigned int inLen) { buffer_ = ""; int i = 0; Loading Loading @@ -85,11 +100,16 @@ public: while ((i++ < 3)) buffer_ += '='; } return buffer_; } const String& decode(const String& encodedString) String buffer_; }; // class Encode class Decode { public: Decode(const String& encodedString) { buffer_ = ""; int inLen = encodedString.size(); Loading Loading @@ -127,11 +147,9 @@ public: for (j = 0; (j < i - 1); j++) buffer_ += charArray3[j]; } return buffer_; } const String& result() const { return buffer_; } const String& operator()() const { return buffer_; } private: Loading @@ -139,10 +157,9 @@ private: return (isalnum(c) || (c == '+') || (c == '/')); } static const String base64Chars_; String buffer_; }; }; // class Decode }; // class PsiBase64 } #endif // PSIBASE64_H Loading Loading
drivers/base64test.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -42,9 +42,9 @@ int main() const PsimagLite::String s = "ADP GmbH\nAnalyse Design & Programmierung" "\nGesellschaft mit beschränkter Haftung" ; PsimagLite::PsiBase64 base64; PsimagLite::String encoded = base64.encode(s); PsimagLite::PsiBase64::Encode base64encode(s); PsimagLite::String encoded = base64encode(); std::cout<<"encoded: "<<encoded<<"\n"; std::cout<<"decoded: "<<base64.decode(encoded)<<"\n"; std::cout<<"decoded: "<<PsimagLite::PsiBase64::Decode(encoded)()<<"\n"; }
src/InputNg.h +3 −3 Original line number Diff line number Diff line Loading @@ -196,7 +196,7 @@ public: continue; } if (str = end) { if (str == end) { mode = 2; break; } Loading @@ -217,8 +217,8 @@ public: assert(mode == 2); PsiBase64 base; data_ = base.decode(buffer); PsiBase64::Decode base64decode(buffer); data_ = base64decode(); check(); if (verbose_) { Loading
src/PsiBase64.h +92 −75 Original line number Diff line number Diff line Loading @@ -42,14 +42,29 @@ namespace PsimagLite { class PsiBase64 { static const String base64Chars_; public: class Encode { public: const String& encode(const String& str) Encode(const String& str) { return encode(reinterpret_cast<const unsigned char*>(str.c_str()),str.length()); encode_(reinterpret_cast<const unsigned char*>(str.c_str()),str.length()); } const String& encode(unsigned char const* bytesToEncode, unsigned int inLen) Encode(unsigned char const* bytesToEncode, unsigned int inLen) { encode_(bytesToEncode,inLen); } const String& operator()() const { return buffer_; } private: void encode_(unsigned char const* bytesToEncode, unsigned int inLen) { buffer_ = ""; int i = 0; Loading Loading @@ -85,11 +100,16 @@ public: while ((i++ < 3)) buffer_ += '='; } return buffer_; } const String& decode(const String& encodedString) String buffer_; }; // class Encode class Decode { public: Decode(const String& encodedString) { buffer_ = ""; int inLen = encodedString.size(); Loading Loading @@ -127,11 +147,9 @@ public: for (j = 0; (j < i - 1); j++) buffer_ += charArray3[j]; } return buffer_; } const String& result() const { return buffer_; } const String& operator()() const { return buffer_; } private: Loading @@ -139,10 +157,9 @@ private: return (isalnum(c) || (c == '+') || (c == '/')); } static const String base64Chars_; String buffer_; }; }; // class Decode }; // class PsiBase64 } #endif // PSIBASE64_H Loading