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

AK: Implement String::find_any_of() and StringView::find_any_of()

This implements StringUtils::find_any_of() and uses it in
String::find_any_of() and StringView::find_any_of(). All uses of
find_{first,last}_of have been replaced with find_any_of(), find() or
find_last(). find_{first,last}_of have subsequently been removed.
This commit is contained in:
Max Wipfli 2021-07-01 18:12:21 +02:00 committed by Andreas Kling
parent 17eddf3ac4
commit 9cc35d1ba3
12 changed files with 44 additions and 52 deletions

View file

@ -60,9 +60,10 @@ struct [[gnu::packed]] MemoryRegionInfo {
StringView memory_region_name { region_name };
if (memory_region_name.contains("Loader.so"))
return "Loader.so";
if (!memory_region_name.contains(":"))
auto maybe_colon_index = memory_region_name.find(':');
if (!maybe_colon_index.has_value())
return {};
return memory_region_name.substring_view(0, memory_region_name.find_first_of(":").value()).to_string();
return memory_region_name.substring_view(0, *maybe_colon_index).to_string();
}
};

View file

@ -73,7 +73,7 @@ Link::Link(String text, const Document& document)
while (index < m_text.length() && (m_text[index] == ' ' || m_text[index] == '\t'))
++index;
auto url_string = m_text.substring_view(index, m_text.length() - index);
auto space_offset = url_string.find_first_of(" \t");
auto space_offset = url_string.find_any_of(" \t");
String url = url_string;
if (space_offset.has_value()) {
url = url_string.substring_view(0, space_offset.value());

View file

@ -252,7 +252,7 @@ bool Editor::load_history(const String& path)
auto data = history_file->read_all();
auto hist = StringView { data.data(), data.size() };
for (auto& str : hist.split_view("\n\n")) {
auto it = str.find_first_of("::").value_or(0);
auto it = str.find("::").value_or(0);
auto time = str.substring_view(0, it).to_uint<time_t>().value_or(0);
auto string = str.substring_view(it == 0 ? it : it + 2);
m_history.append({ string, time });

View file

@ -222,7 +222,7 @@ static StringView parse_custom_property_name(const StringView& value)
if (!value.starts_with("var(") || !value.ends_with(")"))
return {};
// FIXME: Allow for fallback
auto first_comma_index = value.find_first_of(",");
auto first_comma_index = value.find(',');
auto length = value.length();
auto substring_length = first_comma_index.has_value() ? first_comma_index.value() - 4 - 1 : length - 4 - 1;