9 #ifndef FABCOIN_UTILSTRENCODINGS_H 10 #define FABCOIN_UTILSTRENCODINGS_H 16 #define BEGIN(a) ((char*)&(a)) 17 #define END(a) ((char*)&((&(a))[1])) 18 #define UBEGIN(a) ((unsigned char*)&(a)) 19 #define UEND(a) ((unsigned char*)&((&(a))[1])) 20 #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* pfInvalid =
nullptr);
50 std::string
EncodeBase64(
const unsigned char* pch,
size_t len);
52 std::vector<unsigned char>
DecodeBase32(
const char* p,
bool* pfInvalid =
nullptr);
54 std::string
EncodeBase32(
const unsigned char* pch,
size_t len);
57 void SplitHostPort(std::string in,
int &portOut, std::string &hostOut);
60 int64_t
atoi64(
const char* psz);
61 int64_t
atoi64(
const std::string& str);
62 int atoi(
const std::string& str);
69 bool ParseInt32(
const std::string& str, int32_t *out);
76 bool ParseInt64(
const std::string& str, int64_t *out);
83 bool ParseUInt32(
const std::string& str, uint32_t *out);
90 bool ParseUInt64(
const std::string& str, uint64_t *out);
97 bool ParseDouble(
const std::string& str,
double *out);
100 std::string
HexStr(
const T itbegin,
const T itend,
bool fSpaces=
false)
103 static const char hexmap[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
104 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f' };
105 rv.reserve((itend-itbegin)*3);
106 for(
T it = itbegin; it < itend; ++it)
108 unsigned char val = (
unsigned char)(*it);
109 if(fSpaces && it != itbegin)
111 rv.push_back(hexmap[val>>4]);
112 rv.push_back(hexmap[val&15]);
119 inline std::string
HexStr(
const T& vch,
bool fSpaces=
false)
121 return HexStr(vch.begin(), vch.end(), fSpaces);
128 std::string
FormatParagraph(
const std::string& in,
size_t width = 79,
size_t indent = 0);
135 template <
typename T>
138 if (b.size() == 0)
return a.size() == 0;
139 size_t accumulator = a.size() ^ b.size();
140 for (
size_t i = 0; i < a.size(); i++)
141 accumulator |= a[i] ^ b[i%b.size()];
142 return accumulator == 0;
150 bool ParseFixedPoint(
const std::string &val,
int decimals, int64_t *amount_out);
152 #endif // FABCOIN_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...