AK: Guard some APIs that use Vector::append() behind #ifndef KERNEL

Vector::append() will be disallowed in the kernel by the next commit.
This commit is contained in:
Sönke Holz authored and Sönke Holz committed 2025-11-17 11:08:45 +01:00
1 parent afa10af8f7
commit 84e02b71fa
4 files changed
+28 -1

No files matched your search

+4
View File
@@ -29,6 +29,7 @@ namespace AK {
namespace StringUtils {
#ifndef KERNEL
bool matches(StringView str, StringView mask, CaseSensitivity case_sensitivity, Vector<MaskSpan>* match_spans)
{
auto record_span = [&match_spans](size_t start, size_t length) {
@@ -93,6 +94,7 @@ bool matches(StringView str, StringView mask, CaseSensitivity case_sensitivity,
return string_ptr == string_end && mask_ptr == mask_end;
}
#endif
template<typename T>
Optional<T> convert_to_int(StringView str, TrimWhitespace trim_whitespace)
@@ -431,6 +433,7 @@ Optional<size_t> find_last_not(StringView haystack, char needle)
return {};
}
#ifndef KERNEL
Vector<size_t> find_all(StringView haystack, StringView needle)
{
Vector<size_t> positions;
@@ -446,6 +449,7 @@ Vector<size_t> find_all(StringView haystack, StringView needle)
}
return positions;
}
#endif
Optional<size_t> find_any_of(StringView haystack, StringView needles, SearchDirection direction)
{
+7
View File
@@ -73,7 +73,10 @@ struct MaskSpan {
namespace StringUtils {
#ifndef KERNEL
bool matches(StringView str, StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive, Vector<MaskSpan>* match_spans = nullptr);
#endif
template<typename T = int>
Optional<T> convert_to_int(StringView, TrimWhitespace = TrimWhitespace::Yes);
template<typename T = unsigned>
@@ -99,7 +102,11 @@ Optional<size_t> find(StringView haystack, StringView needle, size_t start = 0);
Optional<size_t> find_last(StringView haystack, char needle);
Optional<size_t> find_last(StringView haystack, StringView needle);
Optional<size_t> find_last_not(StringView haystack, char needle);
#ifndef KERNEL
Vector<size_t> find_all(StringView haystack, StringView needle);
#endif
enum class SearchDirection {
Forward,
Backward
+5 -1
View File
@@ -110,6 +110,7 @@ static void for_each_line(StringView string, Callback&& callback)
callback(string.substring_view(substart, taillen));
}
#ifndef KERNEL
Vector<StringView> StringView::lines(ConsiderCarriageReturn consider_carriage_return) const
{
if (is_empty())
@@ -123,6 +124,7 @@ Vector<StringView> StringView::lines(ConsiderCarriageReturn consider_carriage_re
return lines;
}
#endif
size_t StringView::count_lines(ConsiderCarriageReturn consider_carriage_return) const
{
@@ -162,6 +164,7 @@ bool StringView::ends_with(StringView str, CaseSensitivity case_sensitivity) con
return StringUtils::ends_with(*this, str, case_sensitivity);
}
#ifndef KERNEL
bool StringView::matches(StringView mask, Vector<MaskSpan>& mask_spans, CaseSensitivity case_sensitivity) const
{
return StringUtils::matches(*this, mask, case_sensitivity, &mask_spans);
@@ -171,6 +174,7 @@ bool StringView::matches(StringView mask, CaseSensitivity case_sensitivity) cons
{
return StringUtils::matches(*this, mask, case_sensitivity);
}
#endif
bool StringView::contains(char needle) const
{
@@ -267,7 +271,6 @@ ByteString StringView::replace(StringView needle, StringView replacement, Replac
{
return StringUtils::replace(*this, needle, replacement, replace_mode);
}
#endif
Vector<size_t> StringView::find_all(StringView needle) const
{
@@ -297,5 +300,6 @@ Vector<StringView> StringView::split_view_if(Function<bool(char)> const& predica
v.append(substring_view(substart, taillen));
return v;
}
#endif
}
+12
View File
@@ -100,8 +100,12 @@ public:
[[nodiscard]] bool ends_with(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
[[nodiscard]] bool starts_with(char) const;
[[nodiscard]] bool ends_with(char) const;
#ifndef KERNEL
[[nodiscard]] bool matches(StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
[[nodiscard]] bool matches(StringView mask, Vector<MaskSpan>&, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
#endif
[[nodiscard]] bool contains(char) const;
[[nodiscard]] bool contains(u32) const;
[[nodiscard]] bool contains(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
@@ -125,7 +129,9 @@ public:
[[nodiscard]] Optional<size_t> find_last(StringView needle) const { return StringUtils::find_last(*this, needle); }
[[nodiscard]] Optional<size_t> find_last_not(char needle) const { return StringUtils::find_last_not(*this, needle); }
#ifndef KERNEL
[[nodiscard]] Vector<size_t> find_all(StringView needle) const;
#endif
using SearchDirection = StringUtils::SearchDirection;
[[nodiscard]] Optional<size_t> find_any_of(StringView needles, SearchDirection direction = SearchDirection::Forward) const { return StringUtils::find_any_of(*this, needles, direction); }
@@ -147,7 +153,9 @@ public:
[[nodiscard]] Vector<StringView> split_view(char, SplitBehavior = SplitBehavior::Nothing) const;
[[nodiscard]] Vector<StringView> split_view(StringView, SplitBehavior = SplitBehavior::Nothing) const;
#ifndef KERNEL
[[nodiscard]] Vector<StringView> split_view_if(Function<bool(char)> const& predicate, SplitBehavior = SplitBehavior::Nothing) const;
#endif
[[nodiscard]] StringView find_last_split_view(char separator) const
{
@@ -239,7 +247,11 @@ public:
No,
Yes,
};
#ifndef KERNEL
[[nodiscard]] Vector<StringView> lines(ConsiderCarriageReturn = ConsiderCarriageReturn::Yes) const;
#endif
[[nodiscard]] size_t count_lines(ConsiderCarriageReturn = ConsiderCarriageReturn::Yes) const;
// Create a new substring view of this string view, starting either at the beginning of