Botan  2.8.0
Crypto and TLS for C++11
Functions
Botan::Charset Namespace Reference

Functions

bool caseless_cmp (char a, char b)
 
uint8_t char2digit (char c)
 
char digit2char (uint8_t b)
 
bool is_digit (char c)
 
bool is_space (char c)
 
std::string transcode (const std::string &str, Character_Set to, Character_Set from)
 

Function Documentation

◆ caseless_cmp()

bool Botan::Charset::caseless_cmp ( char  a,
char  b 
)

Definition at line 275 of file charset.cpp.

Referenced by Botan::x500_name_cmp().

276  {
277  return (std::tolower(static_cast<unsigned char>(a)) ==
278  std::tolower(static_cast<unsigned char>(b)));
279  }

◆ char2digit()

uint8_t Botan::Charset::char2digit ( char  c)

Definition at line 231 of file charset.cpp.

Referenced by Botan::BigInt::decode().

232  {
233  switch(c)
234  {
235  case '0': return 0;
236  case '1': return 1;
237  case '2': return 2;
238  case '3': return 3;
239  case '4': return 4;
240  case '5': return 5;
241  case '6': return 6;
242  case '7': return 7;
243  case '8': return 8;
244  case '9': return 9;
245  }
246 
247  throw Invalid_Argument("char2digit: Input is not a digit character");
248  }

◆ digit2char()

char Botan::Charset::digit2char ( uint8_t  b)

Definition at line 253 of file charset.cpp.

Referenced by Botan::BigInt::encode(), and Botan::BigInt::to_dec_string().

254  {
255  switch(b)
256  {
257  case 0: return '0';
258  case 1: return '1';
259  case 2: return '2';
260  case 3: return '3';
261  case 4: return '4';
262  case 5: return '5';
263  case 6: return '6';
264  case 7: return '7';
265  case 8: return '8';
266  case 9: return '9';
267  }
268 
269  throw Invalid_Argument("digit2char: Input is not a digit");
270  }

◆ is_digit()

bool Botan::Charset::is_digit ( char  c)

Definition at line 210 of file charset.cpp.

Referenced by Botan::BigInt::decode(), and Botan::timespec_to_u32bit().

211  {
212  if(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' ||
213  c == '5' || c == '6' || c == '7' || c == '8' || c == '9')
214  return true;
215  return false;
216  }

◆ is_space()

bool Botan::Charset::is_space ( char  c)

Definition at line 221 of file charset.cpp.

Referenced by Botan::BigInt::decode(), and Botan::x500_name_cmp().

222  {
223  if(c == ' ' || c == '\t' || c == '\n' || c == '\r')
224  return true;
225  return false;
226  }

◆ transcode()

std::string Botan::Charset::transcode ( const std::string &  str,
Character_Set  to,
Character_Set  from 
)

Definition at line 185 of file charset.cpp.

References Botan::LATIN1_CHARSET, Botan::LOCAL_CHARSET, Botan::ASN1::to_string(), Botan::UCS2_CHARSET, Botan::UTF8_CHARSET, and Botan::utf8_to_latin1().

187  {
188  if(to == LOCAL_CHARSET)
189  to = LATIN1_CHARSET;
190  if(from == LOCAL_CHARSET)
191  from = LATIN1_CHARSET;
192 
193  if(to == from)
194  return str;
195 
196  if(from == LATIN1_CHARSET && to == UTF8_CHARSET)
197  return latin1_to_utf8(str);
198  if(from == UTF8_CHARSET && to == LATIN1_CHARSET)
199  return utf8_to_latin1(str);
200  if(from == UCS2_CHARSET && to == LATIN1_CHARSET)
201  return ucs2_to_latin1(str);
202 
203  throw Invalid_Argument("Unknown transcoding operation from " +
204  std::to_string(from) + " to " + std::to_string(to));
205  }
std::string utf8_to_latin1(const std::string &utf8)
Definition: charset.cpp:98
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:210