File tree Expand file tree Collapse file tree 2 files changed +12
-21
lines changed Expand file tree Collapse file tree 2 files changed +12
-21
lines changed Original file line number Diff line number Diff line change @@ -81,32 +81,24 @@ bool IsHexNumber(const std::string& str)
81
81
return (str.size () > starting_location);
82
82
}
83
83
84
- std::vector<unsigned char > ParseHex (const char * psz )
84
+ std::vector<unsigned char > ParseHex (std::string_view str )
85
85
{
86
86
// convert hex dump to vector
87
87
std::vector<unsigned char > vch;
88
- while (true )
89
- {
90
- while (IsSpace (*psz))
91
- psz++;
92
- signed char c = HexDigit (*psz++);
93
- if (c == (signed char )-1 )
94
- break ;
95
- auto n{uint8_t (c << 4 )};
96
- c = HexDigit (*psz++);
97
- if (c == (signed char )-1 )
98
- break ;
99
- n |= c;
100
- vch.push_back (n);
88
+ auto it = str.begin ();
89
+ while (it != str.end () && it + 1 != str.end ()) {
90
+ if (IsSpace (*it)) {
91
+ ++it;
92
+ continue ;
93
+ }
94
+ auto c1 = HexDigit (*(it++));
95
+ auto c2 = HexDigit (*(it++));
96
+ if (c1 < 0 || c2 < 0 ) break ;
97
+ vch.push_back (uint8_t (c1 << 4 ) | c2);
101
98
}
102
99
return vch;
103
100
}
104
101
105
- std::vector<unsigned char > ParseHex (const std::string& str)
106
- {
107
- return ParseHex (str.c_str ());
108
- }
109
-
110
102
void SplitHostPort (std::string in, uint16_t & portOut, std::string& hostOut)
111
103
{
112
104
size_t colon = in.find_last_of (' :' );
Original file line number Diff line number Diff line change @@ -55,8 +55,7 @@ enum class ByteUnit : uint64_t {
55
55
* @return A new string without unsafe chars
56
56
*/
57
57
std::string SanitizeString (const std::string& str, int rule = SAFE_CHARS_DEFAULT);
58
- std::vector<unsigned char > ParseHex (const char * psz);
59
- std::vector<unsigned char > ParseHex (const std::string& str);
58
+ std::vector<unsigned char > ParseHex (std::string_view str);
60
59
signed char HexDigit (char c);
61
60
/* Returns true if each character in str is a hex character, and has an even
62
61
* number of hex digits.*/
You can’t perform that action at this time.
0 commit comments