9 #ifndef BITCOIN_UTIL_STRENCODINGS_H 10 #define BITCOIN_UTIL_STRENCODINGS_H 19 #define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0])) 38 std::vector<unsigned char>
ParseHex(
const char* psz);
39 std::vector<unsigned char>
ParseHex(
const std::string& str);
43 bool IsHex(
const std::string& str);
48 std::vector<unsigned char>
DecodeBase64(
const char* p,
bool* pf_invalid =
nullptr);
49 std::string
DecodeBase64(
const std::string& str,
bool* pf_invalid =
nullptr);
50 std::string
EncodeBase64(
const unsigned char* pch,
size_t len);
52 std::vector<unsigned char>
DecodeBase32(
const char* p,
bool* pf_invalid =
nullptr);
53 std::string
DecodeBase32(
const std::string& str,
bool* pf_invalid =
nullptr);
54 std::string
EncodeBase32(
const unsigned char* pch,
size_t len);
57 void SplitHostPort(std::string in,
int &portOut, std::string &hostOut);
62 int atoi(
const std::string& str);
71 return c >=
'0' && c <=
'9';
85 constexpr
inline bool IsSpace(
char c) noexcept {
86 return c ==
' ' || c ==
'\f' || c ==
'\n' || c ==
'\r' || c ==
'\t' || c ==
'\v';
125 std::string
HexStr(
const T itbegin,
const T itend)
128 static const char hexmap[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
129 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f' };
130 rv.reserve(std::distance(itbegin, itend) * 2);
131 for(T
it = itbegin;
it < itend; ++
it)
133 unsigned char val = (
unsigned char)(*
it);
134 rv.push_back(hexmap[val>>4]);
135 rv.push_back(hexmap[val&15]);
143 return HexStr(vch.begin(), vch.end());
157 template <
typename T>
160 if (b.size() == 0)
return a.size() == 0;
161 size_t accumulator = a.size() ^ b.size();
162 for (
size_t i = 0; i < a.size(); i++)
163 accumulator |= a[i] ^ b[i%b.size()];
164 return accumulator == 0;
175 template<
int frombits,
int tobits,
bool pad,
typename O,
typename I>
179 constexpr
size_t maxv = (1 << tobits) - 1;
180 constexpr
size_t max_acc = (1 << (frombits + tobits - 1)) - 1;
182 acc = ((acc << frombits) | *
it) & max_acc;
184 while (bits >= tobits) {
186 outfn((acc >> bits) & maxv);
191 if (bits) outfn((acc << (tobits - bits)) & maxv);
192 }
else if (bits >= frombits || ((acc << (tobits - bits)) & maxv)) {
208 return (c >=
'A' && c <=
'Z' ? (c -
'A') +
'a' : c);
229 return (c >=
'a' && c <=
'z' ? (c -
'a') +
'A' : c);
242 #endif // BITCOIN_UTIL_STRENCODINGS_H bool TimingResistantEqual(const T &a, const T &b)
Definition: strencodings.h:158
The full set of allowed chars.
Definition: strencodings.h:24
constexpr char ToUpper(char c)
Definition: strencodings.h:227
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
Definition: strencodings.cpp:109
end
Definition: optimize-pngs.py:40
std::vector< unsigned char > ParseHex(const char *psz)
Definition: strencodings.cpp:83
void Downcase(std::string &str)
Definition: strencodings.cpp:549
signed char HexDigit(char c)
Definition: strencodings.cpp:55
constexpr bool IsDigit(char c)
Definition: strencodings.h:69
NODISCARD bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
Definition: strencodings.cpp:457
bool IsHex(const std::string &str)
Definition: strencodings.cpp:60
std::string i64tostr(int64_t n)
Definition: strencodings.cpp:397
std::vector< unsigned char > DecodeBase64(const char *p, bool *pf_invalid=nullptr)
Definition: strencodings.cpp:144
indent
Definition: gen_key_io_test_vectors.py:247
std::string EncodeBase32(const unsigned char *pch, size_t len)
Definition: strencodings.cpp:197
unsigned int uint32_t
Definition: stdint.h:21
#define NODISCARD
Definition: attributes.h:18
unsigned long long uint64_t
Definition: stdint.h:22
SafeChars
Definition: strencodings.h:22
std::string Capitalize(std::string str)
Definition: strencodings.cpp:554
std::string SanitizeString(const std::string &str, int rule=SAFE_CHARS_DEFAULT)
Definition: strencodings.cpp:26
bool ConvertBits(const O &outfn, I it, I end)
Definition: strencodings.h:176
Chars allowed in filenames.
Definition: strencodings.h:26
NODISCARD bool ParseUInt64(const std::string &str, uint64_t *out)
Definition: strencodings.cpp:325
NODISCARD bool ParseUInt32(const std::string &str, uint32_t *out)
Definition: strencodings.cpp:308
std::string itostr(int n)
Definition: strencodings.cpp:402
constexpr bool IsSpace(char c) noexcept
Definition: strencodings.h:85
bool IsHexNumber(const std::string &str)
Definition: strencodings.cpp:70
NODISCARD bool ParseInt64(const std::string &str, int64_t *out)
Definition: univalue_get.cpp:46
int64_t atoi64(const char *psz)
Definition: strencodings.cpp:407
std::string HexStr(const T itbegin, const T itend)
Definition: strencodings.h:125
std::string EncodeBase64(const unsigned char *pch, size_t len)
Definition: strencodings.cpp:128
signed long long int64_t
Definition: stdint.h:18
int atoi(const std::string &str)
Definition: strencodings.cpp:425
constexpr char ToLower(char c)
Definition: strencodings.h:206
signed int int32_t
Definition: stdint.h:17
Chars allowed in URIs (RFC 3986)
Definition: strencodings.h:27
std::string FormatParagraph(const std::string &in, size_t width=79, size_t indent=0)
Definition: strencodings.cpp:356
NODISCARD bool ParseInt32(const std::string &str, int32_t *out)
Definition: univalue_get.cpp:30
auto it
Definition: validation.cpp:360
BIP-0014 subset.
Definition: strencodings.h:25
std::vector< unsigned char > DecodeBase32(const char *p, bool *pf_invalid=nullptr)
Definition: strencodings.cpp:213
NODISCARD bool ParseDouble(const std::string &str, double *out)
Definition: univalue_get.cpp:61