1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:34:57 +00:00

AK+Everywhere: Remove StringView::find_{first,last}_of(char) methods

This removes StringView::find_first_of(char) and find_last_of(char) and
replaces all its usages with find and find_last respectively. This is
because those two methods are functionally equivalent.
find_{first,last}_of should only be used if searching for multiple
different characters, which is never the case with the char argument.

This also adds the [[nodiscard]] to the remaining find_{first,last}_of
methods.
This commit is contained in:
Max Wipfli 2021-07-01 15:01:29 +02:00 committed by Andreas Kling
parent 56253bf389
commit 3bdaed501e
10 changed files with 41 additions and 68 deletions

View file

@ -29,7 +29,7 @@ LexicalPath::LexicalPath(String path)
m_parts = m_string.split_view('/');
auto last_slash_index = m_string.view().find_last_of('/');
auto last_slash_index = m_string.view().find_last('/');
if (!last_slash_index.has_value()) {
// The path contains a single part and is not absolute. m_dirname = "."sv
m_dirname = { &s_single_dot, 1 };
@ -47,7 +47,7 @@ LexicalPath::LexicalPath(String path)
m_basename = m_parts.last();
}
auto last_dot_index = m_basename.find_last_of('.');
auto last_dot_index = m_basename.find_last('.');
// NOTE: if the dot index is 0, this means we have ".foo", it's not an extension, as the title would then be "".
if (last_dot_index.has_value() && *last_dot_index != 0) {
m_title = m_basename.substring_view(0, *last_dot_index);