mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 18:53:23 -03:00
Make IsHexNumber use string_view
This commit is contained in:
parent
40062997f2
commit
963bc9b576
2 changed files with 5 additions and 8 deletions
|
@ -66,17 +66,14 @@ bool IsHex(std::string_view str)
|
|||
return (str.size() > 0) && (str.size()%2 == 0);
|
||||
}
|
||||
|
||||
bool IsHexNumber(const std::string& str)
|
||||
bool IsHexNumber(std::string_view str)
|
||||
{
|
||||
size_t starting_location = 0;
|
||||
if (str.size() > 2 && *str.begin() == '0' && *(str.begin()+1) == 'x') {
|
||||
starting_location = 2;
|
||||
}
|
||||
for (const char c : str.substr(starting_location)) {
|
||||
if (str.substr(0, 2) == "0x") str.remove_prefix(2);
|
||||
for (char c : str) {
|
||||
if (HexDigit(c) < 0) return false;
|
||||
}
|
||||
// Return false for empty string or "0x".
|
||||
return (str.size() > starting_location);
|
||||
return str.size() > 0;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> ParseHex(std::string_view str)
|
||||
|
|
|
@ -63,7 +63,7 @@ bool IsHex(std::string_view str);
|
|||
/**
|
||||
* Return true if the string is a hex number, optionally prefixed with "0x"
|
||||
*/
|
||||
bool IsHexNumber(const std::string& str);
|
||||
bool IsHexNumber(std::string_view str);
|
||||
std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid = nullptr);
|
||||
std::string DecodeBase64(const std::string& str, bool* pf_invalid = nullptr);
|
||||
std::string EncodeBase64(Span<const unsigned char> input);
|
||||
|
|
Loading…
Add table
Reference in a new issue