Everywhere: Prefer using "..."sv over StringView { "..." }

This commit is contained in:
Gunnar Beutner 2021-07-04 11:08:46 +02:00 committed by Andreas Kling
parent ea8ff03475
commit 3bbe86d8ea
11 changed files with 35 additions and 35 deletions

View file

@ -39,9 +39,9 @@ TEST_CASE(reorder_format_arguments)
EXPECT_EQ(String::formatted("{1}{0}", "a", "b"), "ba");
EXPECT_EQ(String::formatted("{0}{1}", "a", "b"), "ab");
// Compiletime check bypass: ignoring a passed argument.
EXPECT_EQ(String::formatted(StringView { "{0}{0}{0}" }, "a", "b"), "aaa");
EXPECT_EQ(String::formatted("{0}{0}{0}"sv, "a", "b"), "aaa");
// Compiletime check bypass: ignoring a passed argument.
EXPECT_EQ(String::formatted(StringView { "{1}{}{0}" }, "a", "b", "c"), "baa");
EXPECT_EQ(String::formatted("{1}{}{0}"sv, "a", "b", "c"), "baa");
}
TEST_CASE(escape_braces)
@ -108,7 +108,7 @@ TEST_CASE(replacement_field)
EXPECT_EQ(String::formatted("{:*>{1}}", 13, static_cast<size_t>(10)), "********13");
EXPECT_EQ(String::formatted("{:*<{1}}", 7, 4), "7***");
// Compiletime check bypass: intentionally ignoring extra arguments
EXPECT_EQ(String::formatted(StringView { "{:{2}}" }, -5, 8, 16), " -5");
EXPECT_EQ(String::formatted("{:{2}}"sv, -5, 8, 16), " -5");
EXPECT_EQ(String::formatted("{{{:*^{1}}}}", 1, 3), "{*1*}");
EXPECT_EQ(String::formatted("{:0{}}", 1, 3), "001");
}
@ -116,7 +116,7 @@ TEST_CASE(replacement_field)
TEST_CASE(replacement_field_regression)
{
// FIXME: Compiletime check bypass: cannot parse '}}' correctly.
EXPECT_EQ(String::formatted(StringView { "{:{}}" }, "", static_cast<unsigned long>(6)), " ");
EXPECT_EQ(String::formatted("{:{}}"sv, "", static_cast<unsigned long>(6)), " ");
}
TEST_CASE(complex_string_specifiers)
@ -224,7 +224,7 @@ TEST_CASE(file_descriptor)
Array<u8, 256> buffer;
const auto nread = fread(buffer.data(), 1, buffer.size(), file);
EXPECT_EQ(StringView { "Hello, World!\nfoobar\n" }, StringView { buffer.span().trim(nread) });
EXPECT_EQ("Hello, World!\nfoobar\n"sv, StringView { buffer.span().trim(nread) });
fclose(file);
}

View file

@ -17,25 +17,25 @@ TEST_CASE(should_constexpr_construct_from_empty_string_view)
TEST_CASE(should_construct_from_string_view)
{
constexpr GenericLexer sut(StringView { "abcdef" });
constexpr GenericLexer sut("abcdef"sv);
static_assert(!sut.is_eof());
}
TEST_CASE(should_constexpr_tell)
{
constexpr GenericLexer sut(StringView { "abcdef" });
constexpr GenericLexer sut("abcdef"sv);
static_assert(sut.tell() == 0);
}
TEST_CASE(should_constexpr_tell_remaining)
{
constexpr GenericLexer sut(StringView { "abcdef" });
constexpr GenericLexer sut("abcdef"sv);
static_assert(sut.tell_remaining() == 6);
}
TEST_CASE(should_constexpr_peek)
{
constexpr GenericLexer sut(StringView { "abcdef" });
constexpr GenericLexer sut("abcdef"sv);
static_assert(sut.peek() == 'a');
static_assert(sut.peek(2) == 'c');
static_assert(sut.peek(100) == '\0');
@ -43,16 +43,16 @@ TEST_CASE(should_constexpr_peek)
TEST_CASE(should_constexpr_next_is)
{
constexpr GenericLexer sut(StringView { "abcdef" });
constexpr GenericLexer sut("abcdef"sv);
static_assert(sut.next_is('a'));
static_assert(sut.next_is("abc"));
static_assert(sut.next_is(StringView { "abc" }));
static_assert(sut.next_is("abc"sv));
}
TEST_CASE(should_constexpr_retreat)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.consume();
sut.retreat();
return sut;
@ -63,7 +63,7 @@ TEST_CASE(should_constexpr_retreat)
TEST_CASE(should_constexpr_consume_1)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.consume();
return sut;
}();
@ -73,7 +73,7 @@ TEST_CASE(should_constexpr_consume_1)
TEST_CASE(should_constexpr_consume_specific_char)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.consume_specific('a');
return sut;
}();
@ -83,8 +83,8 @@ TEST_CASE(should_constexpr_consume_specific_char)
TEST_CASE(should_constexpr_consume_specific_string_view)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
sut.consume_specific(StringView { "ab" });
GenericLexer sut("abcdef"sv);
sut.consume_specific("ab"sv);
return sut;
}();
static_assert(sut.peek() == 'c');
@ -93,7 +93,7 @@ TEST_CASE(should_constexpr_consume_specific_string_view)
TEST_CASE(should_constexpr_consume_specific_cstring)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.consume_specific("abcd");
return sut;
}();
@ -103,7 +103,7 @@ TEST_CASE(should_constexpr_consume_specific_cstring)
TEST_CASE(should_constexpr_ignore_until)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.ignore_until('d');
return sut;
}();
@ -113,7 +113,7 @@ TEST_CASE(should_constexpr_ignore_until)
TEST_CASE(should_constexpr_ignore_until_cstring)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.ignore_until("cde");
return sut;
}();
@ -125,7 +125,7 @@ TEST_CASE(should_constexpr_next_is_pred)
constexpr auto pred = [](auto c) {
return c == 'a';
};
constexpr GenericLexer sut(StringView { "abcdef" });
constexpr GenericLexer sut("abcdef"sv);
static_assert(sut.next_is(pred));
}
@ -136,7 +136,7 @@ TEST_CASE(should_constexpr_ignore_while_pred)
return c == 'a';
};
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.ignore_while(pred);
return sut;
}();
@ -150,7 +150,7 @@ TEST_CASE(should_constexpr_ignore_until_pred)
return c == 'c';
};
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.ignore_until(pred);
return sut;
}();

