Electroneum
epee::string_encoding Namespace Reference

Functions

std::string convert_to_ansii (const std::wstring &str_from)
 
std::string convert_to_ansii (const std::string &str_from)
 
std::wstring convert_to_unicode (const std::string &str_from)
 
std::wstring convert_to_unicode (const std::wstring &str_from)
 
template<class target_string >
target_string convert_to_t (const std::wstring &str_from)
 
template<>
std::string convert_to_t< std::string > (const std::wstring &str_from)
 
template<>
std::wstring convert_to_t< std::wstring > (const std::wstring &str_from)
 
template<class target_string >
target_string convert_to_t (const std::string &str_from)
 
template<>
std::string convert_to_t< std::string > (const std::string &str_from)
 
template<>
std::wstring convert_to_t< std::wstring > (const std::string &str_from)
 
std::string & base64_chars ()
 
std::string base64_encode (unsigned char const *bytes_to_encode, size_t in_len)
 
std::string base64_encode (const std::string &str)
 
bool is_base64 (unsigned char c)
 
std::string base64_decode (std::string const &encoded_string)
 

Function Documentation

◆ base64_chars()

std::string& epee::string_encoding::base64_chars ( )
inline

Definition at line 132 of file string_coding.h.

133  {
134 
135  static std::string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
136  "abcdefghijklmnopqrstuvwxyz"
137  "0123456789+/";
138 
139  return chars;
140 
141  }
::std::string string
Definition: gtest-port.h:1097
Here is the caller graph for this function:

◆ base64_decode()

std::string epee::string_encoding::base64_decode ( std::string const &  encoded_string)
inline

Definition at line 199 of file string_coding.h.

199  {
200  size_t in_len = encoded_string.size();
201  size_t i = 0;
202  size_t j = 0;
203  size_t in_ = 0;
204  unsigned char char_array_4[4], char_array_3[3];
205  std::string ret;
206 
207  while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
208  char_array_4[i++] = encoded_string[in_]; in_++;
209  if (i ==4) {
210  for (i = 0; i <4; i++)
211  char_array_4[i] = (unsigned char)base64_chars().find(char_array_4[i]);
212 
213  char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
214  char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
215  char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
216 
217  for (i = 0; (i < 3); i++)
218  ret += char_array_3[i];
219  i = 0;
220  }
221  }
222 
223  if (i) {
224  for (j = i; j <4; j++)
225  char_array_4[j] = 0;
226 
227  for (j = 0; j <4; j++)
228  char_array_4[j] = (unsigned char)base64_chars().find(char_array_4[j]);
229 
230  char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
231  char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
232  char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
233 
234  for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
235  }
236 
237  return ret;
238  }
::std::string string
Definition: gtest-port.h:1097
bool is_base64(unsigned char c)
std::string & base64_chars()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ base64_encode() [1/2]

std::string epee::string_encoding::base64_encode ( unsigned char const *  bytes_to_encode,
size_t  in_len 
)
inline

Definition at line 144 of file string_coding.h.

144  {
145  std::string ret;
146  int i = 0;
147  int j = 0;
148  unsigned char char_array_3[3];
149  unsigned char char_array_4[4];
150 
151  while (in_len--) {
152  char_array_3[i++] = *(bytes_to_encode++);
153  if (i == 3) {
154  char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
155  char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
156  char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
157  char_array_4[3] = char_array_3[2] & 0x3f;
158 
159  for(i = 0; (i <4) ; i++)
160  ret += base64_chars()[char_array_4[i]];
161  i = 0;
162  }
163  }
164 
165  if (i)
166  {
167  for(j = i; j < 3; j++)
168  char_array_3[j] = '\0';
169 
170  char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
171  char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
172  char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
173  char_array_4[3] = char_array_3[2] & 0x3f;
174 
175  for (j = 0; (j < i + 1); j++)
176  ret += base64_chars()[char_array_4[j]];
177 
178  while((i++ < 3))
179  ret += '=';
180 
181  }
182 
183  return ret;
184 
185  }
::std::string string
Definition: gtest-port.h:1097
std::string & base64_chars()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ base64_encode() [2/2]

std::string epee::string_encoding::base64_encode ( const std::string &  str)
inline

Definition at line 188 of file string_coding.h.

189  {
190  return base64_encode((unsigned char const* )str.data(), str.size());
191  }
std::string base64_encode(const std::string &str)
Here is the call graph for this function:

◆ convert_to_ansii() [1/2]

std::string epee::string_encoding::convert_to_ansii ( const std::wstring &  str_from)
inline

Definition at line 37 of file string_coding.h.

