srctree

Robin Linden parent 1e9921a0 ac8a94a8
util/string: Rename to_lower to lowercased

This to make it clearer that it doesn't transform its argument, butinstead returns a lowercased copy.

inlinesplit
html2/tokenizer.cpp added: 28, removed: 28, total 0
@@ -216,7 +216,7 @@ void Tokenizer::run() {
};
 
if (util::is_upper_alpha(*c)) {
append_to_tag_name(util::to_lower(*c));
append_to_tag_name(util::lowercased(*c));
continue;
}
 
@@ -299,7 +299,7 @@ void Tokenizer::run() {
}
 
if (util::is_upper_alpha(*c)) {
std::get<EndTagToken>(current_token_).tag_name.append(1, util::to_lower(*c));
std::get<EndTagToken>(current_token_).tag_name.append(1, util::lowercased(*c));
temporary_buffer_.append(1, *c);
continue;
}
@@ -513,7 +513,7 @@ void Tokenizer::run() {
}
 
if (util::is_upper_alpha(*c)) {
std::get<EndTagToken>(current_token_).tag_name.append(1, util::to_lower(*c));
std::get<EndTagToken>(current_token_).tag_name.append(1, util::lowercased(*c));
temporary_buffer_.append(1, *c);
continue;
}
@@ -564,7 +564,7 @@ void Tokenizer::run() {
}
 
if (util::is_upper_alpha(*c)) {
temporary_buffer_.append(1, util::to_lower(*c));
temporary_buffer_.append(1, util::lowercased(*c));
emit(CharacterToken{*c});
continue;
}
@@ -704,7 +704,7 @@ void Tokenizer::run() {
}
 
if (util::is_upper_alpha(*c)) {
temporary_buffer_.append(1, util::to_lower(*c));
temporary_buffer_.append(1, util::lowercased(*c));
emit(CharacterToken{*c});
continue;
}
@@ -776,7 +776,7 @@ void Tokenizer::run() {
};
 
if (util::is_upper_alpha(*c)) {
append_to_current_attribute_name(util::to_lower(*c));
append_to_current_attribute_name(util::lowercased(*c));
continue;
}
 
@@ -1272,7 +1272,7 @@ void Tokenizer::run() {
 
if (util::is_upper_alpha(*c)) {
current_token_ = DoctypeToken{.name = std::string{}};
std::get<DoctypeToken>(current_token_).name->append(1, util::to_lower(*c));
std::get<DoctypeToken>(current_token_).name->append(1, util::lowercased(*c));
state_ = State::DoctypeName;
continue;
}
@@ -1314,7 +1314,7 @@ void Tokenizer::run() {
}
 
if (util::is_upper_alpha(*c)) {
std::get<DoctypeToken>(current_token_).name->append(1, util::to_lower(*c));
std::get<DoctypeToken>(current_token_).name->append(1, util::lowercased(*c));
continue;
}
 
 
protocol/response.cpp added: 28, removed: 28, total 0
@@ -39,7 +39,7 @@ std::size_t Headers::size() const {
 
bool Headers::CaseInsensitiveLess::operator()(std::string_view s1, std::string_view s2) const {
return ranges::lexicographical_compare(
s1, s2, [](char c1, char c2) { return util::to_lower(c1) < util::to_lower(c2); });
s1, s2, [](char c1, char c2) { return util::lowercased(c1) < util::lowercased(c2); });
}
 
} // namespace protocol
 
render/render.cpp added: 28, removed: 28, total 0
@@ -31,7 +31,7 @@ struct CaseInsensitiveLess {
using is_transparent = void;
bool operator()(std::string_view s1, std::string_view s2) const {
return ranges::lexicographical_compare(
s1, s2, [](char c1, char c2) { return util::to_lower(c1) < util::to_lower(c2); });
s1, s2, [](char c1, char c2) { return util::lowercased(c1) < util::lowercased(c2); });
}
};
 
 
uri/uri.cpp added: 28, removed: 28, total 0
@@ -17,8 +17,8 @@ namespace {
void normalize(Uri &uri) {
// The scheme and host components of the URI are case-insensitive and
// therefore should be normalized to lowercase.
uri.scheme = util::to_lower(std::move(uri.scheme));
uri.authority.host = util::to_lower(std::move(uri.authority.host));
uri.scheme = util::lowercased(std::move(uri.scheme));
uri.authority.host = util::lowercased(std::move(uri.authority.host));
 
// In presence of an authority component, an empty path component should be
// normalized to a path component of "/".
 
util/string.h added: 28, removed: 28, total 0
@@ -49,7 +49,7 @@ constexpr bool is_hex_digit(char c) {
return is_upper_hex_digit(c) || is_lower_hex_digit(c);
}
 
constexpr char to_lower(char c) {
constexpr char lowercased(char c) {
if (!is_upper_alpha(c)) {
return c;
}
@@ -57,13 +57,13 @@ constexpr char to_lower(char c) {
return c + ('a' - 'A');
}
 
[[nodiscard]] inline std::string to_lower(std::string s) {
std::transform(begin(s), end(s), begin(s), [](char c) { return to_lower(c); });
[[nodiscard]] inline std::string lowercased(std::string s) {
std::transform(begin(s), end(s), begin(s), [](char c) { return lowercased(c); });
return s;
}
 
constexpr bool no_case_compare(std::string_view a, std::string_view b) {
return ranges::equal(a, b, [](auto c1, auto c2) { return to_lower(c1) == to_lower(c2); });
return ranges::equal(a, b, [](auto c1, auto c2) { return lowercased(c1) == lowercased(c2); });
}
 
inline std::vector<std::string_view> split(std::string_view str, std::string_view sep) {
 
util/string_test.cpp added: 28, removed: 28, total 0
@@ -55,14 +55,14 @@ int main() {
expect(!is_hex_digit('!'));
});
 
etest::test("to_lower(char)", [] {
expect_eq(to_lower('A'), 'a');
expect_eq(to_lower('a'), 'a');
etest::test("lowercased(char)", [] {
expect_eq(lowercased('A'), 'a');
expect_eq(lowercased('a'), 'a');
});
 
etest::test("to_lower(std::string)", [] {
expect_eq(to_lower("Hello There!!1"), "hello there!!1");
expect_eq(to_lower("woop woop"), "woop woop");
etest::test("lowercased(std::string)", [] {
expect_eq(lowercased("Hello There!!1"), "hello there!!1");
expect_eq(lowercased("woop woop"), "woop woop");
});
 
etest::test("no case compare", [] {