Botan  2.6.0
Crypto and TLS for C++11
parsing.h
Go to the documentation of this file.
1 /*
2 * Various string utils and parsing functions
3 * (C) 1999-2007,2013 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_PARSER_H_
9 #define BOTAN_PARSER_H_
10 
11 #include <botan/types.h>
12 #include <string>
13 #include <vector>
14 #include <set>
15 
16 #include <istream>
17 #include <functional>
18 #include <map>
19 
20 namespace Botan {
21 
22 /**
23 * Parse a SCAN-style algorithm name
24 * @param scan_name the name
25 * @return the name components
26 */
27 BOTAN_PUBLIC_API(2,0) std::vector<std::string>
28 parse_algorithm_name(const std::string& scan_name);
29 
30 /**
31 * Split a string
32 * @param str the input string
33 * @param delim the delimitor
34 * @return string split by delim
35 */
36 BOTAN_PUBLIC_API(2,0) std::vector<std::string> split_on(
37  const std::string& str, char delim);
38 
39 /**
40 * Split a string on a character predicate
41 * @param str the input string
42 * @param pred the predicate
43 */
44 BOTAN_PUBLIC_API(2,0) std::vector<std::string>
45 split_on_pred(const std::string& str,
46  std::function<bool (char)> pred);
47 
48 /**
49 * Erase characters from a string
50 */
52 BOTAN_DEPRECATED("Unused")
53 std::string erase_chars(const std::string& str, const std::set<char>& chars);
54 
55 /**
56 * Replace a character in a string
57 * @param str the input string
58 * @param from_char the character to replace
59 * @param to_char the character to replace it with
60 * @return str with all instances of from_char replaced by to_char
61 */
63 BOTAN_DEPRECATED("Unused")
64 std::string replace_char(const std::string& str,
65  char from_char,
66  char to_char);
67 
68 /**
69 * Replace a character in a string
70 * @param str the input string
71 * @param from_chars the characters to replace
72 * @param to_char the character to replace it with
73 * @return str with all instances of from_chars replaced by to_char
74 */
76 BOTAN_DEPRECATED("Unused")
77 std::string replace_chars(const std::string& str,
78  const std::set<char>& from_chars,
79  char to_char);
80 
81 /**
82 * Join a string
83 * @param strs strings to join
84 * @param delim the delimitor
85 * @return string joined by delim
86 */
88 std::string string_join(const std::vector<std::string>& strs,
89  char delim);
90 
91 /**
92 * Parse an ASN.1 OID
93 * @param oid the OID in string form
94 * @return OID components
95 */
96 BOTAN_PUBLIC_API(2,0) std::vector<uint32_t> parse_asn1_oid(const std::string& oid);
97 
98 /**
99 * Compare two names using the X.509 comparison algorithm
100 * @param name1 the first name
101 * @param name2 the second name
102 * @return true if name1 is the same as name2 by the X.509 comparison rules
103 */
104 BOTAN_PUBLIC_API(2,0)
105 bool x500_name_cmp(const std::string& name1,
106  const std::string& name2);
107 
108 /**
109 * Convert a string to a number
110 * @param str the string to convert
111 * @return number value of the string
112 */
113 BOTAN_PUBLIC_API(2,0) uint32_t to_u32bit(const std::string& str);
114 
115 /**
116 * Convert a string to a number
117 * @param str the string to convert
118 * @return number value of the string
119 */
120 BOTAN_PUBLIC_API(2,3) uint16_t to_uint16(const std::string& str);
121 
122 /**
123 * Convert a time specification to a number
124 * @param timespec the time specification
125 * @return number of seconds represented by timespec
126 */
127 BOTAN_PUBLIC_API(2,0) uint32_t BOTAN_DEPRECATED("Not used anymore")
128 timespec_to_u32bit(const std::string& timespec);
129 
130 /**
131 * Convert a string representation of an IPv4 address to a number
132 * @param ip_str the string representation
133 * @return integer IPv4 address
134 */
135 BOTAN_PUBLIC_API(2,0) uint32_t string_to_ipv4(const std::string& ip_str);
136 
137 /**
138 * Convert an IPv4 address to a string
139 * @param ip_addr the IPv4 address to convert
140 * @return string representation of the IPv4 address
141 */
142 BOTAN_PUBLIC_API(2,0) std::string ipv4_to_string(uint32_t ip_addr);
143 
144 std::map<std::string, std::string> BOTAN_PUBLIC_API(2,0) read_cfg(std::istream& is);
145 
146 std::string BOTAN_PUBLIC_API(2,0) clean_ws(const std::string& s);
147 
148 bool BOTAN_PUBLIC_API(2,0) host_wildcard_match(const std::string& wildcard, const std::string& host);
149 
150 
151 }
152 
153 #endif
uint16_t to_uint16(const std::string &str)
Definition: parsing.cpp:21
std::string erase_chars(const std::string &str, const std::set< char > &chars)
Definition: parsing.cpp:308
std::vector< std::string > split_on(const std::string &str, char delim)
Definition: parsing.cpp:144
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
std::vector< std::string > split_on_pred(const std::string &str, std::function< bool(char)> pred)
Definition: parsing.cpp:149
Definition: bigint.h:719
uint32_t to_u32bit(const std::string &str)
Definition: parsing.cpp:31
uint32_t timespec_to_u32bit(const std::string &timespec)
Definition: parsing.cpp:60
std::string clean_ws(const std::string &s)
Definition: read_cfg.cpp:13
bool host_wildcard_match(const std::string &issued_, const std::string &host_)
Definition: parsing.cpp:358
std::map< std::string, std::string > read_cfg(std::istream &is)
Definition: read_cfg.cpp:28
std::string ipv4_to_string(uint32_t ip)
Definition: parsing.cpp:294
std::string replace_char(const std::string &str, char from_char, char to_char)
Definition: parsing.cpp:332
bool x500_name_cmp(const std::string &name1, const std::string &name2)
Definition: parsing.cpp:228
std::vector< std::string > parse_algorithm_name(const std::string &namex)
Definition: parsing.cpp:91
Definition: alg_id.cpp:13
uint32_t string_to_ipv4(const std::string &str)
Definition: parsing.cpp:269
std::string replace_chars(const std::string &str, const std::set< char > &chars, char to_char)
Definition: parsing.cpp:319
std::vector< uint32_t > parse_asn1_oid(const std::string &oid)
Definition: parsing.cpp:195
std::string string_join(const std::vector< std::string > &strs, char delim)
Definition: parsing.cpp:178