diff options
Diffstat (limited to 'src/utils/parsing.cpp')
-rw-r--r-- | src/utils/parsing.cpp | 63 |
1 files changed, 8 insertions, 55 deletions
diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp index 9ec00040c..ff0718bb0 100644 --- a/src/utils/parsing.cpp +++ b/src/utils/parsing.cpp @@ -13,53 +13,6 @@ namespace Botan { /* -* Convert a string into an integer -*/ -u32bit to_u32bit(const std::string& number) - { - u32bit n = 0; - - for(std::string::const_iterator i = number.begin(); i != number.end(); ++i) - { - const u32bit OVERFLOW_MARK = 0xFFFFFFFF / 10; - - if(*i == ' ') - continue; - - byte digit = Charset::char2digit(*i); - - if((n > OVERFLOW_MARK) || (n == OVERFLOW_MARK && digit > 5)) - throw Decoding_Error("to_u32bit: Integer overflow"); - n *= 10; - n += digit; - } - return n; - } - -/* -* Convert an integer into a string -*/ -std::string to_string(u64bit n, size_t min_len) - { - std::string lenstr; - if(n) - { - while(n > 0) - { - lenstr = Charset::digit2char(n % 10) + lenstr; - n /= 10; - } - } - else - lenstr = "0"; - - while(lenstr.size() < min_len) - lenstr = "0" + lenstr; - - return lenstr; - } - -/* * Convert a string into a time duration */ u32bit timespec_to_u32bit(const std::string& timespec) @@ -106,7 +59,7 @@ std::vector<std::string> parse_algorithm_name(const std::string& namex) elems.push_back(name.substr(0, name.find('('))); name = name.substr(name.find('(')); - for(std::string::const_iterator i = name.begin(); i != name.end(); ++i) + for(auto i = name.begin(); i != name.end(); ++i) { char c = *i; @@ -155,7 +108,7 @@ std::vector<std::string> split_on(const std::string& str, char delim) if(str == "") return elems; std::string substr; - for(std::string::const_iterator i = str.begin(); i != str.end(); ++i) + for(auto i = str.begin(); i != str.end(); ++i) { if(*i == delim) { @@ -182,7 +135,7 @@ std::vector<u32bit> parse_asn1_oid(const std::string& oid) std::string substring; std::vector<u32bit> oid_elems; - for(std::string::const_iterator i = oid.begin(); i != oid.end(); ++i) + for(auto i = oid.begin(); i != oid.end(); ++i) { char c = *i; @@ -212,8 +165,8 @@ std::vector<u32bit> parse_asn1_oid(const std::string& oid) */ bool x500_name_cmp(const std::string& name1, const std::string& name2) { - std::string::const_iterator p1 = name1.begin(); - std::string::const_iterator p2 = name2.begin(); + auto p1 = name1.begin(); + auto p2 = name2.begin(); while((p1 != name1.end()) && Charset::is_space(*p1)) ++p1; while((p2 != name2.end()) && Charset::is_space(*p2)) ++p2; @@ -258,9 +211,9 @@ u32bit string_to_ipv4(const std::string& str) u32bit ip = 0; - for(size_t i = 0; i != parts.size(); ++i) + for(auto part = parts.begin(); part != parts.end(); ++part) { - u32bit octet = to_u32bit(parts[i]); + u32bit octet = to_u32bit(*part); if(octet > 255) throw Decoding_Error("Invalid IP string " + str); @@ -282,7 +235,7 @@ std::string ipv4_to_string(u32bit ip) { if(i) str += "."; - str += to_string(get_byte(i, ip)); + str += std::to_string(get_byte(i, ip)); } return str; |