Skip to content

Commit d648b51

Browse files
sipaMacroFake
authored andcommitted
Make SanitizeString use string_view
1 parent 963bc9b commit d648b51

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/util/strencodings.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ static const std::string SAFE_CHARS[] =
2424
CHARS_ALPHA_NUM + "!*'();:@&=+$,/?#[]-_.~%", // SAFE_CHARS_URI
2525
};
2626

27-
std::string SanitizeString(const std::string& str, int rule)
27+
std::string SanitizeString(std::string_view str, int rule)
2828
{
29-
std::string strResult;
30-
for (std::string::size_type i = 0; i < str.size(); i++)
31-
{
32-
if (SAFE_CHARS[rule].find(str[i]) != std::string::npos)
33-
strResult.push_back(str[i]);
29+
std::string result;
30+
for (char c : str) {
31+
if (SAFE_CHARS[rule].find(c) != std::string::npos) {
32+
result.push_back(c);
33+
}
3434
}
35-
return strResult;
35+
return result;
3636
}
3737

3838
const signed char p_util_hexdigit[256] =

src/util/strencodings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum class ByteUnit : uint64_t {
5454
* @param[in] rule The set of safe chars to choose (default: least restrictive)
5555
* @return A new string without unsafe chars
5656
*/
57-
std::string SanitizeString(const std::string& str, int rule = SAFE_CHARS_DEFAULT);
57+
std::string SanitizeString(std::string_view str, int rule = SAFE_CHARS_DEFAULT);
5858
std::vector<unsigned char> ParseHex(std::string_view str);
5959
signed char HexDigit(char c);
6060
/* Returns true if each character in str is a hex character, and has an even

0 commit comments

Comments
 (0)