diff options
author | Jack Lloyd <[email protected]> | 2021-01-13 08:56:18 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2021-01-13 09:03:37 -0500 |
commit | ff081146fae5ede31c7c1b6526f67da6de24861f (patch) | |
tree | 547a2b98d6602973de72f5c41cec9b44ee02a346 /src/lib/utils | |
parent | ad751001a1c3a268852bdab5f6d7fdc96cacfc07 (diff) |
More charset.h cleanups
Now charset.h is just character set conversions
Diffstat (limited to 'src/lib/utils')
-rw-r--r-- | src/lib/utils/charset.cpp | 77 | ||||
-rw-r--r-- | src/lib/utils/charset.h | 16 | ||||
-rw-r--r-- | src/lib/utils/parsing.cpp | 50 | ||||
-rw-r--r-- | src/lib/utils/parsing.h | 9 |
4 files changed, 2 insertions, 150 deletions
diff --git a/src/lib/utils/charset.cpp b/src/lib/utils/charset.cpp index 8ffde469a..e6a2e5c1d 100644 --- a/src/lib/utils/charset.cpp +++ b/src/lib/utils/charset.cpp @@ -113,82 +113,5 @@ std::string latin1_to_utf8(const std::string& iso8859) return utf8; } -namespace Charset { - -/* -* Check if a character represents a digit -*/ -bool is_digit(char c) - { - if(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || - c == '5' || c == '6' || c == '7' || c == '8' || c == '9') - return true; - return false; - } - -/* -* Check if a character represents whitespace -*/ -bool is_space(char c) - { - if(c == ' ' || c == '\t' || c == '\n' || c == '\r') - return true; - return false; - } - -/* -* Convert a character to a digit -*/ -uint8_t char2digit(char c) - { - switch(c) - { - case '0': return 0; - case '1': return 1; - case '2': return 2; - case '3': return 3; - case '4': return 4; - case '5': return 5; - case '6': return 6; - case '7': return 7; - case '8': return 8; - case '9': return 9; - } - - throw Invalid_Argument("char2digit: Input is not a digit character"); - } - -/* -* Convert a digit to a character -*/ -char digit2char(uint8_t b) - { - switch(b) - { - case 0: return '0'; - case 1: return '1'; - case 2: return '2'; - case 3: return '3'; - case 4: return '4'; - case 5: return '5'; - case 6: return '6'; - case 7: return '7'; - case 8: return '8'; - case 9: return '9'; - } - - throw Invalid_Argument("digit2char: Input is not a digit"); - } - -/* -* Case-insensitive character comparison -*/ -bool caseless_cmp(char a, char b) - { - return (std::tolower(static_cast<unsigned char>(a)) == - std::tolower(static_cast<unsigned char>(b))); - } - } -} diff --git a/src/lib/utils/charset.h b/src/lib/utils/charset.h index b14b1ad41..8012472e5 100644 --- a/src/lib/utils/charset.h +++ b/src/lib/utils/charset.h @@ -1,5 +1,5 @@ /* -* Character Set Handling +* Character Set Conversions * (C) 1999-2007 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) @@ -35,20 +35,6 @@ BOTAN_TEST_API std::string ucs4_to_utf8(const uint8_t ucs4[], size_t len); */ BOTAN_TEST_API std::string latin1_to_utf8(const std::string& iso8859); -namespace Charset { - -/* -* Simple character classifier functions -*/ -bool is_digit(char c); -bool is_space(char c); -bool caseless_cmp(char x, char y); - -uint8_t char2digit(char c); -char digit2char(uint8_t b); - -} - } #endif diff --git a/src/lib/utils/parsing.cpp b/src/lib/utils/parsing.cpp index 7d6d9c6d6..9f0f36c79 100644 --- a/src/lib/utils/parsing.cpp +++ b/src/lib/utils/parsing.cpp @@ -8,17 +8,10 @@ */ #include <botan/internal/parsing.h> -#include <botan/exceptn.h> -#include <botan/internal/charset.h> #include <botan/internal/loadstor.h> +#include <botan/exceptn.h> #include <algorithm> #include <cctype> -#include <limits> -#include <set> - -#if defined(BOTAN_HAS_ASN1) - #include <botan/asn1_obj.h> -#endif namespace Botan { @@ -157,47 +150,6 @@ std::string string_join(const std::vector<std::string>& strs, char delim) } /* -* X.500 String Comparison -*/ -bool x500_name_cmp(const std::string& name1, const std::string& name2) - { - 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; - - while(p1 != name1.end() && p2 != name2.end()) - { - if(Charset::is_space(*p1)) - { - if(!Charset::is_space(*p2)) - return false; - - while((p1 != name1.end()) && Charset::is_space(*p1)) ++p1; - while((p2 != name2.end()) && Charset::is_space(*p2)) ++p2; - - if(p1 == name1.end() && p2 == name2.end()) - return true; - if(p1 == name1.end() || p2 == name2.end()) - return false; - } - - if(!Charset::caseless_cmp(*p1, *p2)) - return false; - ++p1; - ++p2; - } - - while((p1 != name1.end()) && Charset::is_space(*p1)) ++p1; - while((p2 != name2.end()) && Charset::is_space(*p2)) ++p2; - - if((p1 != name1.end()) || (p2 != name2.end())) - return false; - return true; - } - -/* * Convert a decimal-dotted string to binary IP */ uint32_t string_to_ipv4(const std::string& str) diff --git a/src/lib/utils/parsing.h b/src/lib/utils/parsing.h index ba3b5eadd..49eacba81 100644 --- a/src/lib/utils/parsing.h +++ b/src/lib/utils/parsing.h @@ -43,15 +43,6 @@ std::string string_join(const std::vector<std::string>& strs, char delim); /** -* Compare two names using the X.509 comparison algorithm -* @param name1 the first name -* @param name2 the second name -* @return true if name1 is the same as name2 by the X.509 comparison rules -*/ -bool x500_name_cmp(const std::string& name1, - const std::string& name2); - -/** * Convert a string to a number * @param str the string to convert * @return number value of the string |