1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:07:34 +00:00

Everywhere: Add sv suffix to strings relying on StringView(char const*)

Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
This commit is contained in:
sin-ack 2022-07-11 17:32:29 +00:00 committed by Andreas Kling
parent e5f09ea170
commit 3f3f45580a
762 changed files with 8315 additions and 8316 deletions

View file

@ -96,7 +96,7 @@ TEST_CASE(regex_options_posix)
TEST_CASE(regex_lexer)
{
Lexer l("/[.*+?^${}()|[\\]\\\\]/g");
Lexer l("/[.*+?^${}()|[\\]\\\\]/g"sv);
EXPECT(l.next().type() == regex::TokenType::Slash);
EXPECT(l.next().type() == regex::TokenType::LeftBracket);
EXPECT(l.next().type() == regex::TokenType::Period);
@ -149,7 +149,7 @@ TEST_CASE(parser_error_special_characters_used_at_wrong_place)
// After vertical line
b.clear();
b.append("a|");
b.append("a|"sv);
b.append(ch);
pattern = b.build();
l.set_source(pattern);
@ -196,25 +196,25 @@ TEST_CASE(parser_error_vertical_line_used_at_wrong_place)
PosixExtended p(l);
// First in ere
l.set_source("|asdf");
l.set_source("|asdf"sv);
p.parse();
EXPECT(p.has_error());
EXPECT(p.error() == regex::Error::EmptySubExpression);
// Last in ere
l.set_source("asdf|");
l.set_source("asdf|"sv);
p.parse();
EXPECT(p.has_error());
EXPECT(p.error() == regex::Error::EmptySubExpression);
// After left parens
l.set_source("(|asdf)");
l.set_source("(|asdf)"sv);
p.parse();
EXPECT(p.has_error());
EXPECT(p.error() == regex::Error::EmptySubExpression);
// Proceed right parens
l.set_source("(asdf)|");
l.set_source("(asdf)|"sv);
p.parse();
EXPECT(p.has_error());
EXPECT(p.error() == regex::Error::EmptySubExpression);
@ -224,21 +224,21 @@ TEST_CASE(catch_all_first)
{
Regex<PosixExtended> re("^.*$");
RegexResult m;
re.match("Hello World", m);
re.match("Hello World"sv, m);
EXPECT(m.count == 1);
EXPECT(re.match("Hello World", m));
EXPECT(re.match("Hello World"sv, m));
}
TEST_CASE(catch_all)
{
Regex<PosixExtended> re("^.*$", PosixFlags::Global);
EXPECT(re.has_match("Hello World"));
EXPECT(re.match("Hello World").success);
EXPECT(re.match("Hello World").count == 1);
EXPECT(re.has_match("Hello World"sv));
EXPECT(re.match("Hello World"sv).success);
EXPECT(re.match("Hello World"sv).count == 1);
EXPECT(has_match("Hello World", re));
auto res = match("Hello World", re);
EXPECT(has_match("Hello World"sv, re));
auto res = match("Hello World"sv, re);
EXPECT(res.success);
EXPECT(res.count == 1);
EXPECT(res.matches.size() == 1);
@ -248,7 +248,7 @@ TEST_CASE(catch_all)
TEST_CASE(catch_all_again)
{
Regex<PosixExtended> re("^.*$", PosixFlags::Extra);
EXPECT_EQ(has_match("Hello World", re), true);
EXPECT_EQ(has_match("Hello World"sv, re), true);
}
TEST_CASE(char_utf8)
@ -295,14 +295,14 @@ TEST_CASE(catch_all_newline_2)
{
Regex<PosixExtended> re("^.*$");
RegexResult result;
result = match("Hello World\nTest\n1234\n", re, PosixFlags::Multiline | PosixFlags::StringCopyMatches);
result = match("Hello World\nTest\n1234\n"sv, re, PosixFlags::Multiline | PosixFlags::StringCopyMatches);
EXPECT_EQ(result.success, true);
EXPECT_EQ(result.count, 3u);
EXPECT_EQ(result.matches.at(0).view, "Hello World");
EXPECT_EQ(result.matches.at(1).view, "Test");
EXPECT_EQ(result.matches.at(2).view, "1234");
result = match("Hello World\nTest\n1234\n", re);
result = match("Hello World\nTest\n1234\n"sv, re);
EXPECT_EQ(result.success, true);
EXPECT_EQ(result.count, 1u);
EXPECT_EQ(result.matches.at(0).view, "Hello World\nTest\n1234\n");
@ -334,16 +334,16 @@ TEST_CASE(match_character_class_with_assertion)
TEST_CASE(example_for_git_commit)
{
Regex<PosixExtended> re("^.*$");
auto result = re.match("Well, hello friends!\nHello World!");
auto result = re.match("Well, hello friends!\nHello World!"sv);
EXPECT(result.success);
EXPECT(result.count == 1);
EXPECT(result.matches.at(0).view.starts_with("Well"));
EXPECT(result.matches.at(0).view.starts_with("Well"sv));
EXPECT(result.matches.at(0).view.length() == 33);
EXPECT(re.has_match("Well,...."));
EXPECT(re.has_match("Well,...."sv));
result = re.match("Well, hello friends!\nHello World!", PosixFlags::Multiline);
result = re.match("Well, hello friends!\nHello World!"sv, PosixFlags::Multiline);
EXPECT(result.success);
EXPECT(result.count == 2);
@ -354,8 +354,8 @@ TEST_CASE(example_for_git_commit)
TEST_CASE(email_address)
{
Regex<PosixExtended> re("^[A-Z0-9a-z._%+-]{1,64}@([A-Za-z0-9-]{1,63}\\.){1,125}[A-Za-z]{2,63}$");
EXPECT(re.has_match("hello.world@domain.tld"));
EXPECT(re.has_match("this.is.a.very_long_email_address@world.wide.web"));
EXPECT(re.has_match("hello.world@domain.tld"sv));
EXPECT(re.has_match("this.is.a.very_long_email_address@world.wide.web"sv));
}
TEST_CASE(ini_file_entries)
@ -480,16 +480,16 @@ TEST_CASE(simple_period_end_benchmark)
{
Regex<PosixExtended> re("hello.$");
RegexResult m;
EXPECT_EQ(re.search("Hello1", m), false);
EXPECT_EQ(re.search("hello1hello1", m), true);
EXPECT_EQ(re.search("hello2hell", m), false);
EXPECT_EQ(re.search("hello?", m), true);
EXPECT_EQ(re.search("Hello1"sv, m), false);
EXPECT_EQ(re.search("hello1hello1"sv, m), true);
EXPECT_EQ(re.search("hello2hell"sv, m), false);
EXPECT_EQ(re.search("hello?"sv, m), true);
}
TEST_CASE(posix_extended_nested_capture_group)
{
Regex<PosixExtended> re("(h(e(?<llo>llo)))"); // group 0 -> "hello", group 1 -> "ello", group 2/"llo" -> "llo"
auto result = re.match("hello");
auto result = re.match("hello"sv);
EXPECT(result.success);
EXPECT_EQ(result.capture_group_matches.size(), 1u);
EXPECT_EQ(result.capture_group_matches[0].size(), 3u);
@ -661,7 +661,7 @@ TEST_CASE(ECMA262_match)
{ "(a{3}){2}"sv, "aaaabaa"sv, false },
{ "(a{4}){2}"sv, "aaaaaaaa"sv },
{ "(a{4}){2}"sv, "aaaaaabaa"sv, false },
{ "\\u{4}"sv, "uuuu" },
{ "\\u{4}"sv, "uuuu"sv },
{ "(?<=.{3})f"sv, "abcdef"sv, true, (ECMAScriptFlags)regex::AllFlags::Global },
{ "(?<=.{3})f"sv, "abc😀ef"sv, true, (ECMAScriptFlags)regex::AllFlags::Global },
// ECMA262, B.1.4. Regular Expression Pattern extensions for browsers
@ -876,7 +876,7 @@ TEST_CASE(replace)
TEST_CASE(case_insensitive_match)
{
Regex<PosixExtended> re("cd", PosixFlags::Insensitive | PosixFlags::Global);
auto result = re.match("AEKFCD");
auto result = re.match("AEKFCD"sv);
EXPECT_EQ(result.success, true);
if (result.success) {
@ -901,7 +901,7 @@ TEST_CASE(theoretically_infinite_loop)
};
for (auto& pattern : patterns) {
Regex<ECMA262> re(pattern);
auto result = re.match("");
auto result = re.match(""sv);
EXPECT_EQ(result.success, true);
}
}
@ -985,10 +985,10 @@ TEST_CASE(posix_basic_dollar_is_end_anchor)
// Ensure that a dollar sign at the end only matches the end of the line.
{
Regex<PosixBasic> re("abc$");
EXPECT_EQ(re.match("123abcdef", PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abc", PosixFlags::Global).success, true);
EXPECT_EQ(re.match("123abc$def", PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abc$", PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abcdef"sv, PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abc"sv, PosixFlags::Global).success, true);
EXPECT_EQ(re.match("123abc$def"sv, PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abc$"sv, PosixFlags::Global).success, false);
}
}
@ -997,19 +997,19 @@ TEST_CASE(posix_basic_dollar_is_literal)
// Ensure that a dollar sign in the middle is treated as a literal.
{
Regex<PosixBasic> re("abc$d");
EXPECT_EQ(re.match("123abcdef", PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abc", PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abc$def", PosixFlags::Global).success, true);
EXPECT_EQ(re.match("123abc$", PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abcdef"sv, PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abc"sv, PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abc$def"sv, PosixFlags::Global).success, true);
EXPECT_EQ(re.match("123abc$"sv, PosixFlags::Global).success, false);
}
// Ensure that a dollar sign is always treated as a literal if escaped, even if at the end of the pattern.
{
Regex<PosixBasic> re("abc\\$");
EXPECT_EQ(re.match("123abcdef", PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abc", PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abc$def", PosixFlags::Global).success, true);
EXPECT_EQ(re.match("123abc$", PosixFlags::Global).success, true);
EXPECT_EQ(re.match("123abcdef"sv, PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abc"sv, PosixFlags::Global).success, false);
EXPECT_EQ(re.match("123abc$def"sv, PosixFlags::Global).success, true);
EXPECT_EQ(re.match("123abc$"sv, PosixFlags::Global).success, true);
}
}
@ -1020,9 +1020,9 @@ TEST_CASE(negative_lookahead)
auto options = ECMAScriptOptions { ECMAScriptFlags::Global };
options.reset_flag((ECMAScriptFlags)regex::AllFlags::Internal_Stateful);
Regex<ECMA262> re(":(?!\\^\\)|1)", options);
EXPECT_EQ(re.match(":^)").success, false);
EXPECT_EQ(re.match(":1").success, false);
EXPECT_EQ(re.match(":foobar").success, true);
EXPECT_EQ(re.match(":^)"sv).success, false);
EXPECT_EQ(re.match(":1"sv).success, false);
EXPECT_EQ(re.match(":foobar"sv).success, true);
}
}
@ -1031,7 +1031,7 @@ TEST_CASE(single_match_flag)
{
// Ensure that only a single match is produced and nothing past that.
Regex<ECMA262> re("[\\u0008-\\uffff]"sv, ECMAScriptFlags::Global | (ECMAScriptFlags)regex::AllFlags::SingleMatch);
auto result = re.match("ABC");
auto result = re.match("ABC"sv);
EXPECT_EQ(result.success, true);
EXPECT_EQ(result.matches.size(), 1u);
EXPECT_EQ(result.matches.first().view.to_string(), "A"sv);
@ -1044,7 +1044,7 @@ TEST_CASE(inversion_state_in_char_class)
// #13755, /[\S\s]/.exec("hello") should be [ "h" ], not null.
Regex<ECMA262> re("[\\S\\s]", ECMAScriptFlags::Global | (ECMAScriptFlags)regex::AllFlags::SingleMatch);
auto result = re.match("hello");
auto result = re.match("hello"sv);
EXPECT_EQ(result.success, true);
EXPECT_EQ(result.matches.size(), 1u);
EXPECT_EQ(result.matches.first().view.to_string(), "h"sv);