Make IsHexNumber use string_view
This commit is contained in:
1 parent
40062997f2
commit
963bc9b576
2 files changed
+5
-8
No files matched your search
@@ -66,17 +66,14 @@ bool IsHex(std::string_view str)
|
|||||||
return (str.size() > 0) && (str.size()%2 == 0);
|
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.substr(0, 2) == "0x") str.remove_prefix(2);
|
||||||
if (str.size() > 2 && *str.begin() == '0' && *(str.begin()+1) == 'x') {
|
for (char c : str) {
|
||||||
starting_location = 2;
|
|
||||||
}
|
|
||||||
for (const char c : str.substr(starting_location)) {
|
|
||||||
if (HexDigit(c) < 0) return false;
|
if (HexDigit(c) < 0) return false;
|
||||||
}
|
}
|
||||||
// Return false for empty string or "0x".
|
// 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)
|
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"
|
* 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::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid = nullptr);
|
||||||
std::string DecodeBase64(const std::string& str, bool* pf_invalid = nullptr);
|
std::string DecodeBase64(const std::string& str, bool* pf_invalid = nullptr);
|
||||||
std::string EncodeBase64(Span<const unsigned char> input);
|
std::string EncodeBase64(Span<const unsigned char> input);
|
||||||
|
|||||||
Reference in new issue
Block a user