9 #ifndef BITCOIN_UTILSTRENCODINGS_H 10 #define BITCOIN_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])) 23 #define PAIRTYPE(t1, t2) std::pair<t1, t2> 40 std::vector<unsigned char>
ParseHex(
const char* psz);
41 std::vector<unsigned char>
ParseHex(
const std::string& str);
43 bool IsHex(
const std::string& str);
44 std::vector<unsigned char>
DecodeBase64(
const char*
p,
bool* pfInvalid = NULL);
46 std::string
EncodeBase64(
const unsigned char* pch,
size_t len);
48 std::vector<unsigned char>
DecodeBase32(
const char*
p,
bool* pfInvalid = NULL);
50 std::string
EncodeBase32(
const unsigned char* pch,
size_t len);
55 int64_t
atoi64(
const char* psz);
56 int64_t
atoi64(
const std::string& str);
57 int atoi(
const std::string& str);
81 std::string
HexStr(
const T itbegin,
const T itend,
bool fSpaces=
false)
84 static const char hexmap[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
85 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f' };
86 rv.reserve((itend-itbegin)*3);
87 for(T it = itbegin; it < itend; ++it)
89 unsigned char val = (
unsigned char)(*it);
90 if(fSpaces && it != itbegin)
92 rv.push_back(hexmap[val>>4]);
93 rv.push_back(hexmap[val&15]);
100 inline std::string
HexStr(
const T& vch,
bool fSpaces=
false)
102 return HexStr(vch.begin(), vch.end(), fSpaces);
116 template <
typename T>
119 if (b.size() == 0)
return a.size() == 0;
120 size_t accumulator = a.size() ^ b.size();
121 for (
size_t i = 0; i < a.size(); i++)
122 accumulator |= a[i] ^ b[i%b.size()];
123 return accumulator == 0;
131 bool ParseFixedPoint(
const std::string &val,
int decimals, int64_t *amount_out);
133 #endif // BITCOIN_UTILSTRENCODINGS_H std::string itostr(int n)
std::vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid=NULL)
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)
std::string EncodeBase64(const unsigned char *pch, size_t len)
bool ParseInt32(const std::string &str, int32_t *out)
int64_t atoi64(const char *psz)
signed char HexDigit(char c)
std::vector< unsigned char > ParseHex(const char *psz)
std::string i64tostr(int64_t n)
bool TimingResistantEqual(const T &a, const T &b)
std::string SanitizeString(const std::string &str, int rule=SAFE_CHARS_DEFAULT)
bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
bool IsHex(const std::string &str)
bool ParseInt64(const std::string &str, int64_t *out)
std::vector< unsigned char > DecodeBase32(const char *p, bool *pfInvalid=NULL)
std::string EncodeBase32(const unsigned char *pch, size_t len)
int atoi(const std::string &str)
std::string FormatParagraph(const std::string &in, size_t width=79, size_t indent=0)