summaryrefslogtreecommitdiff
path: root/Userland/Shell
diff options
context:
space:
mode:
authorsin-ack <sin-ack@users.noreply.github.com>2022-07-11 17:32:29 +0000
committerAndreas Kling <kling@serenityos.org>2022-07-12 23:11:35 +0200
commit3f3f45580ab7266258e97cb3cecf1e24716d61c5 (patch)
tree152c7a187c98184d58bf91a326357e0af435edcf /Userland/Shell
parente5f09ea1703bacfbb79a4ad3c587a7d5d3d7bb13 (diff)
downloadserenity-3f3f45580ab7266258e97cb3cecf1e24716d61c5.zip
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.
Diffstat (limited to 'Userland/Shell')
-rw-r--r--Userland/Shell/AST.cpp138
-rw-r--r--Userland/Shell/Builtin.cpp6
-rw-r--r--Userland/Shell/Formatter.cpp88
-rw-r--r--Userland/Shell/ImmediateFunctions.cpp10
-rw-r--r--Userland/Shell/Parser.cpp104
-rw-r--r--Userland/Shell/Shell.cpp108
6 files changed, 227 insertions, 227 deletions
diff --git a/Userland/Shell/AST.cpp b/Userland/Shell/AST.cpp
index 05f3e1fec5..56012ed9d1 100644
--- a/Userland/Shell/AST.cpp
+++ b/Userland/Shell/AST.cpp
@@ -35,12 +35,12 @@ ErrorOr<void> AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder,
VERIFY_NOT_REACHED();
if (value.argv.is_empty()) {
- TRY(builder.put_literal("(ShellInternal)"));
+ TRY(builder.put_literal("(ShellInternal)"sv));
} else {
bool first = true;
for (auto& arg : value.argv) {
if (!first)
- TRY(builder.put_literal(" "));
+ TRY(builder.put_literal(" "sv));
first = false;
TRY(builder.put_literal(arg));
}
@@ -53,28 +53,28 @@ ErrorOr<void> AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder,
TRY(builder.put_i64(path_redir->fd));
switch (path_redir->direction) {
case Shell::AST::PathRedirection::Read:
- TRY(builder.put_literal("<"));
+ TRY(builder.put_literal("<"sv));
break;
case Shell::AST::PathRedirection::Write:
- TRY(builder.put_literal(">"));
+ TRY(builder.put_literal(">"sv));
break;
case Shell::AST::PathRedirection::WriteAppend:
- TRY(builder.put_literal(">>"));
+ TRY(builder.put_literal(">>"sv));
break;
case Shell::AST::PathRedirection::ReadWrite:
- TRY(builder.put_literal("<>"));
+ TRY(builder.put_literal("<>"sv));
break;
}
TRY(builder.put_literal(path_redir->path));
} else if (redir.is_fd_redirection()) {
auto* fdredir = (Shell::AST::FdRedirection const*)&redir;
TRY(builder.put_i64(fdredir->new_fd));
- TRY(builder.put_literal(">"));
+ TRY(builder.put_literal(">"sv));
TRY(builder.put_i64(fdredir->old_fd));
} else if (redir.is_close_redirection()) {
auto close_redir = (Shell::AST::CloseRedirection const*)&redir;
TRY(builder.put_i64(close_redir->fd));
- TRY(builder.put_literal(">&-"));
+ TRY(builder.put_literal(">&-"sv));
} else {
VERIFY_NOT_REACHED();
}
@@ -84,23 +84,23 @@ ErrorOr<void> AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder,
for (auto& command : value.next_chain) {
switch (command.action) {
case Shell::AST::NodeWithAction::And:
- TRY(builder.put_literal(" && "));
+ TRY(builder.put_literal(" && "sv));
break;
case Shell::AST::NodeWithAction::Or:
- TRY(builder.put_literal(" || "));
+ TRY(builder.put_literal(" || "sv));
break;
case Shell::AST::NodeWithAction::Sequence:
- TRY(builder.put_literal("; "));
+ TRY(builder.put_literal("; "sv));
break;
}
- TRY(builder.put_literal("("));
+ TRY(builder.put_literal("("sv));
TRY(builder.put_literal(command.node->class_name()));
- TRY(builder.put_literal("...)"));
+ TRY(builder.put_literal("...)"sv));
}
}
if (!value.should_wait)
- TRY(builder.put_literal("&"));
+ TRY(builder.put_literal("&"sv));
return {};
}
@@ -367,8 +367,8 @@ Vector<Line::CompletionSuggestion> Node::complete_for_editor(Shell& shell, size_
return {};
// If the literal isn't an option, treat it as a path.
- if (!(text.starts_with("-") || text == "--" || text == "-"))
- return set_results_trivia(shell.complete_path("", text, corrected_offset, Shell::ExecutableOnly::No, hit_test_result.closest_command_node.ptr(), hit_test_result.matching_node, escape_mode));
+ if (!(text.starts_with('-') || text == "--" || text == "-"))
+ return set_results_trivia(shell.complete_path(""sv, text, corrected_offset, Shell::ExecutableOnly::No, hit_test_result.closest_command_node.ptr(), hit_test_result.matching_node, escape_mode));
// If the literal is an option, we have to know the program name
// should we have no way to get that, bail early.
@@ -392,7 +392,7 @@ Vector<Line::CompletionSuggestion> Node::complete_for_editor(Shell& shell, size_
}
auto result = hit_test_position(offset);
if (!result.matching_node)
- return shell.complete_path("", "", 0, Shell::ExecutableOnly::No, result.closest_command_node.ptr(), nullptr, Shell::EscapeMode::Bareword);
+ return shell.complete_path(""sv, ""sv, 0, Shell::ExecutableOnly::No, result.closest_command_node.ptr(), nullptr, Shell::EscapeMode::Bareword);
auto node = result.matching_node;
if (node->is_bareword() || node != result.closest_node_with_semantic_meaning)
@@ -651,7 +651,7 @@ void BarewordLiteral::highlight_in_editor(Line::Editor& editor, Shell& shell, Hi
if (m_text == "-")
return;
- if (m_text.starts_with("--")) {
+ if (m_text.starts_with("--"sv)) {
auto index = m_text.find('=').value_or(m_text.length() - 1) + 1;
editor.stylize({ m_position.start_offset, m_position.start_offset + index }, { Line::Style::Foreground(Line::Style::XtermColor::Cyan) });
} else {
@@ -798,7 +798,7 @@ void CastToList::dump(int level) const
if (m_inner)
m_inner->dump(level + 1);
else
- print_indented("(empty)", level + 1);
+ print_indented("(empty)"sv, level + 1);
}
RefPtr<Value> CastToList::run(RefPtr<Shell> shell)
@@ -934,7 +934,7 @@ Comment::~Comment()
void ContinuationControl::dump(int level) const
{
Node::dump(level);
- print_indented(m_kind == Continue ? "(Continue)" : "(Break)", level + 1);
+ print_indented(m_kind == Continue ? "(Continue)"sv : "(Break)"sv, level + 1);
}
RefPtr<Value> ContinuationControl::run(RefPtr<Shell> shell)
@@ -964,7 +964,7 @@ RefPtr<Value> DoubleQuotedString::run(RefPtr<Shell> shell)
StringBuilder builder;
auto values = m_inner->run(shell)->resolve_as_list(shell);
- builder.join("", values);
+ builder.join(""sv, values);
return make_ref_counted<StringValue>(builder.to_string());
}
@@ -1079,15 +1079,15 @@ void FunctionDeclaration::dump(int level) const
{
Node::dump(level);
print_indented(String::formatted("(name: {})\n", m_name.name), level + 1);
- print_indented("(argument names)", level + 1);
+ print_indented("(argument names)"sv, level + 1);
for (auto& arg : m_arguments)
print_indented(String::formatted("(name: {})\n", arg.name), level + 2);
- print_indented("(body)", level + 1);
+ print_indented("(body)"sv, level + 1);
if (m_block)
m_block->dump(level + 2);
else
- print_indented("(null)", level + 2);
+ print_indented("(null)"sv, level + 2);
}
RefPtr<Value> FunctionDeclaration::run(RefPtr<Shell> shell)
@@ -1173,12 +1173,12 @@ void ForLoop::dump(int level) const
if (m_iterated_expression)
m_iterated_expression->dump(level + 2);
else
- print_indented("(ever)", level + 2);
- print_indented("Running", level + 1);
+ print_indented("(ever)"sv, level + 2);
+ print_indented("Running"sv, level + 1);
if (m_block)
m_block->dump(level + 2);
else
- print_indented("(null)", level + 2);
+ print_indented("(null)"sv, level + 2);
}
RefPtr<Value> ForLoop::run(RefPtr<Shell> shell)
@@ -1362,15 +1362,15 @@ Glob::~Glob()
void Heredoc::dump(int level) const
{
Node::dump(level);
- print_indented("(End Key)", level + 1);
+ print_indented("(End Key)"sv, level + 1);
print_indented(m_end, level + 2);
- print_indented("(Allows Interpolation)", level + 1);
+ print_indented("(Allows Interpolation)"sv, level + 1);
print_indented(String::formatted("{}", m_allows_interpolation), level + 2);
- print_indented("(Contents)", level + 1);
+ print_indented("(Contents)"sv, level + 1);
if (m_contents)
m_contents->dump(level + 2);
else
- print_indented("(null)", level + 2);
+ print_indented("(null)"sv, level + 2);
}
RefPtr<Value> Heredoc::run(RefPtr<Shell> shell)
@@ -1437,24 +1437,24 @@ Heredoc::~Heredoc()
void HistoryEvent::dump(int level) const
{
Node::dump(level);
- print_indented("Event Selector", level + 1);
+ print_indented("Event Selector"sv, level + 1);
switch (m_selector.event.kind) {
case HistorySelector::EventKind::IndexFromStart:
- print_indented("IndexFromStart", level + 2);
+ print_indented("IndexFromStart"sv, level + 2);
break;
case HistorySelector::EventKind::IndexFromEnd:
- print_indented("IndexFromEnd", level + 2);
+ print_indented("IndexFromEnd"sv, level + 2);
break;
case HistorySelector::EventKind::ContainingStringLookup:
- print_indented("ContainingStringLookup", level + 2);
+ print_indented("ContainingStringLookup"sv, level + 2);
break;
case HistorySelector::EventKind::StartingStringLookup:
- print_indented("StartingStringLookup", level + 2);
+ print_indented("StartingStringLookup"sv, level + 2);
break;
}
print_indented(String::formatted("{}({})", m_selector.event.index, m_selector.event.text), level + 3);
- print_indented("Word Selector", level + 1);
+ print_indented("Word Selector"sv, level + 1);
auto print_word_selector = [&](HistorySelector::WordSelector const& selector) {
switch (selector.kind) {
case HistorySelector::WordSelectorKind::Index:
@@ -1467,12 +1467,12 @@ void HistoryEvent::dump(int level) const
};
if (m_selector.word_selector_range.end.has_value()) {
- print_indented("Range Start", level + 2);
+ print_indented("Range Start"sv, level + 2);
print_word_selector(m_selector.word_selector_range.start);
- print_indented("Range End", level + 2);
+ print_indented("Range End"sv, level + 2);
print_word_selector(m_selector.word_selector_range.end.value());
} else {
- print_indented("Direct Address", level + 2);
+ print_indented("Direct Address"sv, level + 2);
print_word_selector(m_selector.word_selector_range.start);
}
}
@@ -1593,7 +1593,7 @@ void Execute::dump(int level) const
{
Node::dump(level);
if (m_capture_stdout)
- print_indented("(Capturing stdout)", level + 1);
+ print_indented("(Capturing stdout)"sv, level + 1);
m_command->dump(level + 1);
}
@@ -1649,7 +1649,7 @@ void Execute::for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(Non
NothingLeft,
};
auto check_and_call = [&] {
- auto ifs = shell->local_variable_or("IFS", "\n");
+ auto ifs = shell->local_variable_or("IFS"sv, "\n"sv);
if (auto offset = stream.offset_of(ifs.bytes()); offset.has_value()) {
auto line_end = offset.value();
@@ -1846,18 +1846,18 @@ Execute::~Execute()
void IfCond::dump(int level) const
{
Node::dump(level);
- print_indented("Condition", ++level);
+ print_indented("Condition"sv, ++level);
m_condition->dump(level + 1);
- print_indented("True Branch", level);
+ print_indented("True Branch"sv, level);
if (m_true_branch)
m_true_branch->dump(level + 1);
else
- print_indented("(empty)", level + 1);
- print_indented("False Branch", level);
+ print_indented("(empty)"sv, level + 1);
+ print_indented("False Branch"sv, level);
if (m_false_branch)
m_false_branch->dump(level + 1);
else
- print_indented("(empty)", level + 1);
+ print_indented("(empty)"sv, level + 1);
}
RefPtr<Value> IfCond::run(RefPtr<Shell> shell)
@@ -1957,9 +1957,9 @@ IfCond::~IfCond()
void ImmediateExpression::dump(int level) const
{
Node::dump(level);
- print_indented("(function)", level + 1);
+ print_indented("(function)"sv, level + 1);
print_indented(m_function.name, level + 2);
- print_indented("(arguments)", level + 1);
+ print_indented("(arguments)"sv, level + 1);
for (auto& argument : arguments())
argument.dump(level + 2);
}
@@ -2115,12 +2115,12 @@ void MatchExpr::dump(int level) const
print_indented(String::formatted("(expression: {})", m_expr_name.characters()), level + 1);
m_matched_expr->dump(level + 2);
print_indented(String::formatted("(named: {})", m_expr_name.characters()), level + 1);
- print_indented("(entries)", level + 1);
+ print_indented("(entries)"sv, level + 1);
for (auto& entry : m_entries) {
StringBuilder builder;
- builder.append("(match");
+ builder.append("(match"sv);
if (entry.match_names.has_value()) {
- builder.append(" to names (");
+ builder.append(" to names ("sv);
bool first = true;
for (auto& name : entry.match_names.value()) {
if (!first)
@@ -2128,7 +2128,7 @@ void MatchExpr::dump(int level) const
first = false;
builder.append(name);
}
- builder.append("))");
+ builder.append("))"sv);
} else {
builder.append(')');
@@ -2143,11 +2143,11 @@ void MatchExpr::dump(int level) const
for (auto& option : options)
print_indented(String::formatted("(regex: {})", option.pattern_value), level + 3);
});
- print_indented("(execute)", level + 2);
+ print_indented("(execute)"sv, level + 2);
if (entry.body)
entry.body->dump(level + 3);
else
- print_indented("(nothing)", level + 3);
+ print_indented("(nothing)"sv, level + 3);
}
}
@@ -2522,7 +2522,7 @@ Vector<Line::CompletionSuggestion> PathRedirectionNode::complete_for_editor(Shel
if (corrected_offset > node->text().length())
return {};
- return shell.complete_path("", node->text(), corrected_offset, Shell::ExecutableOnly::No, nullptr, nullptr);
+ return shell.complete_path(""sv, node->text(), corrected_offset, Shell::ExecutableOnly::No, nullptr, nullptr);
}
PathRedirectionNode::~PathRedirectionNode()
@@ -2532,9 +2532,9 @@ PathRedirectionNode::~PathRedirectionNode()
void Range::dump(int level) const
{
Node::dump(level);
- print_indented("(From)", level + 1);
+ print_indented("(From)"sv, level + 1);
m_start->dump(level + 2);
- print_indented("(To)", level + 1);
+ print_indented("(To)"sv, level + 1);
m_end->dump(level + 2);
}
@@ -2872,13 +2872,13 @@ Slice::~Slice()
void SimpleVariable::dump(int level) const
{
Node::dump(level);
- print_indented("(Name)", level + 1);
+ print_indented("(Name)"sv, level + 1);
print_indented(m_name, level + 2);
- print_indented("(Slice)", level + 1);
+ print_indented("(Slice)"sv, level + 1);
if (m_slice)
m_slice->dump(level + 2);
else
- print_indented("(None)", level + 2);
+ print_indented("(None)"sv, level + 2);
}
RefPtr<Value> SimpleVariable::run(RefPtr<Shell>)
@@ -2940,13 +2940,13 @@ SimpleVariable::~SimpleVariable()
void SpecialVariable::dump(int level) const
{
Node::dump(level);
- print_indented("(Name)", level + 1);
+ print_indented("(Name)"sv, level + 1);
print_indented(String { &m_name, 1 }, level + 1);
- print_indented("(Slice)", level + 1);
+ print_indented("(Slice)"sv, level + 1);
if (m_slice)
m_slice->dump(level + 2);
else
- print_indented("(None)", level + 2);
+ print_indented("(None)"sv, level + 2);
}
RefPtr<Value> SpecialVariable::run(RefPtr<Shell>)
@@ -3221,9 +3221,9 @@ StringPartCompose::~StringPartCompose()
void SyntaxError::dump(int level) const
{
Node::dump(level);
- print_indented("(Error text)", level + 1);
+ print_indented("(Error text)"sv, level + 1);
print_indented(m_syntax_error_text, level + 2);
- print_indented("(Can be recovered from)", level + 1);
+ print_indented("(Can be recovered from)"sv, level + 1);
print_indented(String::formatted("{}", m_is_continuable), level + 2);
}
@@ -3396,7 +3396,7 @@ void VariableDeclarations::dump(int level) const
{
Node::dump(level);
for (auto& var : m_variables) {
- print_indented("Set", level + 1);
+ print_indented("Set"sv, level + 1);
var.name->dump(level + 2);
var.value->dump(level + 2);
}
@@ -3687,11 +3687,11 @@ Vector<String> SpecialVariableValue::resolve_as_list(RefPtr<Shell> shell)
case '$':
return { resolve_slices(shell, String::number(getpid()), m_slices) };
case '*':
- if (auto argv = shell->lookup_local_variable("ARGV"))
+ if (auto argv = shell->lookup_local_variable("ARGV"sv))
return resolve_slices(shell, argv->resolve_as_list(shell), m_slices);
return resolve_slices(shell, Vector<String> {}, m_slices);
case '#':
- if (auto argv = shell->lookup_local_variable("ARGV")) {
+ if (auto argv = shell->lookup_local_variable("ARGV"sv)) {
if (argv->is_list()) {
auto list_argv = static_cast<AST::ListValue*>(argv.ptr());
return { resolve_slices(shell, String::number(list_argv->values().size()), m_slices) };
diff --git a/Userland/Shell/Builtin.cpp b/Userland/Shell/Builtin.cpp
index 28ffe7cbac..7402220c06 100644
--- a/Userland/Shell/Builtin.cpp
+++ b/Userland/Shell/Builtin.cpp
@@ -213,7 +213,7 @@ int Shell::builtin_type(int argc, char const** argv)
if (!(i == fn.arguments.size() - 1))
builder.append(" ");
}
- builder.append(") {\n");
+ builder.append(") {\n"sv);
if (fn.body) {
auto formatter = Formatter(*fn.body);
builder.append(formatter.format());
@@ -831,7 +831,7 @@ int Shell::builtin_shift(int argc, char const** argv)
if (count < 1)
return 0;
- auto argv_ = lookup_local_variable("ARGV");
+ auto argv_ = lookup_local_variable("ARGV"sv);
if (!argv_) {
warnln("shift: ARGV is unset");
return 1;
@@ -864,7 +864,7 @@ int Shell::builtin_source(int argc, char const** argv)
if (!parser.parse(argc, const_cast<char**>(argv)))
return 1;
- auto previous_argv = lookup_local_variable("ARGV");
+ auto previous_argv = lookup_local_variable("ARGV"sv);
ScopeGuard guard { [&] {
if (!args.is_empty())
set_local_variable("ARGV", move(previous_argv));
diff --git a/Userland/Shell/Formatter.cpp b/Userland/Shell/Formatter.cpp
index 5f3ab9d840..9514318c5a 100644
--- a/Userland/Shell/Formatter.cpp
+++ b/Userland/Shell/Formatter.cpp
@@ -123,7 +123,7 @@ void Formatter::insert_separator(bool escaped)
void Formatter::insert_indent()
{
for (size_t i = 0; i < m_current_indent; ++i)
- current_builder().append(" ");
+ current_builder().append(" "sv);
}
void Formatter::visit(const AST::PathRedirectionNode* node)
@@ -147,7 +147,7 @@ void Formatter::visit(const AST::And* node)
current_builder().append(' ');
insert_separator(true);
- current_builder().append("&& ");
+ current_builder().append("&& "sv);
node->right()->visit(*this);
});
@@ -177,7 +177,7 @@ void Formatter::visit(const AST::Background* node)
TemporaryChange<const AST::Node*> parent { m_parent_node, node };
NodeVisitor::visit(node);
- current_builder().append(" &");
+ current_builder().append(" &"sv);
visited(node);
}
@@ -255,7 +255,7 @@ void Formatter::visit(const AST::Comment* node)
{
will_visit(node);
test_and_update_output_cursor(node);
- current_builder().append("#");
+ current_builder().append("#"sv);
current_builder().append(node->text());
visited(node);
}
@@ -265,9 +265,9 @@ void Formatter::visit(const AST::ContinuationControl* node)
will_visit(node);
test_and_update_output_cursor(node);
if (node->continuation_kind() == AST::ContinuationControl::Break)
- current_builder().append("break");
+ current_builder().append("break"sv);
else if (node->continuation_kind() == AST::ContinuationControl::Continue)
- current_builder().append("continue");
+ current_builder().append("continue"sv);
else
VERIFY_NOT_REACHED();
visited(node);
@@ -289,7 +289,7 @@ void Formatter::visit(const AST::DoubleQuotedString* node)
test_and_update_output_cursor(node);
auto not_in_heredoc = m_parent_node->kind() != AST::Node::Kind::Heredoc;
if (not_in_heredoc)
- current_builder().append("\"");
+ current_builder().append("\""sv);
TemporaryChange quotes { m_options.in_double_quotes, true };
TemporaryChange<const AST::Node*> parent { m_parent_node, node };
@@ -297,7 +297,7 @@ void Formatter::visit(const AST::DoubleQuotedString* node)
NodeVisitor::visit(node);
if (not_in_heredoc)
- current_builder().append("\"");
+ current_builder().append("\""sv);
visited(node);
}
@@ -329,7 +329,7 @@ void Formatter::visit(const AST::FunctionDeclaration* node)
current_builder().append(arg.name);
}
- current_builder().append(") ");
+ current_builder().append(") "sv);
in_new_block([&] {
if (node->block())
@@ -343,18 +343,18 @@ void Formatter::visit(const AST::ForLoop* node)
will_visit(node);
test_and_update_output_cursor(node);
auto is_loop = node->iterated_expression().is_null();
- current_builder().append(is_loop ? "loop" : "for ");
+ current_builder().append(is_loop ? "loop"sv : "for "sv);
TemporaryChange<const AST::Node*> parent { m_parent_node, node };
if (!is_loop) {
if (node->index_variable().has_value()) {
- current_builder().append("index ");
+ current_builder().append("index "sv);
current_builder().append(node->index_variable()->name);
- current_builder().append(" ");
+ current_builder().append(" "sv);
}
if (node->variable().has_value() && node->variable()->name != "it") {
current_builder().append(node->variable()->name);
- current_builder().append(" in ");
+ current_builder().append(" in "sv);
}
node->iterated_expression()->visit(*this);
@@ -381,7 +381,7 @@ void Formatter::visit(const AST::Heredoc* node)
will_visit(node);
test_and_update_output_cursor(node);
- current_builder().append("<<");
+ current_builder().append("<<"sv);
if (node->deindent())
current_builder().append('~');
else
@@ -474,12 +474,12 @@ void Formatter::visit(const AST::Execute* node)
ScopedValueRollback options_rollback { m_options };
if (node->does_capture_stdout())
- builder.append("$(");
+ builder.append("$("sv);
NodeVisitor::visit(node);
if (node->does_capture_stdout())
- builder.append(")");
+ builder.append(")"sv);
visited(node);
}
@@ -489,7 +489,7 @@ void Formatter::visit(const AST::IfCond* node)
will_visit(node);
test_and_update_output_cursor(node);
- current_builder().append("if ");
+ current_builder().append("if "sv);
TemporaryChange<const AST::Node*> parent { m_parent_node, node };
node->condition()->visit(*this);
@@ -502,7 +502,7 @@ void Formatter::visit(const AST::IfCond* node)
});
if (node->false_branch()) {
- current_builder().append(" else ");
+ current_builder().append(" else "sv);
if (node->false_branch()->kind() != AST::Node::Kind::IfCond) {
in_new_block([&] {
node->false_branch()->visit(*this);
@@ -511,7 +511,7 @@ void Formatter::visit(const AST::IfCond* node)
node->false_branch()->visit(*this);
}
} else if (node->else_position().has_value()) {
- current_builder().append(" else ");
+ current_builder().append(" else "sv);
}
visited(node);
}
@@ -521,7 +521,7 @@ void Formatter::visit(const AST::ImmediateExpression* node)
will_visit(node);
test_and_update_output_cursor(node);
- current_builder().append("${");
+ current_builder().append("${"sv);
TemporaryChange<const AST::Node*> parent { m_parent_node, node };
current_builder().append(node->function_name());
@@ -564,14 +564,14 @@ void Formatter::visit(const AST::MatchExpr* node)
{
will_visit(node);
test_and_update_output_cursor(node);
- current_builder().append("match ");
+ current_builder().append("match "sv);
TemporaryChange<const AST::Node*> parent { m_parent_node, node };
node->matched_expr()->visit(*this);
if (!node->expr_name().is_empty()) {
- current_builder().append(" as ");
+ current_builder().append(" as "sv);
current_builder().append(node->expr_name());
}
@@ -587,7 +587,7 @@ void Formatter::visit(const AST::MatchExpr* node)
[&](NonnullRefPtrVector<AST::Node> const& patterns) {
for (auto& option : patterns) {
if (!first)
- current_builder().append(" | ");
+ current_builder().append(" | "sv);
first = false;
option.visit(*this);
}
@@ -595,7 +595,7 @@ void Formatter::visit(const AST::MatchExpr* node)
[&](Vector<Regex<ECMA262>> const& patterns) {
for (auto& option : patterns) {
if (!first)
- current_builder().append(" | ");
+ current_builder().append(" | "sv);
first = false;
auto node = make_ref_counted<AST::BarewordLiteral>(AST::Position {}, option.pattern_value);
node->visit(*this);
@@ -604,7 +604,7 @@ void Formatter::visit(const AST::MatchExpr* node)
current_builder().append(' ');
if (entry.match_names.has_value() && !entry.match_names.value().is_empty()) {
- current_builder().append("as (");
+ current_builder().append("as ("sv);
auto first = true;
for (auto& name : entry.match_names.value()) {
if (!first)
@@ -612,7 +612,7 @@ void Formatter::visit(const AST::MatchExpr* node)
first = false;
current_builder().append(name);
}
- current_builder().append(") ");
+ current_builder().append(") "sv);
}
in_new_block([&] {
if (entry.body)
@@ -633,9 +633,9 @@ void Formatter::visit(const AST::Or* node)
with_added_indent(should_indent ? 1 : 0, [&] {
node->left()->visit(*this);
- current_builder().append(" ");
+ current_builder().append(" "sv);
insert_separator(true);
- current_builder().append("|| ");
+ current_builder().append("|| "sv);
node->right()->visit(*this);
});
@@ -650,11 +650,11 @@ void Formatter::visit(const AST::Pipe* node)
TemporaryChange<const AST::Node*> parent { m_parent_node, node };
node->left()->visit(*this);
- current_builder().append(" ");
+ current_builder().append(" "sv);
with_added_indent(should_indent ? 1 : 0, [&] {
insert_separator(true);
- current_builder().append("| ");
+ current_builder().append("| "sv);
node->right()->visit(*this);
});
@@ -670,7 +670,7 @@ void Formatter::visit(const AST::Range* node)
TemporaryChange<const AST::Node*> parent { m_parent_node, node };
node->start()->visit(*this);
- current_builder().append("..");
+ current_builder().append(".."sv);
node->end()->visit(*this);
if (!m_parent_node || m_parent_node->kind() != AST::Node::Kind::Slice)
@@ -687,7 +687,7 @@ void Formatter::visit(const AST::ReadRedirection* node)
if (node->fd() != 0)
current_builder().appendff(" {}<", node->fd());
else
- current_builder().append(" <");
+ current_builder().append(" <"sv);
NodeVisitor::visit(node);
visited(node);
}
@@ -701,7 +701,7 @@ void Formatter::visit(const AST::ReadWriteRedirection* node)
if (node->fd() != 0)
current_builder().appendff(" {}<>", node->fd());
else
- current_builder().append(" <>");
+ current_builder().append(" <>"sv);
NodeVisitor::visit(node);
visited(node);
}
@@ -787,7 +787,7 @@ void Formatter::visit(const AST::StringLiteral* node)
will_visit(node);
test_and_update_output_cursor(node);
if (!m_options.in_double_quotes && !m_options.in_heredoc)
- current_builder().append("'");
+ current_builder().append("'"sv);
if (m_options.in_double_quotes && !m_options.in_heredoc) {
for (auto ch : node->text()) {
@@ -798,25 +798,25 @@ void Formatter::visit(const AST::StringLiteral* node)
current_builder().append('\\');
break;
case '\n':
- current_builder().append("\\n");
+ current_builder().append("\\n"sv);
continue;
case '\r':
- current_builder().append("\\r");
+ current_builder().append("\\r"sv);
continue;
case '\t':
- current_builder().append("\\t");
+ current_builder().append("\\t"sv);
continue;
case '\v':
- current_builder().append("\\v");
+ current_builder().append("\\v"sv);
continue;
case '\f':
- current_builder().append("\\f");
+ current_builder().append("\\f"sv);
continue;
case '\a':
- current_builder().append("\\a");
+ current_builder().append("\\a"sv);
continue;
case '\e':
- current_builder().append("\\e");
+ current_builder().append("\\e"sv);
continue;
default:
break;
@@ -828,7 +828,7 @@ void Formatter::visit(const AST::StringLiteral* node)
}
if (!m_options.in_double_quotes && !m_options.in_heredoc)
- current_builder().append("'");
+ current_builder().append("'"sv);
visited(node);
}
@@ -892,7 +892,7 @@ void Formatter::visit(const AST::WriteAppendRedirection* node)
if (node->fd() != 1)
current_builder().appendff(" {}>>", node->fd());
else
- current_builder().append(" >>");
+ current_builder().append(" >>"sv);
NodeVisitor::visit(node);
visited(node);
}
@@ -906,7 +906,7 @@ void Formatter::visit(const AST::WriteRedirection* node)
if (node->fd() != 1)
current_builder().appendff(" {}>", node->fd());
else
- current_builder().append(" >");
+ current_builder().append(" >"sv);
NodeVisitor::visit(node);
visited(node);
}
diff --git a/Userland/Shell/ImmediateFunctions.cpp b/Userland/Shell/ImmediateFunctions.cpp
index 2791d7b185..eb65f014dd 100644
--- a/Userland/Shell/ImmediateFunctions.cpp
+++ b/Userland/Shell/ImmediateFunctions.cpp
@@ -72,7 +72,7 @@ RefPtr<AST::Node> Shell::immediate_length_impl(AST::ImmediateExpression& invokin
auto do_across = [&](StringView mode_name, auto& values) {
if (is_inferred)
- mode_name = "infer";
+ mode_name = "infer"sv;
// Translate to a list of applications of `length <mode_name>`
Vector<NonnullRefPtr<AST::Node>> resulting_nodes;
resulting_nodes.ensure_capacity(values.size());
@@ -104,7 +104,7 @@ RefPtr<AST::Node> Shell::immediate_length_impl(AST::ImmediateExpression& invokin
if (auto list = dynamic_cast<AST::ListValue*>(value.ptr())) {
if (across)
- return do_across("list", list->values());
+ return do_across("list"sv, list->values());
return value_with_number(list->values().size());
}
@@ -115,7 +115,7 @@ RefPtr<AST::Node> Shell::immediate_length_impl(AST::ImmediateExpression& invokin
dbgln("List has {} entries", list.size());
auto values = AST::make_ref_counted<AST::ListValue>(move(list));
- return do_across("list", values->values());
+ return do_across("list"sv, values->values());
}
case String: {
// 'across' will only accept lists, and '!across' will only accept non-lists here.
@@ -151,7 +151,7 @@ RefPtr<AST::Node> Shell::immediate_length_impl(AST::ImmediateExpression& invokin
if (!across)
goto raise_no_list_allowed;
- return do_across("string", list->values());
+ return do_across("string"sv, list->values());
}
if (across && !value->is_list()) {
@@ -184,7 +184,7 @@ RefPtr<AST::Node> Shell::immediate_length_impl(AST::ImmediateExpression& invokin
}
auto values = AST::make_ref_counted<AST::ListValue>(move(list));
- return do_across("string", values->values());
+ return do_across("string"sv, values->values());
}
}
}
diff --git a/Userland/Shell/Parser.cpp b/Userland/Shell/Parser.cpp
index 22826199fb..fd6f0380b3 100644
--- a/Userland/Shell/Parser.cpp
+++ b/Userland/Shell/Parser.cpp
@@ -192,7 +192,7 @@ Parser::SequenceParseResult Parser::parse_sequence()
auto read_terminators = [&](bool consider_tabs_and_spaces) {
if (m_heredoc_initiations.is_empty()) {
discard_terminators:;
- consume_while(is_any_of(consider_tabs_and_spaces ? " \t\n;" : "\n;"));
+ consume_while(is_any_of(consider_tabs_and_spaces ? " \t\n;"sv : "\n;"sv));
} else {
for (;;) {
if (consider_tabs_and_spaces && (peek() == '\t' || peek() == ' ')) {
@@ -208,7 +208,7 @@ Parser::SequenceParseResult Parser::parse_sequence()
consume();
if (!parse_heredoc_entries()) {
StringBuilder error_builder;
- error_builder.append("Expected to find heredoc entries for ");
+ error_builder.append("Expected to find heredoc entries for "sv);
bool first = true;
for (auto& entry : m_heredoc_initiations) {
if (first)
@@ -249,7 +249,7 @@ Parser::SequenceParseResult Parser::parse_sequence()
if (left.is_empty())
break;
- consume_while(is_any_of("\n;"));
+ consume_while(is_any_of("\n;"sv));
auto pos_after_seps = save_offset();
AST::Position separator_position { pos_before_seps.offset, pos_after_seps.offset, pos_before_seps.line, pos_after_seps.line };
@@ -280,7 +280,7 @@ Parser::SequenceParseResult Parser::parse_sequence()
read_terminators(false);
[[fallthrough]];
case ';': {
- consume_while(is_any_of("\n;"));
+ consume_while(is_any_of("\n;"sv));
auto pos_after_seps = save_offset();
separator_positions.empend(pos_before_seps.offset, pos_after_seps.offset, pos_before_seps.line, pos_after_seps.line);
return { move(left), move(separator_positions), ShouldReadMoreSequences::Yes };
@@ -394,7 +394,7 @@ RefPtr<AST::Node> Parser::parse_function_decl()
arguments.append({ arg_name, { name_offset, m_offset, start_line, line() } });
}
- consume_while(is_any_of("\n\t "));
+ consume_while(is_any_of("\n\t "sv));
{
RefPtr<AST::Node> syntax_error;
@@ -454,7 +454,7 @@ RefPtr<AST::Node> Parser::parse_or_logical_sequence()
consume_while(is_whitespace);
auto pos_before_or = save_offset();
- if (!expect("||"))
+ if (!expect("||"sv))
return and_sequence;
auto pos_after_or = save_offset();
@@ -478,7 +478,7 @@ RefPtr<AST::Node> Parser::parse_and_logical_sequence()
consume_while(is_whitespace);
auto pos_before_and = save_offset();
- if (!expect("&&"))
+ if (!expect("&&"sv))
return pipe_sequence;
auto pos_after_end = save_offset();
@@ -578,10 +578,10 @@ RefPtr<AST::Node> Parser::parse_continuation_control()
auto rule_start = push_start();
- if (expect("break")) {
+ if (expect("break"sv)) {
{
auto break_end = push_start();
- if (consume_while(is_any_of(" \t\n;")).is_empty()) {
+ if (consume_while(is_any_of(" \t\n;"sv)).is_empty()) {
restore_to(*rule_start);
return nullptr;
}
@@ -590,10 +590,10 @@ RefPtr<AST::Node> Parser::parse_continuation_control()
return create<AST::ContinuationControl>(AST::ContinuationControl::Break);
}
- if (expect("continue")) {
+ if (expect("continue"sv)) {
{
auto continue_end = push_start();
- if (consume_while(is_any_of(" \t\n;")).is_empty()) {
+ if (consume_while(is_any_of(" \t\n;"sv)).is_empty()) {
restore_to(*rule_start);
return nullptr;
}
@@ -608,10 +608,10 @@ RefPtr<AST::Node> Parser::parse_continuation_control()
RefPtr<AST::Node> Parser::parse_for_loop()
{
auto rule_start = push_start();
- if (!expect("for"))
+ if (!expect("for"sv))
return nullptr;
- if (consume_while(is_any_of(" \t\n")).is_empty()) {
+ if (consume_while(is_any_of(" \t\n"sv)).is_empty()) {
restore_to(*rule_start);
return nullptr;
}
@@ -620,7 +620,7 @@ RefPtr<AST::Node> Parser::parse_for_loop()
Optional<AST::Position> in_start_position, index_start_position;
auto offset_before_index = current_position();
- if (expect("index")) {
+ if (expect("index"sv)) {
auto offset = current_position();
if (!consume_while(is_whitespace).is_empty()) {
auto offset_before_variable = current_position();
@@ -653,7 +653,7 @@ RefPtr<AST::Node> Parser::parse_for_loop()
};
consume_while(is_whitespace);
auto in_error_start = push_start();
- if (!expect("in")) {
+ if (!expect("in"sv)) {
auto syntax_error = create<AST::SyntaxError>("Expected 'in' after a variable name in a 'for' loop", true);
return create<AST::ForLoop>(move(variable_name), move(index_variable_name), move(syntax_error), nullptr); // ForLoop Var Iterated Block
}
@@ -669,7 +669,7 @@ RefPtr<AST::Node> Parser::parse_for_loop()
iterated_expression = create<AST::SyntaxError>("Expected an expression in 'for' loop", true);
}
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
{
auto obrace_error_start = push_start();
if (!expect('{')) {
@@ -699,10 +699,10 @@ RefPtr<AST::Node> Parser::parse_for_loop()
RefPtr<AST::Node> Parser::parse_loop_loop()
{
auto rule_start = push_start();
- if (!expect("loop"))
+ if (!expect("loop"sv))
return nullptr;
- if (consume_while(is_any_of(" \t\n")).is_empty()) {
+ if (consume_while(is_any_of(" \t\n"sv)).is_empty()) {
restore_to(*rule_start);
return nullptr;
}
@@ -736,10 +736,10 @@ RefPtr<AST::Node> Parser::parse_loop_loop()
RefPtr<AST::Node> Parser::parse_if_expr()
{
auto rule_start = push_start();
- if (!expect("if"))
+ if (!expect("if"sv))
return nullptr;
- if (consume_while(is_any_of(" \t\n")).is_empty()) {
+ if (consume_while(is_any_of(" \t\n"sv)).is_empty()) {
restore_to(*rule_start);
return nullptr;
}
@@ -779,23 +779,23 @@ RefPtr<AST::Node> Parser::parse_if_expr()
return body;
};
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
auto true_branch = parse_braced_toplevel();
auto end_before_else = m_offset;
auto line_before_else = line();
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
Optional<AST::Position> else_position;
{
auto else_start = push_start();
- if (expect("else"))
+ if (expect("else"sv))
else_position = AST::Position { else_start->offset, m_offset, else_start->line, line() };
else
restore_to(end_before_else, line_before_else);
}
if (else_position.has_value()) {
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
if (peek() == '{') {
auto false_branch = parse_braced_toplevel();
return create<AST::IfCond>(else_position, condition.release_nonnull(), move(true_branch), move(false_branch)); // If expr true_branch Else false_branch
@@ -834,7 +834,7 @@ RefPtr<AST::Node> Parser::parse_subshell()
RefPtr<AST::Node> Parser::parse_match_expr()
{
auto rule_start = push_start();
- if (!expect("match"))
+ if (!expect("match"sv))
return nullptr;
if (consume_while(is_whitespace).is_empty()) {
@@ -849,16 +849,16 @@ RefPtr<AST::Node> Parser::parse_match_expr()
String {}, Optional<AST::Position> {}, Vector<AST::MatchEntry> {});
}
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
String match_name;
Optional<AST::Position> as_position;
auto as_start = m_offset;
auto as_line = line();
- if (expect("as")) {
+ if (expect("as"sv)) {
as_position = AST::Position { as_start, m_offset, as_line, line() };
- if (consume_while(is_any_of(" \t\n")).is_empty()) {
+ if (consume_while(is_any_of(" \t\n"sv)).is_empty()) {
auto node = create<AST::MatchExpr>(
match_expression.release_nonnull(),
String {}, move(as_position), Vector<AST::MatchEntry> {});
@@ -876,7 +876,7 @@ RefPtr<AST::Node> Parser::parse_match_expr()
}
}
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
if (!expect('{')) {
auto node = create<AST::MatchExpr>(
@@ -886,19 +886,19 @@ RefPtr<AST::Node> Parser::parse_match_expr()
return node;
}
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
Vector<AST::MatchEntry> entries;
for (;;) {
auto entry = parse_match_entry();
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
if (entry.options.visit([](auto& x) { return x.is_empty(); }))
break;
entries.append(move(entry));
}
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
if (!expect('}')) {
auto node = create<AST::MatchExpr>(
@@ -925,7 +925,7 @@ AST::MatchEntry Parser::parse_match_entry()
Glob,
} pattern_kind;
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
auto regex_pattern = parse_regex_pattern();
if (regex_pattern.has_value()) {
@@ -943,14 +943,14 @@ AST::MatchEntry Parser::parse_match_entry()
patterns.append(glob_pattern.release_nonnull());
}
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
auto previous_pipe_start_position = m_offset;
auto previous_pipe_start_line = line();
RefPtr<AST::SyntaxError> error;
while (expect('|')) {
pipe_positions.append({ previous_pipe_start_position, m_offset, previous_pipe_start_line, line() });
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
switch (pattern_kind) {
case Regex: {
auto pattern = parse_regex_pattern();
@@ -972,19 +972,19 @@ AST::MatchEntry Parser::parse_match_entry()
}
}
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
previous_pipe_start_line = line();
previous_pipe_start_position = m_offset;
}
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
auto as_start_position = m_offset;
auto as_start_line = line();
- if (pattern_kind == Glob && expect("as")) {
+ if (pattern_kind == Glob && expect("as"sv)) {
match_as_position = AST::Position { as_start_position, m_offset, as_start_line, line() };
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
if (!expect('(')) {
if (!error)
error = create<AST::SyntaxError>("Expected an explicit list of identifiers after a pattern 'as'");
@@ -1003,7 +1003,7 @@ AST::MatchEntry Parser::parse_match_entry()
error = create<AST::SyntaxError>("Expected a close paren ')' to end the identifier list of pattern 'as'", true);
}
}
- consume_while(is_any_of(" \t\n"));
+ consume_while(is_any_of(" \t\n"sv));
}
if (pattern_kind == Regex) {
@@ -1064,7 +1064,7 @@ Optional<Regex<ECMA262>> Parser::parse_regex_pattern()
auto rule_start = push_start();
auto start = m_offset;
- if (!expect("(?:") && !expect("(?<"))
+ if (!expect("(?:"sv) && !expect("(?<"sv))
return {};
size_t open_parens = 1;
@@ -1072,9 +1072,9 @@ Optional<Regex<ECMA262>> Parser::parse_regex_pattern()
if (at_end())
break;
- if (next_is("("))
+ if (next_is("("sv))
++open_parens;
- else if (next_is(")"))
+ else if (next_is(")"sv))
--open_parens;
consume();
}
@@ -1094,7 +1094,7 @@ RefPtr<AST::Node> Parser::parse_redirection()
auto rule_start = push_start();
// heredoc entry
- if (next_is("<<-") || next_is("<<~"))
+ if (next_is("<<-"sv) || next_is("<<~"sv))
return nullptr;
auto pipe_fd = 0;
@@ -1229,7 +1229,7 @@ RefPtr<AST::Node> Parser::parse_expression()
};
// Heredocs are expressions, so allow them
- if (!(next_is("<<-") || next_is("<<~"))) {
+ if (!(next_is("<<-"sv) || next_is("<<~"sv))) {
if (strchr("&|)} ;<>\n", starting_char) != nullptr)
return nullptr;
}
@@ -1237,7 +1237,7 @@ RefPtr<AST::Node> Parser::parse_expression()
if (m_extra_chars_not_allowed_in_barewords.contains_slow(starting_char))
return nullptr;
- if (m_is_in_brace_expansion_spec && next_is(".."))
+ if (m_is_in_brace_expansion_spec && next_is(".."sv))
return nullptr;
if (isdigit(starting_char)) {
@@ -1524,7 +1524,7 @@ RefPtr<AST::Node> Parser::parse_variable_ref()
RefPtr<AST::Slice> Parser::parse_slice()
{
auto rule_start = push_start();
- if (!next_is("["))
+ if (!next_is("["sv))
return nullptr;
consume(); // [
@@ -1865,7 +1865,7 @@ RefPtr<AST::Node> Parser::parse_bareword()
continue;
}
- if (m_is_in_brace_expansion_spec && next_is("..")) {
+ if (m_is_in_brace_expansion_spec && next_is(".."sv)) {
// Don't eat '..' in a brace expansion spec.
break;
}
@@ -1922,7 +1922,7 @@ RefPtr<AST::Node> Parser::parse_bareword()
return create<AST::Juxtaposition>(tilde.release_nonnull(), text.release_nonnull()); // Juxtaposition Variable Bareword
}
- if (string.starts_with("\\~")) {
+ if (string.starts_with("\\~"sv)) {
// Un-escape the tilde, but only at the start (where it would be an expansion)
string = string.substring(1, string.length() - 1);
}
@@ -2010,13 +2010,13 @@ RefPtr<AST::Node> Parser::parse_brace_expansion_spec()
auto rule_start = push_start();
NonnullRefPtrVector<AST::Node> subexpressions;
- if (next_is(",")) {
+ if (next_is(","sv)) {
// Note that we don't consume the ',' here.
subexpressions.append(create<AST::StringLiteral>("", AST::StringLiteral::EnclosureType::None));
} else {
auto start_expr = parse_expression();
if (start_expr) {
- if (expect("..")) {
+ if (expect(".."sv)) {
if (auto end_expr = parse_expression()) {
if (end_expr->position().start_offset != start_expr->position().end_offset + 2)
end_expr->set_is_syntax_error(create<AST::SyntaxError>("Expected no whitespace between '..' and the following expression in brace expansion"));
@@ -2049,7 +2049,7 @@ RefPtr<AST::Node> Parser::parse_brace_expansion_spec()
RefPtr<AST::Node> Parser::parse_heredoc_initiation_record()
{
- if (!next_is("<<"))
+ if (!next_is("<<"sv))
return nullptr;
auto rule_start = push_start();
diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp
index 9f23e0cc93..bb13209a1e 100644
--- a/Userland/Shell/Shell.cpp
+++ b/Userland/Shell/Shell.cpp
@@ -98,7 +98,7 @@ String Shell::prompt() const
break;
switch (*ptr) {
case 'X':
- builder.append("\033]0;");
+ builder.append("\033]0;"sv);
break;
case 'a':
builder.append(0x07);
@@ -208,7 +208,7 @@ Vector<String> Shell::expand_globs(StringView path, StringView base)
{
auto explicitly_set_base = false;
if (path.starts_with('/')) {
- base = "/";
+ base = "/"sv;
explicitly_set_base = true;
}
auto parts = split_path(path);
@@ -367,7 +367,7 @@ RefPtr<AST::Value> Shell::get_argument(size_t index) const
return adopt_ref(*new AST::StringValue(current_script));
--index;
- if (auto argv = lookup_local_variable("ARGV")) {
+ if (auto argv = lookup_local_variable("ARGV"sv)) {
if (argv->is_list_without_resolution()) {
AST::ListValue* list = static_cast<AST::ListValue*>(argv.ptr());
if (list->values().size() <= index)
@@ -887,7 +887,7 @@ void Shell::execute_process(Vector<char const*>&& argv)
int rc = execvp(argv[0], const_cast<char* const*>(argv.data()));
if (rc < 0) {
- auto parts = StringView { argv[0] }.split_view('/');
+ auto parts = StringView { argv[0], strlen(argv[0]) }.split_view('/');
if (parts.size() == 1) {
// If this is a path in the current directory and it caused execvp() to fail,
// simply don't attempt to execute it, see #6774.
@@ -913,10 +913,10 @@ void Shell::execute_process(Vector<char const*>&& argv)
break;
auto& file = file_result.value();
auto line = file->read_line();
- if (!line.starts_with("#!"))
+ if (!line.starts_with("#!"sv))
break;
GenericLexer shebang_lexer { line.substring_view(2) };
- auto shebang = shebang_lexer.consume_until(is_any_of("\n\r")).to_string();
+ auto shebang = shebang_lexer.consume_until(is_any_of("\n\r"sv)).to_string();
argv.prepend(shebang.characters());
int rc = execvp(argv[0], const_cast<char* const*>(argv.data()));
if (rc < 0) {
@@ -1139,27 +1139,27 @@ String Shell::escape_token_for_single_quotes(StringView token)
// `foo bar \n '` -> `'foo bar \n '"'"`
StringBuilder builder;
- builder.append("'");
+ builder.append("'"sv);
auto started_single_quote = true;
for (auto c : token) {
switch (c) {
case '\'':
- builder.append("\"'\"");
+ builder.append("\"'\""sv);
started_single_quote = false;
continue;
default:
builder.append(c);
if (!started_single_quote) {
started_single_quote = true;
- builder.append("'");
+ builder.append("'"sv);
}
break;
}
}
if (started_single_quote)
- builder.append("'");
+ builder.append("'"sv);
return builder.build();
}
@@ -1174,10 +1174,10 @@ String Shell::escape_token_for_double_quotes(StringView token)
for (auto c : token) {
switch (c) {
case '\"':
- builder.append("\\\"");
+ builder.append("\\\""sv);
continue;
case '\\':
- builder.append("\\\\");
+ builder.append("\\\\"sv);
continue;
default:
builder.append(c);
@@ -1244,40 +1244,40 @@ static String do_escape(Shell::EscapeMode escape_mode, auto& token)
break;
case Shell::SpecialCharacterEscapeMode::Escaped:
if (escape_mode == Shell::EscapeMode::SingleQuotedString)
- builder.append("'");
+ builder.append("'"sv);
builder.append('\\');
builder.append(c);
if (escape_mode == Shell::EscapeMode::SingleQuotedString)
- builder.append("'");
+ builder.append("'"sv);
break;
case Shell::SpecialCharacterEscapeMode::QuotedAsEscape:
if (escape_mode == Shell::EscapeMode::SingleQuotedString)
- builder.append("'");
+ builder.append("'"sv);
if (escape_mode != Shell::EscapeMode::DoubleQuotedString)
- builder.append("\"");
+ builder.append("\""sv);
switch (c) {
case '\n':
- builder.append(R"(\n)");
+ builder.append(R"(\n)"sv);
break;
case '\t':
- builder.append(R"(\t)");
+ builder.append(R"(\t)"sv);
break;
case '\r':
- builder.append(R"(\r)");
+ builder.append(R"(\r)"sv);
break;
default:
VERIFY_NOT_REACHED();
}
if (escape_mode != Shell::EscapeMode::DoubleQuotedString)
- builder.append("\"");
+ builder.append("\""sv);
if (escape_mode == Shell::EscapeMode::SingleQuotedString)
- builder.append("'");
+ builder.append("'"sv);
break;
case Shell::SpecialCharacterEscapeMode::QuotedAsHex:
if (escape_mode == Shell::EscapeMode::SingleQuotedString)
- builder.append("'");
+ builder.append("'"sv);
if (escape_mode != Shell::EscapeMode::DoubleQuotedString)
- builder.append("\"");
+ builder.append("\""sv);
if (c <= NumericLimits<u8>::max())
builder.appendff(R"(\x{:0>2x})", static_cast<u8>(c));
@@ -1285,9 +1285,9 @@ static String do_escape(Shell::EscapeMode escape_mode, auto& token)
builder.appendff(R"(\u{:0>8x})", static_cast<u32>(c));
if (escape_mode != Shell::EscapeMode::DoubleQuotedString)
- builder.append("\"");
+ builder.append("\""sv);
if (escape_mode == Shell::EscapeMode::SingleQuotedString)
- builder.append("'");
+ builder.append("'"sv);
break;
}
}
@@ -1460,7 +1460,7 @@ Vector<Line::CompletionSuggestion> Shell::complete(StringView line)
Vector<Line::CompletionSuggestion> Shell::complete_path(StringView base, StringView part, size_t offset, ExecutableOnly executable_only, AST::Node const* command_node, AST::Node const* node, EscapeMode escape_mode)
{
- auto token = offset ? part.substring_view(0, offset) : "";
+ auto token = offset ? part.substring_view(0, offset) : ""sv;
String path;
ssize_t last_slash = token.length() - 1;
@@ -1526,11 +1526,11 @@ Vector<Line::CompletionSuggestion> Shell::complete_path(StringView base, StringV
int stat_error = stat(file_path.characters(), &program_status);
if (!stat_error && (executable_only == ExecutableOnly::No || access(file_path.characters(), X_OK) == 0)) {
if (S_ISDIR(program_status.st_mode)) {
- suggestions.append({ escape_token(file, escape_mode), "/" });
+ suggestions.append({ escape_token(file, escape_mode), "/"sv });
} else {
- if (!allow_direct_children && !file.contains("/"))
+ if (!allow_direct_children && !file.contains('/'))
continue;
- suggestions.append({ escape_token(file, escape_mode), " " });
+ suggestions.append({ escape_token(file, escape_mode), " "sv });
}
suggestions.last().input_offset = token_length;
suggestions.last().invariant_offset = invariant_offset;
@@ -1556,7 +1556,7 @@ Vector<Line::CompletionSuggestion> Shell::complete_program_name(StringView name,
});
if (!match)
- return complete_path("", name, offset, ExecutableOnly::Yes, nullptr, nullptr, escape_mode);
+ return complete_path(""sv, name, offset, ExecutableOnly::Yes, nullptr, nullptr, escape_mode);
String completion = match->path;
auto token_length = escape_token(name, escape_mode).length();
@@ -1573,10 +1573,10 @@ Vector<Line::CompletionSuggestion> Shell::complete_program_name(StringView name,
int index = match - cached_path.data();
for (int i = index - 1; i >= 0 && cached_path[i].path.starts_with(name); --i)
- suggestions.append({ cached_path[i].path, " " });
+ suggestions.append({ cached_path[i].path, " "sv });
for (size_t i = index + 1; i < cached_path.size() && cached_path[i].path.starts_with(name); ++i)
- suggestions.append({ cached_path[i].path, " " });
- suggestions.append({ cached_path[index].path, " " });
+ suggestions.append({ cached_path[i].path, " "sv });
+ suggestions.append({ cached_path[index].path, " "sv });
for (auto& entry : suggestions) {
entry.input_offset = token_length;
@@ -1590,7 +1590,7 @@ Vector<Line::CompletionSuggestion> Shell::complete_program_name(StringView name,
Vector<Line::CompletionSuggestion> Shell::complete_variable(StringView name, size_t offset)
{
Vector<Line::CompletionSuggestion> suggestions;
- auto pattern = offset ? name.substring_view(0, offset) : "";
+ auto pattern = offset ? name.substring_view(0, offset) : ""sv;
auto invariant_offset = offset;
size_t static_offset = 0;
@@ -1631,7 +1631,7 @@ Vector<Line::CompletionSuggestion> Shell::complete_variable(StringView name, siz
Vector<Line::CompletionSuggestion> Shell::complete_user(StringView name, size_t offset)
{
Vector<Line::CompletionSuggestion> suggestions;
- auto pattern = offset ? name.substring_view(0, offset) : "";
+ auto pattern = offset ? name.substring_view(0, offset) : ""sv;
auto invariant_offset = offset;
size_t static_offset = 0;
@@ -1668,7 +1668,7 @@ Vector<Line::CompletionSuggestion> Shell::complete_option(StringView program_nam
size_t start = 0;
while (start < option.length() && option[start] == '-' && start < 2)
++start;
- auto option_pattern = offset > start ? option.substring_view(start, offset - start) : "";
+ auto option_pattern = offset > start ? option.substring_view(start, offset - start) : ""sv;
auto invariant_offset = offset;
size_t static_offset = 0;
if (m_editor)
@@ -1762,7 +1762,7 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
AST::NodeVisitor::visit(node);
auto list = pop_list();
StringBuilder builder;
- builder.join("", list);
+ builder.join(""sv, list);
this->list().append(builder.build());
}
@@ -1781,7 +1781,7 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
AST::NodeVisitor::visit(node);
auto list = pop_list();
StringBuilder builder;
- builder.join("", list);
+ builder.join(""sv, list);
this->list().append(builder.build());
}
@@ -1898,32 +1898,32 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
auto parsed = parsed_result.release_value();
if (parsed.is_object()) {
auto& object = parsed.as_object();
- auto kind = object.get("kind").as_string_or("plain");
+ auto kind = object.get("kind"sv).as_string_or("plain");
if (kind == "path") {
- auto base = object.get("base").as_string_or("");
- auto part = object.get("part").as_string_or("");
- auto executable_only = object.get("executable_only").to_bool(false) ? ExecutableOnly::Yes : ExecutableOnly::No;
+ auto base = object.get("base"sv).as_string_or("");
+ auto part = object.get("part"sv).as_string_or("");
+ auto executable_only = object.get("executable_only"sv).to_bool(false) ? ExecutableOnly::Yes : ExecutableOnly::No;
suggestions.extend(complete_path(base, part, part.length(), executable_only, nullptr, nullptr));
} else if (kind == "program") {
- auto name = object.get("name").as_string_or("");
+ auto name = object.get("name"sv).as_string_or("");
suggestions.extend(complete_program_name(name, name.length()));
} else if (kind == "proxy") {
if (m_completion_stack_info.size_free() < 4 * KiB) {
dbgln("Not enough stack space, recursion?");
return IterationDecision::Continue;
}
- auto argv = object.get("argv").as_string_or("");
+ auto argv = object.get("argv"sv).as_string_or("");
dbgln("Proxy completion for {}", argv);
suggestions.extend(complete(argv));
} else if (kind == "plain") {
Line::CompletionSuggestion suggestion {
- object.get("completion").as_string_or(""),
- object.get("trailing_trivia").as_string_or(""),
- object.get("display_trivia").as_string_or(""),
+ object.get("completion"sv).as_string_or(""),
+ object.get("trailing_trivia"sv).as_string_or(""),
+ object.get("display_trivia"sv).as_string_or(""),
};
- suggestion.static_offset = object.get("static_offset").to_u64(0);
- suggestion.invariant_offset = object.get("invariant_offset").to_u64(0);
- suggestion.allow_commit_without_listing = object.get("allow_commit_without_listing").to_bool(true);
+ suggestion.static_offset = object.get("static_offset"sv).to_u64(0);
+ suggestion.invariant_offset = object.get("invariant_offset"sv).to_u64(0);
+ suggestion.allow_commit_without_listing = object.get("allow_commit_without_listing"sv).to_bool(true);
suggestions.append(move(suggestion));
} else {
dbgln("LibLine: Unhandled completion kind: {}", kind);
@@ -1957,7 +1957,7 @@ Vector<Line::CompletionSuggestion> Shell::complete_immediate_function_name(Strin
#define __ENUMERATE_SHELL_IMMEDIATE_FUNCTION(fn_name) \
if (auto name_view = #fn_name##sv; name_view.starts_with(name)) \
- suggestions.append({ name_view, " " });
+ suggestions.append({ name_view, " "sv });
ENUMERATE_SHELL_IMMEDIATE_FUNCTIONS();
@@ -2040,7 +2040,7 @@ bool Shell::read_single_line()
if (is_eof || is_empty) {
// Pretend the user tried to execute builtin_exit()
- auto exit_code = run_command("exit");
+ auto exit_code = run_command("exit"sv);
if (exit_code != 0) {
// If we didn't end up actually calling exit(), and the command didn't succeed, just pretend it's all okay
// unless we can't, then just quit anyway.
@@ -2188,8 +2188,8 @@ Shell::Shell()
if (path_env_ptr != NULL)
path.append({ path_env_ptr, strlen(path_env_ptr) });
if (path.length())
- path.append(":");
- path.append("/usr/local/sbin:/usr/local/bin:/usr/bin:/bin");
+ path.append(":"sv);
+ path.append("/usr/local/sbin:/usr/local/bin:/usr/bin:/bin"sv);
setenv("PATH", path.to_string().characters(), true);
}