 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
9 #ifndef BITCOIN_UTILSTRENCODINGS_H
10 #define BITCOIN_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]))
24 #define PAIRTYPE(t1, t2) std::pair<t1, t2>
42 std::vector<unsigned char>
ParseHex(
const char* psz);
43 std::vector<unsigned char>
ParseHex(
const std::string& str);
45 bool IsHex(
const std::string& str);
46 std::vector<unsigned char>
DecodeBase64(
const char* p,
bool* pfInvalid = NULL);
48 std::string
EncodeBase64(
const unsigned char* pch,
size_t len);
52 std::vector<unsigned char>
DecodeBase32(
const char* p,
bool* pfInvalid = NULL);
54 std::string
EncodeBase32(
const unsigned char* pch,
size_t len);
59 int64_t
atoi64(
const char* psz);
60 int64_t
atoi64(
const std::string& str);
61 int atoi(
const std::string& str);
68 bool ParseInt32(
const std::string& str, int32_t *out);
75 bool ParseInt64(
const std::string& str, int64_t *out);
82 bool ParseDouble(
const std::string& str,
double *out);
85 std::string
HexStr(
const T itbegin,
const T itend,
bool fSpaces =
false)
88 static const char hexmap[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
89 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'};
90 rv.reserve((itend - itbegin) * 3);
91 for (T it = itbegin; it < itend; ++it) {
92 unsigned char val = (
unsigned char)(*it);
93 if (fSpaces && it != itbegin)
95 rv.push_back(hexmap[val >> 4]);
96 rv.push_back(hexmap[val & 15]);
102 template <
typename T>
103 inline std::string
HexStr(
const T& vch,
bool fSpaces =
false)
105 return HexStr(vch.begin(), vch.end(), fSpaces);
111 std::string out =
"";
112 unsigned int s = in.size();
113 for (
unsigned int i = 0; i < s; i += 2) {
114 out += in.substr(s - i - 2, 2);
124 std::string
FormatParagraph(
const std::string in,
size_t width = 79,
size_t indent = 0);
131 template <
typename T>
134 if (
b.size() == 0)
return a.size() == 0;
135 size_t accumulator = a.size() ^
b.size();
136 for (
size_t i = 0; i < a.size(); i++)
137 accumulator |= a[i] ^
b[i %
b.size()];
138 return accumulator == 0;
141 #endif // BITCOIN_UTILSTRENCODINGS_H
std::string ReverseEndianString(std::string in)
Reverse the endianess of a string.
std::vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid=NULL)
std::vector< unsigned char > DecodeBase32(const char *p, bool *pfInvalid=NULL)
bool ParseDouble(const std::string &str, double *out)
Convert string to double with strict parse error feedback.
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.
int atoi(const std::string &str)
std::string EncodeBase32(const unsigned char *pch, size_t len)
bool TimingResistantEqual(const T &a, const T &b)
Timing-attack-resistant comparison.
@ SAFE_CHARS_DEFAULT
The full set of allowed chars.
SecureString EncodeBase64Secure(const SecureString &input)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
SafeChars
Used by SanitizeString()
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
std::string SanitizeString(const std::string &str, int rule=SAFE_CHARS_DEFAULT)
Remove unsafe chars.
bool ParseInt32(const std::string &str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
SecureString DecodeBase64Secure(const SecureString &input)
std::vector< unsigned char > ParseHex(const char *psz)
@ SAFE_CHARS_FILENAME
Chars allowed in filenames.
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.
signed char HexDigit(char c)
@ SAFE_CHARS_UA_COMMENT
BIP-0014 subset.
int64_t atoi64(const char *psz)
std::string i64tostr(int64_t n)
std::string EncodeBase64(const unsigned char *pch, size_t len)
std::string itostr(int n)