Botan 1.10.17
Botan::Charset Namespace Reference

Functions

bool caseless_cmp (char a, char b)
byte char2digit (char c)
char digit2char (byte 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_DLL Botan::Charset::caseless_cmp ( char a,
char b )

Definition at line 193 of file charset.cpp.

194 {
195 return (std::tolower(static_cast<unsigned char>(a)) ==
196 std::tolower(static_cast<unsigned char>(b)));
197 }

References caseless_cmp().

Referenced by caseless_cmp(), and Botan::x500_name_cmp().

◆ char2digit()

byte BOTAN_DLL Botan::Charset::char2digit ( char c)

Definition at line 149 of file charset.cpp.

150 {
151 switch(c)
152 {
153 case '0': return 0;
154 case '1': return 1;
155 case '2': return 2;
156 case '3': return 3;
157 case '4': return 4;
158 case '5': return 5;
159 case '6': return 6;
160 case '7': return 7;
161 case '8': return 8;
162 case '9': return 9;
163 }
164
165 throw Invalid_Argument("char2digit: Input is not a digit character");
166 }
std::invalid_argument Invalid_Argument
Definition exceptn.h:20

References char2digit().

Referenced by char2digit(), Botan::BigInt::decode(), and Botan::to_u32bit().

◆ digit2char()

char BOTAN_DLL Botan::Charset::digit2char ( byte b)

Definition at line 171 of file charset.cpp.

172 {
173 switch(b)
174 {
175 case 0: return '0';
176 case 1: return '1';
177 case 2: return '2';
178 case 3: return '3';
179 case 4: return '4';
180 case 5: return '5';
181 case 6: return '6';
182 case 7: return '7';
183 case 8: return '8';
184 case 9: return '9';
185 }
186
187 throw Invalid_Argument("digit2char: Input is not a digit");
188 }

References digit2char().

Referenced by digit2char(), Botan::BigInt::encode(), and Botan::to_string().

◆ is_digit()

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

Definition at line 128 of file charset.cpp.

129 {
130 if(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' ||
131 c == '5' || c == '6' || c == '7' || c == '8' || c == '9')
132 return true;
133 return false;
134 }

References is_digit().

Referenced by Botan::BigInt::decode(), is_digit(), Botan::EAC_Time::set_to(), Botan::X509_Time::set_to(), and Botan::timespec_to_u32bit().

◆ is_space()

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

Definition at line 139 of file charset.cpp.

140 {
141 if(c == ' ' || c == '\t' || c == '\n' || c == '\r')
142 return true;
143 return false;
144 }

References is_space().

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

◆ transcode()

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

Definition at line 103 of file charset.cpp.

105 {
106 if(to == LOCAL_CHARSET)
107 to = LATIN1_CHARSET;
108 if(from == LOCAL_CHARSET)
109 from = LATIN1_CHARSET;
110
111 if(to == from)
112 return str;
113
114 if(from == LATIN1_CHARSET && to == UTF8_CHARSET)
115 return latin1_to_utf8(str);
116 if(from == UTF8_CHARSET && to == LATIN1_CHARSET)
117 return utf8_to_latin1(str);
118 if(from == UCS2_CHARSET && to == LATIN1_CHARSET)
119 return ucs2_to_latin1(str);
120
121 throw Invalid_Argument("Unknown transcoding operation from " +
122 to_string(from) + " to " + to_string(to));
123 }
@ UCS2_CHARSET
Definition charset.h:21
@ LOCAL_CHARSET
Definition charset.h:20
@ LATIN1_CHARSET
Definition charset.h:23
@ UTF8_CHARSET
Definition charset.h:22
std::string to_string(u64bit n, size_t min_len)
Definition parsing.cpp:42

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

Referenced by Botan::ASN1_EAC_String::ASN1_EAC_String(), Botan::ASN1_String::ASN1_String(), Botan::ASN1_String::ASN1_String(), Botan::AlternativeName::decode_from(), Botan::ASN1_EAC_String::decode_from(), Botan::ASN1_String::decode_from(), Botan::X509_Time::decode_from(), Botan::ASN1_String::encode_into(), Botan::X509_Time::encode_into(), transcode(), Botan::ASN1_EAC_String::value(), and Botan::ASN1_String::value().