mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Make ParseHex use string_view
This commit is contained in:
@@ -81,32 +81,24 @@ bool IsHexNumber(const std::string& str)
|
|||||||
return (str.size() > starting_location);
|
return (str.size() > starting_location);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned char> ParseHex(const char* psz)
|
std::vector<unsigned char> ParseHex(std::string_view str)
|
||||||
{
|
{
|
||||||
// convert hex dump to vector
|
// convert hex dump to vector
|
||||||
std::vector<unsigned char> vch;
|
std::vector<unsigned char> vch;
|
||||||
while (true)
|
auto it = str.begin();
|
||||||
{
|
while (it != str.end() && it + 1 != str.end()) {
|
||||||
while (IsSpace(*psz))
|
if (IsSpace(*it)) {
|
||||||
psz++;
|
++it;
|
||||||
signed char c = HexDigit(*psz++);
|
continue;
|
||||||
if (c == (signed char)-1)
|
}
|
||||||
break;
|
auto c1 = HexDigit(*(it++));
|
||||||
auto n{uint8_t(c << 4)};
|
auto c2 = HexDigit(*(it++));
|
||||||
c = HexDigit(*psz++);
|
if (c1 < 0 || c2 < 0) break;
|
||||||
if (c == (signed char)-1)
|
vch.push_back(uint8_t(c1 << 4) | c2);
|
||||||
break;
|
|
||||||
n |= c;
|
|
||||||
vch.push_back(n);
|
|
||||||
}
|
}
|
||||||
return vch;
|
return vch;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned char> ParseHex(const std::string& str)
|
|
||||||
{
|
|
||||||
return ParseHex(str.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void SplitHostPort(std::string in, uint16_t& portOut, std::string& hostOut)
|
void SplitHostPort(std::string in, uint16_t& portOut, std::string& hostOut)
|
||||||
{
|
{
|
||||||
size_t colon = in.find_last_of(':');
|
size_t colon = in.find_last_of(':');
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ enum class ByteUnit : uint64_t {
|
|||||||
* @return A new string without unsafe chars
|
* @return A new string without unsafe chars
|
||||||
*/
|
*/
|
||||||
std::string SanitizeString(const std::string& str, int rule = SAFE_CHARS_DEFAULT);
|
std::string SanitizeString(const std::string& str, int rule = SAFE_CHARS_DEFAULT);
|
||||||
std::vector<unsigned char> ParseHex(const char* psz);
|
std::vector<unsigned char> ParseHex(std::string_view str);
|
||||||
std::vector<unsigned char> ParseHex(const std::string& str);
|
|
||||||
signed char HexDigit(char c);
|
signed char HexDigit(char c);
|
||||||
/* Returns true if each character in str is a hex character, and has an even
|
/* Returns true if each character in str is a hex character, and has an even
|
||||||
* number of hex digits.*/
|
* number of hex digits.*/
|
||||||
|
|||||||
Reference in New Issue
Block a user