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