Skip to content

Commit 84e02b7

Browse files
committed
AK: Guard some APIs that use Vector::append() behind #ifndef KERNEL
Vector::append() will be disallowed in the kernel by the next commit.
1 parent afa10af commit 84e02b7

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

AK/StringUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace AK {
2929

3030
namespace StringUtils {
3131

32+
#ifndef KERNEL
3233
bool matches(StringView str, StringView mask, CaseSensitivity case_sensitivity, Vector<MaskSpan>* match_spans)
3334
{
3435
auto record_span = [&match_spans](size_t start, size_t length) {
@@ -93,6 +94,7 @@ bool matches(StringView str, StringView mask, CaseSensitivity case_sensitivity,
9394

9495
return string_ptr == string_end && mask_ptr == mask_end;
9596
}
97+
#endif
9698

9799
template<typename T>
98100
Optional<T> convert_to_int(StringView str, TrimWhitespace trim_whitespace)
@@ -431,6 +433,7 @@ Optional<size_t> find_last_not(StringView haystack, char needle)
431433
return {};
432434
}
433435

436+
#ifndef KERNEL
434437
Vector<size_t> find_all(StringView haystack, StringView needle)
435438
{
436439
Vector<size_t> positions;
@@ -446,6 +449,7 @@ Vector<size_t> find_all(StringView haystack, StringView needle)
446449
}
447450
return positions;
448451
}
452+
#endif
449453

450454
Optional<size_t> find_any_of(StringView haystack, StringView needles, SearchDirection direction)
451455
{

AK/StringUtils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ struct MaskSpan {
7373

7474
namespace StringUtils {
7575

76+
#ifndef KERNEL
7677
bool matches(StringView str, StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive, Vector<MaskSpan>* match_spans = nullptr);
78+
#endif
79+
7780
template<typename T = int>
7881
Optional<T> convert_to_int(StringView, TrimWhitespace = TrimWhitespace::Yes);
7982
template<typename T = unsigned>
@@ -99,7 +102,11 @@ Optional<size_t> find(StringView haystack, StringView needle, size_t start = 0);
99102
Optional<size_t> find_last(StringView haystack, char needle);
100103
Optional<size_t> find_last(StringView haystack, StringView needle);
101104
Optional<size_t> find_last_not(StringView haystack, char needle);
105+
106+
#ifndef KERNEL
102107
Vector<size_t> find_all(StringView haystack, StringView needle);
108+
#endif
109+
103110
enum class SearchDirection {
104111
Forward,
105112
Backward

AK/StringView.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ static void for_each_line(StringView string, Callback&& callback)
110110
callback(string.substring_view(substart, taillen));
111111
}
112112

113+
#ifndef KERNEL
113114
Vector<StringView> StringView::lines(ConsiderCarriageReturn consider_carriage_return) const
114115
{
115116
if (is_empty())
@@ -123,6 +124,7 @@ Vector<StringView> StringView::lines(ConsiderCarriageReturn consider_carriage_re
123124

124125
return lines;
125126
}
127+
#endif
126128

127129
size_t StringView::count_lines(ConsiderCarriageReturn consider_carriage_return) const
128130
{
@@ -162,6 +164,7 @@ bool StringView::ends_with(StringView str, CaseSensitivity case_sensitivity) con
162164
return StringUtils::ends_with(*this, str, case_sensitivity);
163165
}
164166

167+
#ifndef KERNEL
165168
bool StringView::matches(StringView mask, Vector<MaskSpan>& mask_spans, CaseSensitivity case_sensitivity) const
166169
{
167170
return StringUtils::matches(*this, mask, case_sensitivity, &mask_spans);
@@ -171,6 +174,7 @@ bool StringView::matches(StringView mask, CaseSensitivity case_sensitivity) cons
171174
{
172175
return StringUtils::matches(*this, mask, case_sensitivity);
173176
}
177+
#endif
174178

175179
bool StringView::contains(char needle) const
176180
{
@@ -267,7 +271,6 @@ ByteString StringView::replace(StringView needle, StringView replacement, Replac
267271
{
268272
return StringUtils::replace(*this, needle, replacement, replace_mode);
269273
}
270-
#endif
271274

272275
Vector<size_t> StringView::find_all(StringView needle) const
273276
{
@@ -297,5 +300,6 @@ Vector<StringView> StringView::split_view_if(Function<bool(char)> const& predica
297300
v.append(substring_view(substart, taillen));
298301
return v;
299302
}
303+
#endif
300304

301305
}

AK/StringView.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ class StringView {
100100
[[nodiscard]] bool ends_with(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
101101
[[nodiscard]] bool starts_with(char) const;
102102
[[nodiscard]] bool ends_with(char) const;
103+
104+
#ifndef KERNEL
103105
[[nodiscard]] bool matches(StringView mask, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
104106
[[nodiscard]] bool matches(StringView mask, Vector<MaskSpan>&, CaseSensitivity = CaseSensitivity::CaseInsensitive) const;
107+
#endif
108+
105109
[[nodiscard]] bool contains(char) const;
106110
[[nodiscard]] bool contains(u32) const;
107111
[[nodiscard]] bool contains(StringView, CaseSensitivity = CaseSensitivity::CaseSensitive) const;
@@ -125,7 +129,9 @@ class StringView {
125129
[[nodiscard]] Optional<size_t> find_last(StringView needle) const { return StringUtils::find_last(*this, needle); }
126130
[[nodiscard]] Optional<size_t> find_last_not(char needle) const { return StringUtils::find_last_not(*this, needle); }
127131

132+
#ifndef KERNEL
128133
[[nodiscard]] Vector<size_t> find_all(StringView needle) const;
134+
#endif
129135

130136
using SearchDirection = StringUtils::SearchDirection;
131137
[[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 @@ class StringView {
147153
[[nodiscard]] Vector<StringView> split_view(char, SplitBehavior = SplitBehavior::Nothing) const;
148154
[[nodiscard]] Vector<StringView> split_view(StringView, SplitBehavior = SplitBehavior::Nothing) const;
149155

156+
#ifndef KERNEL
150157
[[nodiscard]] Vector<StringView> split_view_if(Function<bool(char)> const& predicate, SplitBehavior = SplitBehavior::Nothing) const;
158+
#endif
151159

152160
[[nodiscard]] StringView find_last_split_view(char separator) const
153161
{
@@ -239,7 +247,11 @@ class StringView {
239247
No,
240248
Yes,
241249
};
250+
251+
#ifndef KERNEL
242252
[[nodiscard]] Vector<StringView> lines(ConsiderCarriageReturn = ConsiderCarriageReturn::Yes) const;
253+
#endif
254+
243255
[[nodiscard]] size_t count_lines(ConsiderCarriageReturn = ConsiderCarriageReturn::Yes) const;
244256

245257
// Create a new substring view of this string view, starting either at the beginning of

0 commit comments

Comments
 (0)