Botan
1.11.15
|
00001 /* 00002 * Various string utils and parsing functions 00003 * (C) 1999-2007,2013 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_PARSER_H__ 00009 #define BOTAN_PARSER_H__ 00010 00011 #include <botan/types.h> 00012 #include <string> 00013 #include <vector> 00014 #include <set> 00015 00016 #include <istream> 00017 #include <functional> 00018 #include <map> 00019 00020 namespace Botan { 00021 00022 /** 00023 * Parse a SCAN-style algorithm name 00024 * @param scan_name the name 00025 * @return the name components 00026 */ 00027 BOTAN_DLL std::vector<std::string> 00028 parse_algorithm_name(const std::string& scan_name); 00029 00030 /** 00031 * Split a string 00032 * @param str the input string 00033 * @param delim the delimitor 00034 * @return string split by delim 00035 */ 00036 BOTAN_DLL std::vector<std::string> split_on( 00037 const std::string& str, char delim); 00038 00039 /** 00040 * Split a string on a character predicate 00041 * @param str the input string 00042 */ 00043 BOTAN_DLL std::vector<std::string> 00044 split_on_pred(const std::string& str, 00045 std::function<bool (char)> pred); 00046 00047 /** 00048 * Erase characters from a string 00049 */ 00050 BOTAN_DLL std::string erase_chars(const std::string& str, const std::set<char>& chars); 00051 00052 /** 00053 * Replace a character in a string 00054 * @param str the input string 00055 * @param from_char the character to replace 00056 * @param to_char the character to replace it with 00057 * @return str with all instances of from_char replaced by to_char 00058 */ 00059 BOTAN_DLL std::string replace_char(const std::string& str, 00060 char from_char, 00061 char to_char); 00062 00063 /** 00064 * Replace a character in a string 00065 * @param str the input string 00066 * @param from_chars the characters to replace 00067 * @param to_char the character to replace it with 00068 * @return str with all instances of from_chars replaced by to_char 00069 */ 00070 BOTAN_DLL std::string replace_chars(const std::string& str, 00071 const std::set<char>& from_chars, 00072 char to_char); 00073 00074 /** 00075 * Join a string 00076 * @param strs strings to join 00077 * @param delim the delimitor 00078 * @return string joined by delim 00079 */ 00080 BOTAN_DLL std::string string_join(const std::vector<std::string>& strs, 00081 char delim); 00082 00083 /** 00084 * Parse an ASN.1 OID 00085 * @param oid the OID in string form 00086 * @return OID components 00087 */ 00088 BOTAN_DLL std::vector<u32bit> parse_asn1_oid(const std::string& oid); 00089 00090 /** 00091 * Compare two names using the X.509 comparison algorithm 00092 * @param name1 the first name 00093 * @param name2 the second name 00094 * @return true if name1 is the same as name2 by the X.509 comparison rules 00095 */ 00096 BOTAN_DLL bool x500_name_cmp(const std::string& name1, 00097 const std::string& name2); 00098 00099 /** 00100 * Convert a string to a number 00101 * @param str the string to convert 00102 * @return number value of the string 00103 */ 00104 BOTAN_DLL u32bit to_u32bit(const std::string& str); 00105 00106 /** 00107 * Convert a time specification to a number 00108 * @param timespec the time specification 00109 * @return number of seconds represented by timespec 00110 */ 00111 BOTAN_DLL u32bit timespec_to_u32bit(const std::string& timespec); 00112 00113 /** 00114 * Convert a string representation of an IPv4 address to a number 00115 * @param ip_str the string representation 00116 * @return integer IPv4 address 00117 */ 00118 BOTAN_DLL u32bit string_to_ipv4(const std::string& ip_str); 00119 00120 /** 00121 * Convert an IPv4 address to a string 00122 * @param ip_addr the IPv4 address to convert 00123 * @return string representation of the IPv4 address 00124 */ 00125 BOTAN_DLL std::string ipv4_to_string(u32bit ip_addr); 00126 00127 std::map<std::string, std::string> BOTAN_DLL read_cfg(std::istream& is); 00128 00129 std::string BOTAN_DLL clean_ws(const std::string& s); 00130 00131 00132 } 00133 00134 #endif