10 #ifndef RAVEN_UTILSTRENCODINGS_H 11 #define RAVEN_UTILSTRENCODINGS_H 17 #define BEGIN(a) ((char*)&(a)) 18 #define END(a) ((char*)&((&(a))[1])) 19 #define UBEGIN(a) ((unsigned char*)&(a)) 20 #define UEND(a) ((unsigned char*)&((&(a))[1])) 21 #define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0])) 39 std::vector<unsigned char>
ParseHex(
const char* psz);
40 std::vector<unsigned char>
ParseHex(
const std::string& str);
44 bool IsHex(
const std::string& str);
49 std::vector<unsigned char>
DecodeBase64(
const char* p,
bool* pfInvalid =
nullptr);
51 std::string
EncodeBase64(
const unsigned char* pch,
size_t len);
53 std::vector<unsigned char>
DecodeBase32(
const char* p,
bool* pfInvalid =
nullptr);
55 std::string
EncodeBase32(
const unsigned char* pch,
size_t len);
58 void SplitHostPort(std::string in,
int &portOut, std::string &hostOut);
61 int64_t
atoi64(
const char* psz);
62 int64_t
atoi64(
const std::string& str);
63 int atoi(
const std::string& str);
70 bool ParseInt32(
const std::string& str, int32_t *out);
77 bool ParseInt64(
const std::string& str, int64_t *out);
84 bool ParseUInt32(
const std::string& str, uint32_t *out);
91 bool ParseUInt64(
const std::string& str, uint64_t *out);
98 bool ParseDouble(
const std::string& str,
double *out);
101 std::string
HexStr(
const T itbegin,
const T itend,
bool fSpaces=
false)
104 static const char hexmap[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
105 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f' };
106 rv.reserve((itend-itbegin)*3);
107 for(T it = itbegin; it < itend; ++it)
109 unsigned char val = (
unsigned char)(*it);
110 if(fSpaces && it != itbegin)
112 rv.push_back(hexmap[val>>4]);
113 rv.push_back(hexmap[val&15]);
120 inline std::string
HexStr(
const T& vch,
bool fSpaces=
false)
122 return HexStr(vch.begin(), vch.end(), fSpaces);
129 std::string
FormatParagraph(
const std::string& in,
size_t width = 79,
size_t indent = 0);
136 template <
typename T>
139 if (b.size() == 0)
return a.size() == 0;
140 size_t accumulator = a.size() ^ b.size();
141 for (
size_t i = 0; i < a.size(); i++)
142 accumulator |= a[i] ^ b[i%b.size()];
143 return accumulator == 0;
151 bool ParseFixedPoint(
const std::string &val,
int decimals, int64_t *amount_out);
153 #endif // RAVEN_UTILSTRENCODINGS_H std::string itostr(int n)
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
The full set of allowed chars.
bool ParseDouble(const std::string &str, double *out)
Convert string to double with strict parse error feedback.
std::string EncodeBase64(const unsigned char *pch, size_t len)
bool ParseInt32(const std::string &str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
int64_t atoi64(const char *psz)
std::vector< unsigned char > DecodeBase32(const char *p, bool *pfInvalid=nullptr)
signed char HexDigit(char c)
std::vector< unsigned char > ParseHex(const char *psz)
std::string i64tostr(int64_t n)
bool ParseUInt32(const std::string &str, uint32_t *out)
Convert decimal string to unsigned 32-bit integer with strict parse error feedback.
bool TimingResistantEqual(const T &a, const T &b)
Timing-attack-resistant comparison.
std::string SanitizeString(const std::string &str, int rule=SAFE_CHARS_DEFAULT)
Remove unsafe chars.
Chars allowed in filenames.
std::vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid=nullptr)
bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
bool IsHex(const std::string &str)
bool ParseInt64(const std::string &str, int64_t *out)
Convert string to signed 64-bit integer with strict parse error feedback.
bool IsHexNumber(const std::string &str)
Return true if the string is a hex number, optionally prefixed with "0x".
bool ParseUInt64(const std::string &str, uint64_t *out)
Convert decimal string to unsigned 64-bit integer with strict parse error feedback.
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
std::string EncodeBase32(const unsigned char *pch, size_t len)
SafeChars
Used by SanitizeString()
int atoi(const std::string &str)
std::string FormatParagraph(const std::string &in, size_t width=79, size_t indent=0)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line...