comparison C++/modules/Base64/Base64.cpp @ 393:875b5ce19fda

Base64: remove class, use namespace
author David Demelier <markand@malikania.fr>
date Mon, 28 Sep 2015 15:16:31 +0200
parents 0b576ee64d45
children d5ec1174b707
comparison
equal deleted inserted replaced
391:e2cefd0ee511 393:875b5ce19fda
19 #include <iterator> 19 #include <iterator>
20 #include <sstream> 20 #include <sstream>
21 21
22 #include "Base64.h" 22 #include "Base64.h"
23 23
24 char Base64::lookup(int value) noexcept 24 namespace base64 {
25
26 char lookup(int value) noexcept
25 { 27 {
26 static const char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 28 static const char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
27 29
28 return table[value]; 30 return table[value];
29 } 31 }
30 32
31 int Base64::rlookup(char ch) 33 int rlookup(char ch)
32 { 34 {
33 if (ch == '+') 35 if (ch == '+')
34 return 62; 36 return 62;
35 if (ch == '/') 37 if (ch == '/')
36 return 63; 38 return 63;
43 return ch - 71; 45 return ch - 71;
44 46
45 throw std::invalid_argument("not a valid base64 string"); 47 throw std::invalid_argument("not a valid base64 string");
46 } 48 }
47 49
48 std::string Base64::encode(const std::string &input) 50 std::string encode(const std::string &input)
49 { 51 {
50 std::string result; 52 std::string result;
51 std::istringstream iss(input, std::istringstream::in); 53 std::istringstream iss(input, std::istringstream::in);
52 54
53 encode(std::istreambuf_iterator<char>(iss), std::istreambuf_iterator<char>(), std::back_inserter(result)); 55 encode(std::istreambuf_iterator<char>(iss), std::istreambuf_iterator<char>(), std::back_inserter(result));
54 56
55 return result; 57 return result;
56 } 58 }
57 59
58 std::string Base64::decode(const std::string &input) 60 std::string decode(const std::string &input)
59 { 61 {
60 std::string result; 62 std::string result;
61 std::istringstream iss(input, std::istringstream::in); 63 std::istringstream iss(input, std::istringstream::in);
62 64
63 decode(std::istreambuf_iterator<char>(iss), std::istreambuf_iterator<char>(), std::back_inserter(result)); 65 decode(std::istreambuf_iterator<char>(iss), std::istreambuf_iterator<char>(), std::back_inserter(result));
64 66
65 return result; 67 return result;
66 } 68 }
69
70 } // !base64