| 164 | } |
| 165 | |
| 166 | bool Base64Decode(const string& in, string* out) { |
| 167 | typedef transform_width<binary_from_base64<string::const_iterator>, 8, 6> base64_decode; |
| 168 | string tmp = in; |
| 169 | // Replace padding with base64 encoded NULL |
| 170 | replace(tmp.begin(), tmp.end(), '=', 'A'); |
| 171 | try { |
| 172 | *out = string(base64_decode(tmp.begin()), base64_decode(tmp.end())); |
| 173 | } catch(std::exception& e) { |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | // Remove trailing '\0' that were added as padding. Since \0 is special, |
| 178 | // the boost functions get confused so do this manually. |
| 179 | int num_padded_chars = 0; |
| 180 | for (int i = out->size() - 1; i >= 0; --i) { |
| 181 | if ((*out)[i] != '\0') break; |
| 182 | ++num_padded_chars; |
| 183 | } |
| 184 | out->resize(out->size() - num_padded_chars); |
| 185 | return true; |
| 186 | } |
| 187 | |
| 188 | void EscapeForHtml(const string& in, std::ostringstream* out) { |
| 189 | DCHECK(out != nullptr); |