Bitcoin Core  24.99.0
P2P Digital Currency
strencodings.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2021 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 <span.h>
7 #include <util/strencodings.h>
8 
9 #include <array>
10 #include <cassert>
11 #include <cstring>
12 #include <limits>
13 #include <optional>
14 #include <ostream>
15 #include <string>
16 #include <vector>
17 
18 static const std::string CHARS_ALPHA_NUM = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
19 
20 static const std::string SAFE_CHARS[] =
21 {
22  CHARS_ALPHA_NUM + " .,;-_/:?@()", // SAFE_CHARS_DEFAULT
23  CHARS_ALPHA_NUM + " .,;-_?@", // SAFE_CHARS_UA_COMMENT
24  CHARS_ALPHA_NUM + ".-_", // SAFE_CHARS_FILENAME
25  CHARS_ALPHA_NUM + "!*'();:@&=+$,/?#[]-_.~%", // SAFE_CHARS_URI
26 };
27 
28 std::string SanitizeString(std::string_view str, int rule)
29 {
30  std::string result;
31  for (char c : str) {
32  if (SAFE_CHARS[rule].find(c) != std::string::npos) {
33  result.push_back(c);
34  }
35  }
36  return result;
37 }
38 
39 const signed char p_util_hexdigit[256] =
40 { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
41  -1,-1,-1,-1,-1,-1,-1,-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  0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
44  -1,0xa,0xb,0xc,0xd,0xe,0xf,-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,0xa,0xb,0xc,0xd,0xe,0xf,-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  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
54  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
55  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, };
56 
57 signed char HexDigit(char c)
58 {
59  return p_util_hexdigit[(unsigned char)c];
60 }
61 
62 bool IsHex(std::string_view str)
63 {
64  for (char c : str) {
65  if (HexDigit(c) < 0) return false;
66  }
67  return (str.size() > 0) && (str.size()%2 == 0);
68 }
69 
70 bool IsHexNumber(std::string_view str)
71 {
72  if (str.substr(0, 2) == "0x") str.remove_prefix(2);
73  for (char c : str) {
74  if (HexDigit(c) < 0) return false;
75  }
76  // Return false for empty string or "0x".
77  return str.size() > 0;
78 }
79 
80 template <typename Byte>
81 std::vector<Byte> ParseHex(std::string_view str)
82 {
83  std::vector<Byte> vch;
84  auto it = str.begin();
85  while (it != str.end() && it + 1 != str.end()) {
86  if (IsSpace(*it)) {
87  ++it;
88  continue;
89  }
90  auto c1 = HexDigit(*(it++));
91  auto c2 = HexDigit(*(it++));
92  if (c1 < 0 || c2 < 0) break;
93  vch.push_back(Byte(c1 << 4) | Byte(c2));
94  }
95  return vch;
96 }
97 template std::vector<std::byte> ParseHex(std::string_view);
98 template std::vector<uint8_t> ParseHex(std::string_view);
99 
100 void SplitHostPort(std::string_view in, uint16_t& portOut, std::string& hostOut)
101 {
102  size_t colon = in.find_last_of(':');
103  // if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator
104  bool fHaveColon = colon != in.npos;
105  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
106  bool fMultiColon{fHaveColon && colon != 0 && (in.find_last_of(':', colon - 1) != in.npos)};
107  if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) {
108  uint16_t n;
109  if (ParseUInt16(in.substr(colon + 1), &n)) {
110  in = in.substr(0, colon);
111  portOut = n;
112  }
113  }
114  if (in.size() > 0 && in[0] == '[' && in[in.size() - 1] == ']') {
115  hostOut = in.substr(1, in.size() - 2);
116  } else {
117  hostOut = in;
118  }
119 }
120 
122 {
123  static const char *pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
124 
125  std::string str;
126  str.reserve(((input.size() + 2) / 3) * 4);
127  ConvertBits<8, 6, true>([&](int v) { str += pbase64[v]; }, input.begin(), input.end());
128  while (str.size() % 4) str += '=';
129  return str;
130 }
131 
132 std::optional<std::vector<unsigned char>> DecodeBase64(std::string_view str)
133 {
134  static const int8_t decode64_table[256]{
135  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
136  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
137  -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1,
138  -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
139  15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28,
140  29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
141  49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
142  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
143  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
144  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
145  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
146  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
147  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
148  };
149 
150  if (str.size() % 4 != 0) return {};
151  /* One or two = characters at the end are permitted. */
152  if (str.size() >= 1 && str.back() == '=') str.remove_suffix(1);
153  if (str.size() >= 1 && str.back() == '=') str.remove_suffix(1);
154 
155  std::vector<unsigned char> ret;
156  ret.reserve((str.size() * 3) / 4);
157  bool valid = ConvertBits<6, 8, false>(
158  [&](unsigned char c) { ret.push_back(c); },
159  str.begin(), str.end(),
160  [](char c) { return decode64_table[uint8_t(c)]; }
161  );
162  if (!valid) return {};
163 
164  return ret;
165 }
166 
167 std::string EncodeBase32(Span<const unsigned char> input, bool pad)
168 {
169  static const char *pbase32 = "abcdefghijklmnopqrstuvwxyz234567";
170 
171  std::string str;
172  str.reserve(((input.size() + 4) / 5) * 8);
173  ConvertBits<8, 5, true>([&](int v) { str += pbase32[v]; }, input.begin(), input.end());
174  if (pad) {
175  while (str.size() % 8) {
176  str += '=';
177  }
178  }
179  return str;
180 }
181 
182 std::string EncodeBase32(std::string_view str, bool pad)
183 {
184  return EncodeBase32(MakeUCharSpan(str), pad);
185 }
186 
187 std::optional<std::vector<unsigned char>> DecodeBase32(std::string_view str)
188 {
189  static const int8_t decode32_table[256]{
190  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
191  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
192  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1,
193  -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
194  15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 0, 1, 2,
195  3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
196  23, 24, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
197  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
198  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
199  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
200  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
201  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
202  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
203  };
204 
205  if (str.size() % 8 != 0) return {};
206  /* 1, 3, 4, or 6 padding '=' suffix characters are permitted. */
207  if (str.size() >= 1 && str.back() == '=') str.remove_suffix(1);
208  if (str.size() >= 2 && str.substr(str.size() - 2) == "==") str.remove_suffix(2);
209  if (str.size() >= 1 && str.back() == '=') str.remove_suffix(1);
210  if (str.size() >= 2 && str.substr(str.size() - 2) == "==") str.remove_suffix(2);
211 
212  std::vector<unsigned char> ret;
213  ret.reserve((str.size() * 5) / 8);
214  bool valid = ConvertBits<5, 8, false>(
215  [&](unsigned char c) { ret.push_back(c); },
216  str.begin(), str.end(),
217  [](char c) { return decode32_table[uint8_t(c)]; }
218  );
219 
220  if (!valid) return {};
221 
222  return ret;
223 }
224 
225 namespace {
226 template <typename T>
227 bool ParseIntegral(std::string_view str, T* out)
228 {
229  static_assert(std::is_integral<T>::value);
230  // Replicate the exact behavior of strtol/strtoll/strtoul/strtoull when
231  // handling leading +/- for backwards compatibility.
232  if (str.length() >= 2 && str[0] == '+' && str[1] == '-') {
233  return false;
234  }
235  const std::optional<T> opt_int = ToIntegral<T>((!str.empty() && str[0] == '+') ? str.substr(1) : str);
236  if (!opt_int) {
237  return false;
238  }
239  if (out != nullptr) {
240  *out = *opt_int;
241  }
242  return true;
243 }
244 }; // namespace
245 
246 bool ParseInt32(std::string_view str, int32_t* out)
247 {
248  return ParseIntegral<int32_t>(str, out);
249 }
250 
251 bool ParseInt64(std::string_view str, int64_t* out)
252 {
253  return ParseIntegral<int64_t>(str, out);
254 }
255 
256 bool ParseUInt8(std::string_view str, uint8_t* out)
257 {
258  return ParseIntegral<uint8_t>(str, out);
259 }
260 
261 bool ParseUInt16(std::string_view str, uint16_t* out)
262 {
263  return ParseIntegral<uint16_t>(str, out);
264 }
265 
266 bool ParseUInt32(std::string_view str, uint32_t* out)
267 {
268  return ParseIntegral<uint32_t>(str, out);
269 }
270 
271 bool ParseUInt64(std::string_view str, uint64_t* out)
272 {
273  return ParseIntegral<uint64_t>(str, out);
274 }
275 
276 std::string FormatParagraph(std::string_view in, size_t width, size_t indent)
277 {
278  assert(width >= indent);
279  std::stringstream out;
280  size_t ptr = 0;
281  size_t indented = 0;
282  while (ptr < in.size())
283  {
284  size_t lineend = in.find_first_of('\n', ptr);
285  if (lineend == std::string::npos) {
286  lineend = in.size();
287  }
288  const size_t linelen = lineend - ptr;
289  const size_t rem_width = width - indented;
290  if (linelen <= rem_width) {
291  out << in.substr(ptr, linelen + 1);
292  ptr = lineend + 1;
293  indented = 0;
294  } else {
295  size_t finalspace = in.find_last_of(" \n", ptr + rem_width);
296  if (finalspace == std::string::npos || finalspace < ptr) {
297  // No place to break; just include the entire word and move on
298  finalspace = in.find_first_of("\n ", ptr);
299  if (finalspace == std::string::npos) {
300  // End of the string, just add it and break
301  out << in.substr(ptr);
302  break;
303  }
304  }
305  out << in.substr(ptr, finalspace - ptr) << "\n";
306  if (in[finalspace] == '\n') {
307  indented = 0;
308  } else if (indent) {
309  out << std::string(indent, ' ');
310  indented = indent;
311  }
312  ptr = finalspace + 1;
313  }
314  }
315  return out.str();
316 }
317 
326 static const int64_t UPPER_BOUND = 1000000000000000000LL - 1LL;
327 
329 static inline bool ProcessMantissaDigit(char ch, int64_t &mantissa, int &mantissa_tzeros)
330 {
331  if(ch == '0')
332  ++mantissa_tzeros;
333  else {
334  for (int i=0; i<=mantissa_tzeros; ++i) {
335  if (mantissa > (UPPER_BOUND / 10LL))
336  return false; /* overflow */
337  mantissa *= 10;
338  }
339  mantissa += ch - '0';
340  mantissa_tzeros = 0;
341  }
342  return true;
343 }
344 
345 bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out)
346 {
347  int64_t mantissa = 0;
348  int64_t exponent = 0;
349  int mantissa_tzeros = 0;
350  bool mantissa_sign = false;
351  bool exponent_sign = false;
352  int ptr = 0;
353  int end = val.size();
354  int point_ofs = 0;
355 
356  if (ptr < end && val[ptr] == '-') {
357  mantissa_sign = true;
358  ++ptr;
359  }
360  if (ptr < end)
361  {
362  if (val[ptr] == '0') {
363  /* pass single 0 */
364  ++ptr;
365  } else if (val[ptr] >= '1' && val[ptr] <= '9') {
366  while (ptr < end && IsDigit(val[ptr])) {
367  if (!ProcessMantissaDigit(val[ptr], mantissa, mantissa_tzeros))
368  return false; /* overflow */
369  ++ptr;
370  }
371  } else return false; /* missing expected digit */
372  } else return false; /* empty string or loose '-' */
373  if (ptr < end && val[ptr] == '.')
374  {
375  ++ptr;
376  if (ptr < end && IsDigit(val[ptr]))
377  {
378  while (ptr < end && IsDigit(val[ptr])) {
379  if (!ProcessMantissaDigit(val[ptr], mantissa, mantissa_tzeros))
380  return false; /* overflow */
381  ++ptr;
382  ++point_ofs;
383  }
384  } else return false; /* missing expected digit */
385  }
386  if (ptr < end && (val[ptr] == 'e' || val[ptr] == 'E'))
387  {
388  ++ptr;
389  if (ptr < end && val[ptr] == '+')
390  ++ptr;
391  else if (ptr < end && val[ptr] == '-') {
392  exponent_sign = true;
393  ++ptr;
394  }
395  if (ptr < end && IsDigit(val[ptr])) {
396  while (ptr < end && IsDigit(val[ptr])) {
397  if (exponent > (UPPER_BOUND / 10LL))
398  return false; /* overflow */
399  exponent = exponent * 10 + val[ptr] - '0';
400  ++ptr;
401  }
402  } else return false; /* missing expected digit */
403  }
404  if (ptr != end)
405  return false; /* trailing garbage */
406 
407  /* finalize exponent */
408  if (exponent_sign)
409  exponent = -exponent;
410  exponent = exponent - point_ofs + mantissa_tzeros;
411 
412  /* finalize mantissa */
413  if (mantissa_sign)
414  mantissa = -mantissa;
415 
416  /* convert to one 64-bit fixed-point value */
417  exponent += decimals;
418  if (exponent < 0)
419  return false; /* cannot represent values smaller than 10^-decimals */
420  if (exponent >= 18)
421  return false; /* cannot represent values larger than or equal to 10^(18-decimals) */
422 
423  for (int i=0; i < exponent; ++i) {
424  if (mantissa > (UPPER_BOUND / 10LL) || mantissa < -(UPPER_BOUND / 10LL))
425  return false; /* overflow */
426  mantissa *= 10;
427  }
428  if (mantissa > UPPER_BOUND || mantissa < -UPPER_BOUND)
429  return false; /* overflow */
430 
431  if (amount_out)
432  *amount_out = mantissa;
433 
434  return true;
435 }
436 
437 std::string ToLower(std::string_view str)
438 {
439  std::string r;
440  for (auto ch : str) r += ToLower(ch);
441  return r;
442 }
443 
444 std::string ToUpper(std::string_view str)
445 {
446  std::string r;
447  for (auto ch : str) r += ToUpper(ch);
448  return r;
449 }
450 
451 std::string Capitalize(std::string str)
452 {
453  if (str.empty()) return str;
454  str[0] = ToUpper(str.front());
455  return str;
456 }
457 
458 namespace {
459 
460 using ByteAsHex = std::array<char, 2>;
461 
462 constexpr std::array<ByteAsHex, 256> CreateByteToHexMap()
463 {
464  constexpr char hexmap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
465 
466  std::array<ByteAsHex, 256> byte_to_hex{};
467  for (size_t i = 0; i < byte_to_hex.size(); ++i) {
468  byte_to_hex[i][0] = hexmap[i >> 4];
469  byte_to_hex[i][1] = hexmap[i & 15];
470  }
471  return byte_to_hex;
472 }
473 
474 } // namespace
475 
476 std::string HexStr(const Span<const uint8_t> s)
477 {
478  std::string rv(s.size() * 2, '\0');
479  static constexpr auto byte_to_hex = CreateByteToHexMap();
480  static_assert(sizeof(byte_to_hex) == 512);
481 
482  char* it = rv.data();
483  for (uint8_t v : s) {
484  std::memcpy(it, byte_to_hex[v].data(), 2);
485  it += 2;
486  }
487 
488  assert(it == rv.data() + rv.size());
489  return rv;
490 }
491 
492 std::optional<uint64_t> ParseByteUnits(std::string_view str, ByteUnit default_multiplier)
493 {
494  if (str.empty()) {
495  return std::nullopt;
496  }
497  auto multiplier = default_multiplier;
498  char unit = str.back();
499  switch (unit) {
500  case 'k':
501  multiplier = ByteUnit::k;
502  break;
503  case 'K':
504  multiplier = ByteUnit::K;
505  break;
506  case 'm':
507  multiplier = ByteUnit::m;
508  break;
509  case 'M':
510  multiplier = ByteUnit::M;
511  break;
512  case 'g':
513  multiplier = ByteUnit::g;
514  break;
515  case 'G':
516  multiplier = ByteUnit::G;
517  break;
518  case 't':
519  multiplier = ByteUnit::t;
520  break;
521  case 'T':
522  multiplier = ByteUnit::T;
523  break;
524  default:
525  unit = 0;
526  break;
527  }
528 
529  uint64_t unit_amount = static_cast<uint64_t>(multiplier);
530  auto parsed_num = ToIntegral<uint64_t>(unit ? str.substr(0, str.size() - 1) : str);
531  if (!parsed_num || parsed_num > std::numeric_limits<uint64_t>::max() / unit_amount) { // check overflow
532  return std::nullopt;
533  }
534  return *parsed_num * unit_amount;
535 }
int ret
constexpr std::size_t size() const noexcept
Definition: span.h:186
constexpr C * end() const noexcept
Definition: span.h:175
constexpr C * begin() const noexcept
Definition: span.h:174
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(Span{std::forward< V >(v)}))
Like the Span constructor, but for (const) unsigned char member types only.
Definition: span.h:285
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.
Definition: strencodings.h:137
ByteUnit
Used by ParseByteUnits() Lowercase base 1000 Uppercase base 1024.
Definition: strencodings.h:40
constexpr bool IsSpace(char c) noexcept
Tests if the given character is a whitespace character.
Definition: strencodings.h:153
std::string Capitalize(std::string str)
Capitalizes the first character of the given string.
static const std::string SAFE_CHARS[]
bool IsHexNumber(std::string_view str)
Return true if the string is a hex number, optionally prefixed with "0x".
bool ParseInt32(std::string_view str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool ParseUInt16(std::string_view str, uint16_t *out)
Convert decimal string to unsigned 16-bit integer with strict parse error feedback.
std::optional< uint64_t > ParseByteUnits(std::string_view str, ByteUnit default_multiplier)
Parse a string with suffix unit [k|K|m|M|g|G|t|T].
std::string ToUpper(std::string_view str)
Returns the uppercase equivalent of the given string.
const signed char p_util_hexdigit[256]
std::vector< Byte > ParseHex(std::string_view str)
Parse the hex string into bytes (uint8_t or std::byte).
std::string EncodeBase64(Span< const unsigned char > input)
bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
bool ParseInt64(std::string_view str, int64_t *out)
Convert string to signed 64-bit integer with strict parse error feedback.
std::string EncodeBase32(Span< const unsigned char > input, bool pad)
Base32 encode.
bool ParseUInt8(std::string_view str, uint8_t *out)
Convert decimal string to unsigned 8-bit integer with strict parse error feedback.
bool ParseUInt64(std::string_view str, uint64_t *out)
Convert decimal string to unsigned 64-bit integer with strict parse error feedback.
signed char HexDigit(char c)
static bool ProcessMantissaDigit(char ch, int64_t &mantissa, int &mantissa_tzeros)
Helper function for ParseFixedPoint.
bool IsHex(std::string_view str)
std::string FormatParagraph(std::string_view in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.
static const int64_t UPPER_BOUND
Upper bound for mantissa.
std::optional< std::vector< unsigned char > > DecodeBase64(std::string_view str)
bool ParseUInt32(std::string_view str, uint32_t *out)
Convert decimal string to unsigned 32-bit integer with strict parse error feedback.
void SplitHostPort(std::string_view in, uint16_t &portOut, std::string &hostOut)
std::string ToLower(std::string_view str)
Returns the lowercase equivalent of the given string.
std::string SanitizeString(std::string_view str, int rule)
Remove unsafe chars.
static const std::string CHARS_ALPHA_NUM
std::optional< std::vector< unsigned char > > DecodeBase32(std::string_view str)
assert(!tx.IsCoinBase())