| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #include "../pch/pch.h"
- #include "CLewaimaiString.h"
- #include <boost/archive/iterators/base64_from_binary.hpp>
- #include <boost/archive/iterators/binary_from_base64.hpp>
- #include <boost/archive/iterators/transform_width.hpp>
- #include <string>
- #include <iostream>
- #include <sstream>
- using namespace std;
- using namespace boost::archive::iterators;
- CLewaimaiString::CLewaimaiString()
- {
- }
- CLewaimaiString::~CLewaimaiString()
- {
- }
- bool CLewaimaiString::base64_encode(const string& input, string* output)
- {
- typedef base64_from_binary<transform_width<string::const_iterator, 6, 8>> Base64EncodeIterator;
- stringstream result;
- try {
- copy(Base64EncodeIterator(input.begin()), Base64EncodeIterator(input.end()), ostream_iterator<char>(result));
- }
- catch (...) {
- return false;
- }
- size_t equal_count = (3 - input.length() % 3) % 3;
- for (size_t i = 0; i < equal_count; i++)
- {
- result.put('=');
- }
- *output = result.str();
- return output->empty() == false;
- }
- bool CLewaimaiString::base64_decode(const string& input, string* output)
- {
- typedef transform_width<binary_from_base64<string::const_iterator>, 8, 6> Base64DecodeIterator;
- stringstream result;
- try {
- copy(Base64DecodeIterator(input.begin()), Base64DecodeIterator(input.end()), ostream_iterator<char>(result));
- }
- catch (...) {
- return false;
- }
- *output = result.str();
- return output->empty() == false;
- }
- void CLewaimaiString::trim(string &s)
- {
- if (!s.empty())
- {
- s.erase(0, s.find_first_not_of(" "));
- s.erase(s.find_last_not_of(" ") + 1);
- }
- }
|