38  {
39 
40  std::string res(str_from.begin(), str_from.end());
41  return res;
42  /*
43  std::string result;
44  std::locale loc;
45  for(unsigned int i= 0; i < str_from.size(); ++i)
46  {
47  result += std::use_facet<std::ctype<wchar_t> >(loc).narrow(str_from[i]);
48  }
49  return result;
50  */
51 
52  //return boost::lexical_cast<std::string>(str_from);
53  /*
54  std::string str_trgt;
55  if(!str_from.size())
56  return str_trgt;
57  int cb = ::WideCharToMultiByte( code_page, 0, str_from.data(), (__int32)str_from.size(), 0, 0, 0, 0 );
58  if(!cb)
59  return str_trgt;
60  str_trgt.resize(cb);
61  ::WideCharToMultiByte( code_page, 0, str_from.data(), (int)str_from.size(),
62  (char*)str_trgt.data(), (int)str_trgt.size(), 0, 0);
63  return str_trgt;*/
64  }
const char * res
Definition: hmac_keccak.cpp:41
::std::string string
Definition: gtest-port.h:1097
Here is the caller graph for this function:

◆ convert_to_ansii() [2/2]

std::string epee::string_encoding::convert_to_ansii ( const std::string &  str_from)
inline

Definition at line 66 of file string_coding.h.

67  {
68  return str_from;
69  }

◆ convert_to_t() [1/2]

template<class target_string >
target_string epee::string_encoding::convert_to_t ( const std::wstring &  str_from)
inline
Here is the caller graph for this function:

◆ convert_to_t() [2/2]

template<class target_string >
target_string epee::string_encoding::convert_to_t ( const std::string &  str_from)
inline

◆ convert_to_t< std::string >() [1/2]

template<>
std::string epee::string_encoding::convert_to_t< std::string > ( const std::wstring &  str_from)
inline

Definition at line 105 of file string_coding.h.

106  {
107  return convert_to_ansii(str_from);
108  }
std::string convert_to_ansii(const std::string &str_from)
Definition: string_coding.h:66
Here is the call graph for this function:

◆ convert_to_t< std::string >() [2/2]

template<>
std::string epee::string_encoding::convert_to_t< std::string > ( const std::string &  str_from)
inline

Definition at line 120 of file string_coding.h.

121  {
122  return str_from;
123  }

◆ convert_to_t< std::wstring >() [1/2]

template<>
std::wstring epee::string_encoding::convert_to_t< std::wstring > ( const std::wstring &  str_from)
inline

Definition at line 111 of file string_coding.h.

112  {
113  return str_from;
114  }

◆ convert_to_t< std::wstring >() [2/2]

template<>
std::wstring epee::string_encoding::convert_to_t< std::wstring > ( const std::string &  str_from)
inline

Definition at line 126 of file string_coding.h.

127  {
128  return convert_to_unicode(str_from);
129  }
std::wstring convert_to_unicode(const std::wstring &str_from)
Definition: string_coding.h:96
Here is the call graph for this function:

◆ convert_to_unicode() [1/2]

std::wstring epee::string_encoding::convert_to_unicode ( const std::string &  str_from)
inline

Definition at line 71 of file string_coding.h.

72  {
73  std::wstring result;
74  std::locale loc;
75  for(unsigned int i= 0; i < str_from.size(); ++i)
76  {
77  result += std::use_facet<std::ctype<wchar_t> >(loc).widen(str_from[i]);
78  }
79  return result;
80 
81  //return boost::lexical_cast<std::wstring>(str_from);
82  /*
83  std::wstring str_trgt;
84  if(!str_from.size())
85  return str_trgt;
86 
87  int cb = ::MultiByteToWideChar( code_page, 0, str_from.data(), (int)str_from.size(), 0, 0 );
88  if(!cb)
89  return str_trgt;
90 
91  str_trgt.resize(cb);
92  ::MultiByteToWideChar( code_page, 0, str_from.data(),(int)str_from.size(),
93  (wchar_t*)str_trgt.data(),(int)str_trgt.size());
94  return str_trgt;*/
95  }
::std::wstring wstring
Definition: gtest-port.h:1103
Here is the caller graph for this function:

◆ convert_to_unicode() [2/2]

std::wstring epee::string_encoding::convert_to_unicode ( const std::wstring &  str_from)
inline

Definition at line 96 of file string_coding.h.

97  {
98  return str_from;
99  }

◆ is_base64()

bool epee::string_encoding::is_base64 ( unsigned char  c)
inline

Definition at line 193 of file string_coding.h.

193  {
194  return (isalnum(c) || (c == '+') || (c == '/'));
195  }
Here is the caller graph for this function: