mirror of https://github.com/aria2/aria2
Optimize htmlEscape implementation a bit
parent
1b8de6bb18
commit
b2da75ca33
39
src/util.cc
39
src/util.cc
|
@ -1533,25 +1533,32 @@ getNumericNameInfo(const struct sockaddr* sockaddr, socklen_t len)
|
||||||
|
|
||||||
std::string htmlEscape(const std::string& src)
|
std::string htmlEscape(const std::string& src)
|
||||||
{
|
{
|
||||||
std::string dest;
|
std::string rv(src);
|
||||||
for(std::string::const_iterator i = src.begin(), eoi = src.end();
|
std::string::size_type pos = 0;
|
||||||
i != eoi; ++i) {
|
while ((pos = rv.find_first_of("<>&\"'", pos)) != std::string::npos) {
|
||||||
char ch = *i;
|
auto ch = rv[pos];
|
||||||
if (ch == '<') {
|
if (ch == '<') {
|
||||||
dest += "<";
|
rv.replace(pos, 1, "<");
|
||||||
} else if(ch == '>') {
|
pos += 4;
|
||||||
dest += ">";
|
}
|
||||||
} else if(ch == '&') {
|
else if (ch == '>') {
|
||||||
dest += "&";
|
rv.replace(pos, 1, ">");
|
||||||
} else if(ch == '\'') {
|
pos += 4;
|
||||||
dest += "'";
|
}
|
||||||
} else if(ch == '"') {
|
else if (ch == '&') {
|
||||||
dest += """;
|
rv.replace(pos, 1, "&");
|
||||||
} else {
|
pos += 5;
|
||||||
dest += ch;
|
}
|
||||||
|
else if (ch == '"') {
|
||||||
|
rv.replace(pos, 1, """);
|
||||||
|
pos += 6;
|
||||||
|
}
|
||||||
|
else { // '\''
|
||||||
|
rv.replace(pos, 1, "'");
|
||||||
|
pos += 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dest;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<size_t, std::string>
|
std::pair<size_t, std::string>
|
||||||
|
|
Loading…
Reference in New Issue