Botan 3.4.0
Crypto and TLS for C&
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_PARSING_UTILS_H_
9#define BOTAN_PARSING_UTILS_H_
10
11#include <botan/types.h>
12#include <istream>
13#include <map>
14#include <string>
15#include <string_view>
16#include <vector>
17
18namespace Botan {
19
20/**
21* Parse a SCAN-style algorithm name
22* @param scan_name the name
23* @return the name components
24*/
25std::vector<std::string> parse_algorithm_name(std::string_view scan_name);
26
27/**
28* Split a string
29* @param str the input string
30* @param delim the delimitor
31* @return string split by delim
32*/
33BOTAN_TEST_API std::vector<std::string> split_on(std::string_view str, char delim);
34
35/**
36* Join a string
37* @param strs strings to join
38* @param delim the delimitor
39* @return string joined by delim
40*/
41std::string string_join(const std::vector<std::string>& strs, char delim);
42
43/**
44* Convert a decimal string to a number
45* @param str the string to convert
46* @return number value of the string
47*/
48BOTAN_TEST_API uint32_t to_u32bit(std::string_view str);
49
50/**
51* Convert a decimal string to a number
52* @param str the string to convert
53* @return number value of the string
54*/
55uint16_t to_uint16(std::string_view str);
56
57/**
58* Convert a string representation of an IPv4 address to a number
59* @param ip_str the string representation
60* @return integer IPv4 address
61*/
62uint32_t string_to_ipv4(std::string_view ip_str);
63
64/**
65* Convert an IPv4 address to a string
66* @param ip_addr the IPv4 address to convert
67* @return string representation of the IPv4 address
68*/
69std::string ipv4_to_string(uint32_t ip_addr);
70
71std::map<std::string, std::string> read_cfg(std::istream& is);
72
73/**
74* Accepts key value pairs deliminated by commas:
75*
76* "" (returns empty map)
77* "K=V" (returns map {'K': 'V'})
78* "K1=V1,K2=V2"
79* "K1=V1,K2=V2,K3=V3"
80* "K1=V1,K2=V2,K3=a_value\,with\,commas_and_\=equals"
81*
82* Values may be empty, keys must be non-empty and unique. Duplicate
83* keys cause an exception.
84*
85* Within both key and value, comma and equals can be escaped with
86* backslash. Backslash can also be escaped.
87*/
89std::map<std::string, std::string> read_kv(std::string_view kv);
90
91std::string tolower_string(std::string_view s);
92
93/**
94* Check if the given hostname is a match for the specified wildcard
95*/
97bool host_wildcard_match(std::string_view wildcard, std::string_view host);
98
99} // namespace Botan
100
101#endif
#define BOTAN_TEST_API
Definition compiler.h:51
uint32_t to_u32bit(std::string_view str_view)
Definition parsing.cpp:32
uint32_t string_to_ipv4(std::string_view str)
Definition parsing.cpp:156
uint16_t to_uint16(std::string_view str)
Definition parsing.cpp:22
std::map< std::string, std::string > read_cfg(std::istream &is)
Definition read_cfg.cpp:34
BOTAN_TEST_API std::map< std::string, std::string > read_kv(std::string_view kv)
Definition read_kv.cpp:13
std::vector< std::string > split_on(std::string_view str, char delim)
Definition parsing.cpp:111
std::string tolower_string(std::string_view in)
Definition parsing.cpp:196
std::string string_join(const std::vector< std::string > &strs, char delim)
Definition parsing.cpp:140
bool host_wildcard_match(std::string_view issued_, std::string_view host_)
Definition parsing.cpp:207
std::vector< std::string > parse_algorithm_name(std::string_view namex)
Definition parsing.cpp:57
std::string ipv4_to_string(uint32_t ip)
Definition parsing.cpp:181