BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
utilstrencodings.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <utilstrencodings.h>
7 
8 #include <tinyformat.h>
9 
10 #include <algorithm>
11 #include <cstdlib>
12 #include <cstring>
13 #include <errno.h>
14 #include <limits>
15 
16 static const std::string CHARS_ALPHA_NUM = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
17 
18 static const std::string SAFE_CHARS[] =
19 {
20  CHARS_ALPHA_NUM + " .,;-_/:?@()", // SAFE_CHARS_DEFAULT
21  CHARS_ALPHA_NUM + " .,;-_?@", // SAFE_CHARS_UA_COMMENT
22  CHARS_ALPHA_NUM + ".-_", // SAFE_CHARS_FILENAME
23 };
24 
25 std::string SanitizeString(const std::string& str, int rule)
26 {
27  std::string strResult;
28  for (std::string::size_type i = 0; i < str.size(); i++)
29  {
30  if (SAFE_CHARS[rule].find(str[i]) != std::string::npos)
31  strResult.push_back(str[i]);
32  }
33  return strResult;
34 }
35 
36 const signed char p_util_hexdigit[256] =
37 { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
38  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
39  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
40  0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
41  -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
42  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
43  -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
44  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
45  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
46  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
47  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
48  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
49  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
50  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
51  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
52  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, };
53 
54 signed char HexDigit(char c)
55 {
56  return p_util_hexdigit[(unsigned char)c];
57 }
58 
59 bool IsHex(const std::string& str)
60 {
61  for(std::string::const_iterator it(str.begin()); it != str.end(); ++it)
62  {
63  if (HexDigit(*it) < 0)
64  return false;
65  }
66  return (str.size() > 0) && (str.size()%2 == 0);
67 }
68 
69 bool IsHexNumber(const std::string& str)
70 {
71  size_t starting_location = 0;
72  if (str.size() > 2 && *str.begin() == '0' && *(str.begin()+1) == 'x') {
73  starting_location = 2;
74  }
75  for (const char c : str.substr(starting_location)) {
76  if (HexDigit(c) < 0) return false;
77  }
78  // Return false for empty string or "0x".
79  return (str.size() > starting_location);
80 }
81 
82 std::vector<unsigned char> ParseHex(const char* psz)
83 {
84  // convert hex dump to vector
85  std::vector<unsigned char> vch;
86  while (true)
87  {
88  while (IsSpace(*psz))
89  psz++;
90  signed char c = HexDigit(*psz++);
91  if (c == (signed char)-1)
92  break;
93  unsigned char n = (c << 4);
94  c = HexDigit(*psz++);
95  if (c == (signed char)-1)
96  break;
97  n |= c;
98  vch.push_back(n);
99  }
100  return vch;
101 }
102 
103 std::vector<unsigned char> ParseHex(const std::string& str)
104 {
105  return ParseHex(str.c_str());
106 }
107 
108 void SplitHostPort(std::string in, int &portOut, std::string &hostOut) {
109  size_t colon = in.find_last_of(':');
110  // if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator
111  bool fHaveColon = colon != in.npos;
112  bool fBracketed = fHaveColon && (in[0]=='[' && in[colon-1]==']'); // if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is safe
113  bool fMultiColon = fHaveColon && (in.find_last_of(':',colon-1) != in.npos);
114  if (fHaveColon && (colon==0 || fBracketed || !fMultiColon)) {
115  int32_t n;
116  if (ParseInt32(in.substr(colon + 1), &n) && n > 0 && n < 0x10000) {
117  in = in.substr(0, colon);
118  portOut = n;
119  }
120  }
121  if (in.size()>0 && in[0] == '[' && in[in.size()-1] == ']')
122  hostOut = in.substr(1, in.size()-2);
123  else
124  hostOut = in;
125 }
126 
127 std::string EncodeBase64(const unsigned char* pch, size_t len)
128 {
129  static const char *pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
130 
131  std::string str;
132  str.reserve(((len + 2) / 3) * 4);
133  ConvertBits<8, 6, true>([&](int v) { str += pbase64[v]; }, pch, pch + len);
134  while (str.size() % 4) str += '=';
135  return str;
136 }
137 
138 std::string EncodeBase64(const std::string& str)
139 {
140  return EncodeBase64((const unsigned char*)str.c_str(), str.size());
141 }
142 
143 std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
144 {
145  static const int decode64_table[256] =
146  {
147  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
148  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
149  -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1,
150  -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
151  15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28,
152  29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
153  49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
154  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
155  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
156  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
157  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
159  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
160  };
161 
162  const char* e = p;
163  std::vector<uint8_t> val;
164  val.reserve(strlen(p));
165  while (*p != 0) {
166  int x = decode64_table[(unsigned char)*p];
167  if (x == -1) break;
168  val.push_back(x);
169  ++p;
170  }
171 
172  std::vector<unsigned char> ret;
173  ret.reserve((val.size() * 3) / 4);
174  bool valid = ConvertBits<6, 8, false>([&](unsigned char c) { ret.push_back(c); }, val.begin(), val.end());
175 
176  const char* q = p;
177  while (valid && *p != 0) {
178  if (*p != '=') {
179  valid = false;
180  break;
181  }
182  ++p;
183  }
184  valid = valid && (p - e) % 4 == 0 && p - q < 4;
185  if (pfInvalid) *pfInvalid = !valid;
186 
187  return ret;
188 }
189 
190 std::string DecodeBase64(const std::string& str)
191 {
192  std::vector<unsigned char> vchRet = DecodeBase64(str.c_str());
193  return std::string((const char*)vchRet.data(), vchRet.size());
194 }
195 
196 std::string EncodeBase32(const unsigned char* pch, size_t len)
197 {
198  static const char *pbase32 = "abcdefghijklmnopqrstuvwxyz234567";
199 
200  std::string str;
201  str.reserve(((len + 4) / 5) * 8);
202  ConvertBits<8, 5, true>([&](int v) { str += pbase32[v]; }, pch, pch + len);
203  while (str.size() % 8) str += '=';
204  return str;
205 }
206 
207 std::string EncodeBase32(const std::string& str)
208 {
209  return EncodeBase32((const unsigned char*)str.c_str(), str.size());
210 }
211 
212 std::vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid)
213 {
214  static const int decode32_table[256] =
215  {
216  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
217  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
218  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1,
219  -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
220  15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 0, 1, 2,
221  3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
222  23, 24, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
223  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
224  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
225  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
226  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
227  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
228  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
229  };
230 
231  const char* e = p;
232  std::vector<uint8_t> val;
233  val.reserve(strlen(p));
234  while (*p != 0) {
235  int x = decode32_table[(unsigned char)*p];
236  if (x == -1) break;
237  val.push_back(x);
238  ++p;
239  }
240 
241  std::vector<unsigned char> ret;
242  ret.reserve((val.size() * 5) / 8);
243  bool valid = ConvertBits<5, 8, false>([&](unsigned char c) { ret.push_back(c); }, val.begin(), val.end());
244 
245  const char* q = p;
246  while (valid && *p != 0) {
247  if (*p != '=') {
248  valid = false;
249  break;
250  }
251  ++p;
252  }
253  valid = valid && (p - e) % 8 == 0 && p - q < 8;
254  if (pfInvalid) *pfInvalid = !valid;
255 
256  return ret;
257 }
258 
259 std::string DecodeBase32(const std::string& str)
260 {
261  std::vector<unsigned char> vchRet = DecodeBase32(str.c_str());
262  return std::string((const char*)vchRet.data(), vchRet.size());
263 }
264 
265 static bool ParsePrechecks(const std::string& str)
266 {
267  if (str.empty()) // No empty string allowed
268  return false;
269  if (str.size() >= 1 && (IsSpace(str[0]) || IsSpace(str[str.size()-1]))) // No padding allowed
270  return false;
271  if (str.size() != strlen(str.c_str())) // No embedded NUL characters allowed
272  return false;
273  return true;
274 }
275 
276 bool ParseInt32(const std::string& str, int32_t *out)
277 {
278  if (!ParsePrechecks(str))
279  return false;
280  char *endp = nullptr;
281  errno = 0; // strtol will not set errno if valid
282  long int n = strtol(str.c_str(), &endp, 10);
283  if(out) *out = (int32_t)n;
284  // Note that strtol returns a *long int*, so even if strtol doesn't report an over/underflow
285  // we still have to check that the returned value is within the range of an *int32_t*. On 64-bit
286  // platforms the size of these types may be different.
287  return endp && *endp == 0 && !errno &&
288  n >= std::numeric_limits<int32_t>::min() &&
289  n <= std::numeric_limits<int32_t>::max();
290 }
291 
292 bool ParseInt64(const std::string& str, int64_t *out)
293 {
294  if (!ParsePrechecks(str))
295  return false;
296  char *endp = nullptr;
297  errno = 0; // strtoll will not set errno if valid
298  long long int n = strtoll(str.c_str(), &endp, 10);
299  if(out) *out = (int64_t)n;
300  // Note that strtoll returns a *long long int*, so even if strtol doesn't report an over/underflow
301  // we still have to check that the returned value is within the range of an *int64_t*.
302  return endp && *endp == 0 && !errno &&
303  n >= std::numeric_limits<int64_t>::min() &&
304  n <= std::numeric_limits<int64_t>::max();
305 }
306 
307 bool ParseUInt32(const std::string& str, uint32_t *out)
308 {
309  if (!ParsePrechecks(str))
310  return false;
311  if (str.size() >= 1 && str[0] == '-') // Reject negative values, unfortunately strtoul accepts these by default if they fit in the range
312  return false;
313  char *endp = nullptr;
314  errno = 0; // strtoul will not set errno if valid
315  unsigned long int n = strtoul(str.c_str(), &endp, 10);
316  if(out) *out = (uint32_t)n;
317  // Note that strtoul returns a *unsigned long int*, so even if it doesn't report an over/underflow
318  // we still have to check that the returned value is within the range of an *uint32_t*. On 64-bit
319  // platforms the size of these types may be different.
320  return endp && *endp == 0 && !errno &&
321  n <= std::numeric_limits<uint32_t>::max();
322 }
323 
324 bool ParseUInt64(const std::string& str, uint64_t *out)
325 {
326  if (!ParsePrechecks(str))
327  return false;
328  if (str.size() >= 1 && str[0] == '-') // Reject negative values, unfortunately strtoull accepts these by default if they fit in the range
329  return false;
330  char *endp = nullptr;
331  errno = 0; // strtoull will not set errno if valid
332  unsigned long long int n = strtoull(str.c_str(), &endp, 10);
333  if(out) *out = (uint64_t)n;
334  // Note that strtoull returns a *unsigned long long int*, so even if it doesn't report an over/underflow
335  // we still have to check that the returned value is within the range of an *uint64_t*.
336  return endp && *endp == 0 && !errno &&
337  n <= std::numeric_limits<uint64_t>::max();
338 }
339 
340 
341 bool ParseDouble(const std::string& str, double *out)
342 {
343  if (!ParsePrechecks(str))
344  return false;
345  if (str.size() >= 2 && str[0] == '0' && str[1] == 'x') // No hexadecimal floats allowed
346  return false;
347  std::istringstream text(str);
348  text.imbue(std::locale::classic());
349  double result;
350  text >> result;
351  if(out) *out = result;
352  return text.eof() && !text.fail();
353 }
354 
355 std::string FormatParagraph(const std::string& in, size_t width, size_t indent)
356 {
357  std::stringstream out;
358  size_t ptr = 0;
359  size_t indented = 0;
360  while (ptr < in.size())
361  {
362  size_t lineend = in.find_first_of('\n', ptr);
363  if (lineend == std::string::npos) {
364  lineend = in.size();
365  }
366  const size_t linelen = lineend - ptr;
367  const size_t rem_width = width - indented;
368  if (linelen <= rem_width) {
369  out << in.substr(ptr, linelen + 1);
370  ptr = lineend + 1;
371  indented = 0;
372  } else {
373  size_t finalspace = in.find_last_of(" \n", ptr + rem_width);
374  if (finalspace == std::string::npos || finalspace < ptr) {
375  // No place to break; just include the entire word and move on
376  finalspace = in.find_first_of("\n ", ptr);
377  if (finalspace == std::string::npos) {
378  // End of the string, just add it and break
379  out << in.substr(ptr);
380  break;
381  }
382  }
383  out << in.substr(ptr, finalspace - ptr) << "\n";
384  if (in[finalspace] == '\n') {
385  indented = 0;
386  } else if (indent) {
387  out << std::string(indent, ' ');
388  indented = indent;
389  }
390  ptr = finalspace + 1;
391  }
392  }
393  return out.str();
394 }
395 
396 std::string i64tostr(int64_t n)
397 {
398  return strprintf("%d", n);
399 }
400 
401 std::string itostr(int n)
402 {
403  return strprintf("%d", n);
404 }
405 
406 int64_t atoi64(const char* psz)
407 {
408 #ifdef _MSC_VER
409  return _atoi64(psz);
410 #else
411  return strtoll(psz, nullptr, 10);
412 #endif
413 }
414 
415 int64_t atoi64(const std::string& str)
416 {
417 #ifdef _MSC_VER
418  return _atoi64(str.c_str());
419 #else
420  return strtoll(str.c_str(), nullptr, 10);
421 #endif
422 }
423 
424 int atoi(const std::string& str)
425 {
426  return atoi(str.c_str());
427 }
428 
437 static const int64_t UPPER_BOUND = 1000000000000000000LL - 1LL;
438 
440 static inline bool ProcessMantissaDigit(char ch, int64_t &mantissa, int &mantissa_tzeros)
441 {
442  if(ch == '0')
443  ++mantissa_tzeros;
444  else {
445  for (int i=0; i<=mantissa_tzeros; ++i) {
446  if (mantissa > (UPPER_BOUND / 10LL))
447  return false; /* overflow */
448  mantissa *= 10;
449  }
450  mantissa += ch - '0';
451  mantissa_tzeros = 0;
452  }
453  return true;
454 }
455 
456 bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
457 {
458  int64_t mantissa = 0;
459  int64_t exponent = 0;
460  int mantissa_tzeros = 0;
461  bool mantissa_sign = false;
462  bool exponent_sign = false;
463  int ptr = 0;
464  int end = val.size();
465  int point_ofs = 0;
466 
467  if (ptr < end && val[ptr] == '-') {
468  mantissa_sign = true;
469  ++ptr;
470  }
471  if (ptr < end)
472  {
473  if (val[ptr] == '0') {
474  /* pass single 0 */
475  ++ptr;
476  } else if (val[ptr] >= '1' && val[ptr] <= '9') {
477  while (ptr < end && IsDigit(val[ptr])) {
478  if (!ProcessMantissaDigit(val[ptr], mantissa, mantissa_tzeros))
479  return false; /* overflow */
480  ++ptr;
481  }
482  } else return false; /* missing expected digit */
483  } else return false; /* empty string or loose '-' */
484  if (ptr < end && val[ptr] == '.')
485  {
486  ++ptr;
487  if (ptr < end && IsDigit(val[ptr]))
488  {
489  while (ptr < end && IsDigit(val[ptr])) {
490  if (!ProcessMantissaDigit(val[ptr], mantissa, mantissa_tzeros))
491  return false; /* overflow */
492  ++ptr;
493  ++point_ofs;
494  }
495  } else return false; /* missing expected digit */
496  }
497  if (ptr < end && (val[ptr] == 'e' || val[ptr] == 'E'))
498  {
499  ++ptr;
500  if (ptr < end && val[ptr] == '+')
501  ++ptr;
502  else if (ptr < end && val[ptr] == '-') {
503  exponent_sign = true;
504  ++ptr;
505  }
506  if (ptr < end && IsDigit(val[ptr])) {
507  while (ptr < end && IsDigit(val[ptr])) {
508  if (exponent > (UPPER_BOUND / 10LL))
509  return false; /* overflow */
510  exponent = exponent * 10 + val[ptr] - '0';
511  ++ptr;
512  }
513  } else return false; /* missing expected digit */
514  }
515  if (ptr != end)
516  return false; /* trailing garbage */
517 
518  /* finalize exponent */
519  if (exponent_sign)
520  exponent = -exponent;
521  exponent = exponent - point_ofs + mantissa_tzeros;
522 
523  /* finalize mantissa */
524  if (mantissa_sign)
525  mantissa = -mantissa;
526 
527  /* convert to one 64-bit fixed-point value */
528  exponent += decimals;
529  if (exponent < 0)
530  return false; /* cannot represent values smaller than 10^-decimals */
531  if (exponent >= 18)
532  return false; /* cannot represent values larger than or equal to 10^(18-decimals) */
533 
534  for (int i=0; i < exponent; ++i) {
535  if (mantissa > (UPPER_BOUND / 10LL) || mantissa < -(UPPER_BOUND / 10LL))
536  return false; /* overflow */
537  mantissa *= 10;
538  }
539  if (mantissa > UPPER_BOUND || mantissa < -UPPER_BOUND)
540  return false; /* overflow */
541 
542  if (amount_out)
543  *amount_out = mantissa;
544 
545  return true;
546 }
547 
548 bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath)
549 {
550  std::stringstream ss(keypath_str);
551  std::string item;
552  bool first = true;
553  while (std::getline(ss, item, '/')) {
554  if (item.compare("m") == 0) {
555  if (first) {
556  first = false;
557  continue;
558  }
559  return false;
560  }
561  // Finds whether it is hardened
562  uint32_t path = 0;
563  size_t pos = item.find("'");
564  if (pos != std::string::npos) {
565  // The hardened tick can only be in the last index of the string
566  if (pos != item.size() - 1) {
567  return false;
568  }
569  path |= 0x80000000;
570  item = item.substr(0, item.size() - 1); // Drop the last character which is the hardened tick
571  }
572 
573  // Ensure this is only numbers
574  if (item.find_first_not_of( "0123456789" ) != std::string::npos) {
575  return false;
576  }
577  uint32_t number;
578  if (!ParseUInt32(item, &number)) {
579  return false;
580  }
581  path |= number;
582 
583  keypath.push_back(path);
584  first = false;
585  }
586  return true;
587 }
588 
589 void Downcase(std::string& str)
590 {
591  std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c){return ToLower(c);});
592 }
593 
594 std::string Capitalize(std::string str)
595 {
596  if (str.empty()) return str;
597  str[0] = ToUpper(str.front());
598  return str;
599 }
constexpr unsigned char ToLower(unsigned char c)
Converts the given character to its lowercase equivalent.
bool IsHexNumber(const std::string &str)
Return true if the string is a hex number, optionally prefixed with "0x".
std::vector< unsigned char > DecodeBase64(const char *p, bool *pfInvalid)
void Downcase(std::string &str)
Converts the given string to its lowercase equivalent.
#define strprintf
Definition: tinyformat.h:1066
UniValue ret(UniValue::VARR)
Definition: rpcwallet.cpp:1140
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.
bool ParseDouble(const std::string &str, double *out)
Convert string to double with strict parse error feedback.
std::string Capitalize(std::string str)
Capitalizes the first character of the given string.
bool ParseUInt64(const std::string &str, uint64_t *out)
Convert decimal string to unsigned 64-bit integer with strict parse error feedback.
constexpr unsigned char ToUpper(unsigned char c)
Converts the given character to its uppercase equivalent.
bool ParseInt64(const std::string &str, int64_t *out)
Convert string to signed 64-bit integer with strict parse error feedback.
bool push_back(const UniValue &val)
Definition: univalue.cpp:108
const signed char p_util_hexdigit[256]
bool ParseHDKeypath(const std::string &keypath_str, std::vector< uint32_t > &keypath)
Parse an HD keypaths like "m/7/0&#39;/2000".
bool ParseInt32(const std::string &str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
std::vector< unsigned char > DecodeBase32(const char *p, bool *pfInvalid)
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)
std::string FormatParagraph(const std::string &in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line...
auto end
Definition: rpcwallet.cpp:1068
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
bool ParseUInt32(const std::string &str, uint32_t *out)
Convert decimal string to unsigned 32-bit integer with strict parse error feedback.
int64_t atoi64(const char *psz)
std::string i64tostr(int64_t n)
std::string EncodeBase32(const unsigned char *pch, size_t len)
signed char HexDigit(char c)
std::string SanitizeString(const std::string &str, int rule)
Remove unsafe chars.
constexpr bool IsSpace(char c) noexcept
Tests if the given character is a whitespace character.
std::string itostr(int n)
int atoi(const std::string &str)
std::string EncodeBase64(const unsigned char *pch, size_t len)
std::vector< unsigned char > ParseHex(const char *psz)