rippled
Loading...
Searching...
No Matches
StringUtilities.h
1#ifndef XRPL_BASICS_STRINGUTILITIES_H_INCLUDED
2#define XRPL_BASICS_STRINGUTILITIES_H_INCLUDED
3
4#include <xrpl/basics/Blob.h>
5#include <xrpl/basics/strHex.h>
6
7#include <boost/format.hpp>
8#include <boost/utility/string_view.hpp>
9
10#include <array>
11#include <cstdint>
12#include <optional>
13#include <string>
14
15namespace ripple {
16
28sqlBlobLiteral(Blob const& blob);
29
30template <class Iterator>
32strUnHex(std::size_t strSize, Iterator begin, Iterator end)
33{
34 static constexpr std::array<int, 256> const unxtab = []() {
36
37 for (auto& x : t)
38 x = -1;
39
40 for (int i = 0; i < 10; ++i)
41 t['0' + i] = i;
42
43 for (int i = 0; i < 6; ++i)
44 {
45 t['A' + i] = 10 + i;
46 t['a' + i] = 10 + i;
47 }
48
49 return t;
50 }();
51
52 Blob out;
53
54 out.reserve((strSize + 1) / 2);
55
56 auto iter = begin;
57
58 if (strSize & 1)
59 {
60 int c = unxtab[*iter++];
61
62 if (c < 0)
63 return {};
64
65 out.push_back(c);
66 }
67
68 while (iter != end)
69 {
70 int cHigh = unxtab[*iter++];
71
72 if (cHigh < 0)
73 return {};
74
75 int cLow = unxtab[*iter++];
76
77 if (cLow < 0)
78 return {};
79
80 out.push_back(static_cast<unsigned char>((cHigh << 4) | cLow));
81 }
82
83 return {std::move(out)};
84}
85
87strUnHex(std::string const& strSrc)
88{
89 return strUnHex(strSrc.size(), strSrc.cbegin(), strSrc.cend());
90}
91
94{
95 return strUnHex(strSrc.size(), strSrc.cbegin(), strSrc.cend());
96}
97
99{
100 explicit parsedURL() = default;
101
108
109 bool
110 operator==(parsedURL const& other) const
111 {
112 return scheme == other.scheme && domain == other.domain &&
113 port == other.port && path == other.path;
114 }
115};
116
117bool
118parseUrl(parsedURL& pUrl, std::string const& strUrl);
119
122
124to_uint64(std::string const& s);
125
132bool
134
135} // namespace ripple
136
137#endif
T cbegin(T... args)
T cend(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
std::string trim_whitespace(std::string str)
std::optional< std::uint64_t > to_uint64(std::string const &s)
bool parseUrl(parsedURL &pUrl, std::string const &strUrl)
std::string sqlBlobLiteral(Blob const &blob)
Format arbitrary binary data as an SQLite "blob literal".
std::optional< Blob > strViewUnHex(std::string_view strSrc)
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition Blob.h:11
bool isProperlyFormedTomlDomain(std::string_view domain)
Determines if the given string looks like a TOML-file hosting domain.
T reserve(T... args)
T size(T... args)
parsedURL()=default
bool operator==(parsedURL const &other) const
std::optional< std::uint16_t > port