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