View file

@ -158,7 +158,7 @@ String Keypad::to_string() const
if (m_frac_length > 0) {
// FIXME: This disables the compiletime format string check since we can't parse '}}' here correctly.
// remove the 'StringView { }' when that's fixed.
builder.appendff(StringView { "{:0{}}" }, m_frac_value.value(), m_frac_length);
builder.appendff("{:0{}}"sv, m_frac_value.value(), m_frac_length);
}
return builder.to_string();

View file

@ -160,7 +160,7 @@ void HackStudioWidget::update_actions()
auto widget = m_action_tab_widget->active_widget();
if (!widget)
return false;
if (StringView { "TerminalWrapper" } != widget->class_name())
if ("TerminalWrapper"sv != widget->class_name())
return false;
if (!reinterpret_cast<TerminalWrapper*>(widget)->user_spawned())
return false;

View file

@ -149,7 +149,7 @@ void GMLAutocompleteProvider::provide_completions(Function<void(Vector<Entry>)>
identifier_entries.empend(it.key, identifier_string.length());
}
}
if (can_have_declared_layout(class_names.last()) && StringView { "layout" }.starts_with(identifier_string))
if (can_have_declared_layout(class_names.last()) && "layout"sv.starts_with(identifier_string))
identifier_entries.empend("layout", identifier_string.length());
// No need to suggest anything if it's already completely typed out!
if (identifier_entries.size() == 1 && identifier_entries.first().completion == identifier_string)

View file

@ -98,9 +98,9 @@ int main(int argc, char** argv)
.long_name = "show-progress",
.short_name = 'p',
.accept_value = [&](auto* str) {
if (StringView { "true" } == str)
if ("true"sv == str)
print_progress = true;
else if (StringView { "false" } == str)
else if ("false"sv == str)
print_progress = false;
else
return false;

View file

@ -138,7 +138,7 @@ int main(int argc, char** argv)
}
}
auto execute_file = file_to_read_from && StringView { "-" } != file_to_read_from;
auto execute_file = file_to_read_from && "-"sv != file_to_read_from;
attempt_interactive = !execute_file;
initialize();

View file

@ -577,7 +577,7 @@ int main(int argc, char** argv)
return 1;
}
if ((argc == 2 && StringView { "--help" } == argv[1]) || argc == 1)
if ((argc == 2 && "--help"sv == argv[1]) || argc == 1)
print_help_and_exit();
Queue<StringView> args;

View file

@ -59,11 +59,11 @@ int main(int argc, char** argv)
.help_string = "Action to take for binary files ([binary], text, skip)",
.long_name = "binary-mode",
.accept_value = [&](auto* str) {
if (StringView { "text" } == str)
if ("text"sv == str)
binary_mode = BinaryFileMode::Text;
else if (StringView { "binary" } == str)
else if ("binary"sv == str)
binary_mode = BinaryFileMode::Binary;
else if (StringView { "skip" } == str)
else if ("skip"sv == str)
binary_mode = BinaryFileMode::Skip;
else
return false;

View file

@ -276,9 +276,9 @@ int main(int argc, char** argv)
.long_name = "show-progress",
.short_name = 'p',
.accept_value = [&](auto* str) {
if (StringView { "true" } == str)
if ("true"sv == str)
print_progress = true;
else if (StringView { "false" } == str)
else if ("false"sv == str)
print_progress = false;
else
return false;

View file

@ -89,7 +89,7 @@ int main(int argc, char** argv)
FILE* fp = stdin;
bool is_stdin = true;
if (StringView { "-" } != file_to_read) {
if ("-"sv != file_to_read) {
// A file was specified, try to open it.
fp = fopen(file_to_read, "re");
if (!fp) {