diff options
author | Andreas Kling <kling@serenityos.org> | 2021-05-24 11:50:46 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-24 11:59:18 +0200 |
commit | de395a3df236eb653db78b5b88a0178036f99ba0 (patch) | |
tree | 2a6bd2f6126aa62650fc92092eaa4d88ebebc19e /Userland/Shell | |
parent | 875a2cbb7150b036af343364a8bf2d07a97dd03d (diff) | |
download | serenity-de395a3df236eb653db78b5b88a0178036f99ba0.zip |
AK+Everywhere: Consolidate String::index_of() and String::find()
We had two functions for doing mostly the same thing. Combine both
of them into String::find() and use that everywhere.
Also add some tests to cover basic behavior.
Diffstat (limited to 'Userland/Shell')
-rw-r--r-- | Userland/Shell/AST.cpp | 2 | ||||
-rw-r--r-- | Userland/Shell/Parser.cpp | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/Userland/Shell/AST.cpp b/Userland/Shell/AST.cpp index 0863b72fb4..8bdc8f69d1 100644 --- a/Userland/Shell/AST.cpp +++ b/Userland/Shell/AST.cpp @@ -611,7 +611,7 @@ void BarewordLiteral::highlight_in_editor(Line::Editor& editor, Shell& shell, Hi return; if (m_text.starts_with("--")) { - auto index = m_text.index_of("=").value_or(m_text.length() - 1) + 1; + 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 { editor.stylize({ m_position.start_offset, m_position.end_offset }, { Line::Style::Foreground(Line::Style::XtermColor::Cyan) }); diff --git a/Userland/Shell/Parser.cpp b/Userland/Shell/Parser.cpp index a7df601c90..f615547727 100644 --- a/Userland/Shell/Parser.cpp +++ b/Userland/Shell/Parser.cpp @@ -1772,7 +1772,7 @@ RefPtr<AST::Node> Parser::parse_bareword() String username; RefPtr<AST::Node> tilde, text; - auto first_slash_index = string.index_of("/"); + auto first_slash_index = string.find('/'); if (first_slash_index.has_value()) { username = string.substring_view(1, first_slash_index.value() - 1); string = string.substring_view(first_slash_index.value(), string.length() - first_slash_index.value()); |