AK+Everywhere: Stop including Vector.h from StringView.h

Preparation for using Error.h from Vector.h. This required moving some
things out of line.
This commit is contained in:
Andreas Kling 2021-11-10 11:05:21 +01:00
parent e52f987020
commit 5f7d008791
27 changed files with 88 additions and 51 deletions

View file

@ -11,6 +11,7 @@
#include <AK/Assertions.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <AK/Vector.h>
class [[gnu::packed]] MACAddress {
static constexpr size_t s_mac_address_length = 6u;

View file

@ -479,4 +479,9 @@ String String::vformatted(StringView fmtstr, TypeErasedFormatParams& params)
return builder.to_string();
}
Vector<size_t> String::find_all(StringView needle) const
{
return StringUtils::find_all(*this, needle);
}
}

View file

@ -149,7 +149,7 @@ public:
[[nodiscard]] Optional<size_t> find(StringView const& needle, size_t start = 0) const { return StringUtils::find(*this, needle, start); }
[[nodiscard]] Optional<size_t> find_last(char needle) const { return StringUtils::find_last(*this, needle); }
// FIXME: Implement find_last(StringView const&) for API symmetry.
[[nodiscard]] Vector<size_t> find_all(StringView const& needle) const { return StringUtils::find_all(*this, needle); }
Vector<size_t> find_all(StringView needle) const;
using SearchDirection = StringUtils::SearchDirection;
[[nodiscard]] Optional<size_t> find_any_of(StringView const& needles, SearchDirection direction) const { return StringUtils::find_any_of(*this, needles, direction); }

View file

@ -8,9 +8,11 @@
#include <AK/ByteBuffer.h>
#include <AK/Find.h>
#include <AK/FlyString.h>
#include <AK/Function.h>
#include <AK/Memory.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
namespace AK {
@ -252,4 +254,31 @@ String StringView::replace(const StringView& needle, const StringView& replaceme
return StringUtils::replace(*this, needle, replacement, all_occurrences);
}
Vector<size_t> StringView::find_all(StringView needle) const
{
return StringUtils::find_all(*this, needle);
}
Vector<StringView> StringView::split_view_if(Function<bool(char)> const& predicate, bool keep_empty) const
{
if (is_empty())
return {};
Vector<StringView> v;
size_t substart = 0;
for (size_t i = 0; i < length(); ++i) {
char ch = characters_without_null_termination()[i];
if (predicate(ch)) {
size_t sublen = i - substart;
if (sublen != 0 || keep_empty)
v.append(substring_view(substart, sublen));
substart = i + 1;
}
}
size_t taillen = length() - substart;
if (taillen != 0 || keep_empty)
v.append(substring_view(substart, taillen));
return v;
}
}

View file

@ -9,11 +9,11 @@
#include <AK/Assertions.h>
#include <AK/Checked.h>
#include <AK/Forward.h>
#include <AK/Optional.h>
#include <AK/Span.h>
#include <AK/StdLibExtras.h>
#include <AK/StringHash.h>
#include <AK/StringUtils.h>
#include <AK/Vector.h>
namespace AK {
@ -96,7 +96,7 @@ public:
[[nodiscard]] Optional<size_t> find_last(char needle) const { return StringUtils::find_last(*this, needle); }
// FIXME: Implement find_last(StringView const&) for API symmetry.
[[nodiscard]] Vector<size_t> find_all(StringView const& needle) const { return StringUtils::find_all(*this, needle); }
[[nodiscard]] Vector<size_t> find_all(StringView needle) const;
using SearchDirection = StringUtils::SearchDirection;
[[nodiscard]] Optional<size_t> find_any_of(StringView const& needles, SearchDirection direction = SearchDirection::Forward) { return StringUtils::find_any_of(*this, needles, direction); }
@ -116,28 +116,7 @@ public:
[[nodiscard]] Vector<StringView> split_view(char, bool keep_empty = false) const;
[[nodiscard]] Vector<StringView> split_view(const StringView&, bool keep_empty = false) const;
template<typename UnaryPredicate>
[[nodiscard]] Vector<StringView> split_view_if(UnaryPredicate&& predicate, bool keep_empty = false) const
{
if (is_empty())
return {};
Vector<StringView> v;
size_t substart = 0;
for (size_t i = 0; i < length(); ++i) {
char ch = characters_without_null_termination()[i];
if (predicate(ch)) {
size_t sublen = i - substart;
if (sublen != 0 || keep_empty)
v.append(substring_view(substart, sublen));
substart = i + 1;
}
}
size_t taillen = length() - substart;
if (taillen != 0 || keep_empty)
v.append(substring_view(substart, taillen));
return v;
}
[[nodiscard]] Vector<StringView> split_view_if(Function<bool(char)> const& predicate, bool keep_empty = false) const;
// Create a Vector of StringViews split by line endings. As of CommonMark
// 0.29, the spec defines a line ending as "a newline (U+000A), a carriage

View file

@ -9,6 +9,7 @@
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
namespace AK {

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/Types.h>
#include <AK/Vector.h>
#include <Kernel/Memory/Region.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/VirtualAddress.h>

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Vector.h>
#include <Kernel/KLexicalPath.h>
namespace Kernel::KLexicalPath {

View file

@ -8,6 +8,7 @@
#include <AK/AllOf.h>
#include <AK/Array.h>
#include <AK/Vector.h>
TEST_CASE(should_determine_if_predicate_applies_to_all_elements_in_container)
{

View file

@ -8,6 +8,7 @@
#include <AK/AnyOf.h>
#include <AK/Array.h>
#include <AK/Vector.h>
TEST_CASE(should_determine_if_predicate_applies_to_any_element_in_container)
{

View file

@ -8,6 +8,7 @@
#include <AK/BinarySearch.h>
#include <AK/Span.h>
#include <AK/Vector.h>
#include <cstring>
#include <new>

View file

@ -8,6 +8,7 @@
#include <AK/DisjointChunks.h>
#include <AK/String.h>
#include <AK/Vector.h>
TEST_CASE(basic)
{

View file

@ -8,6 +8,7 @@
#include <AK/StdLibExtras.h>
#include <AK/TypeList.h>
#include <AK/Vector.h>
template<typename F, typename... Args>
F for_each_argument(F f, Args&&... args)

View file

@ -9,6 +9,7 @@
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Vector.h>
TEST_CASE(basic_optional)
{

View file

@ -9,6 +9,7 @@
#include <AK/FlyString.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <cstring>
TEST_CASE(construct_empty)

View file

@ -7,6 +7,7 @@
#include <LibTest/TestCase.h>
#include <AK/StringUtils.h>
#include <AK/Vector.h>
TEST_CASE(matches_null)
{

View file

@ -7,6 +7,7 @@
#include <LibTest/TestCase.h>
#include <AK/String.h>
#include <AK/Vector.h>
TEST_CASE(construct_empty)
{
@ -157,7 +158,7 @@ TEST_CASE(split_view)
EXPECT_EQ(test_string_view.split_view("xx", true), Vector<StringView>({ "a", "bc", "d", "" }));
test_string_view = "ax_b_cxd";
auto predicate = [](char ch) { return ch == 'x' || ch == '_'; };
Function<bool(char)> predicate = [](char ch) { return ch == 'x' || ch == '_'; };
EXPECT_EQ(test_string_view.split_view_if(predicate), Vector<StringView>({ "a", "b", "c", "d" }));
EXPECT_EQ(test_string_view.split_view_if(predicate, true), Vector<StringView>({ "a", "", "b", "c", "d" }));
EXPECT_EQ(test_string_view.split_view_if(predicate), Vector<StringView>({ "a", "b", "c", "d" }));

View file

@ -7,6 +7,7 @@
#include <LibTest/TestCase.h>
#include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <LibC/regex.h>
#include <stdio.h>

View file

@ -7,6 +7,7 @@
#include "Format.h"
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Vector.h>
namespace Diff {
String generate_only_additions(const String& text)

View file

@ -12,6 +12,7 @@
#include <AK/RefPtr.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <AK/Vector.h>
#include <LibGfx/Font.h>
#include <LibGfx/Size.h>

View file

@ -311,6 +311,30 @@ Optional<Color> Color::from_string(StringView const& string)
return Color(r.value(), g.value(), b.value(), a.value());
}
Vector<Color> Color::shades(u32 steps, float max) const
{
float shade = 1.f;
float step = max / steps;
Vector<Color> shades;
for (u32 i = 0; i < steps; i++) {
shade -= step;
shades.append(this->darkened(shade));
}
return shades;
}
Vector<Color> Color::tints(u32 steps, float max) const
{
float shade = 1.f;
float step = max / steps;
Vector<Color> tints;
for (u32 i = 0; i < steps; i++) {
shade += step;
tints.append(this->lightened(shade));
}
return tints;
}
}
bool IPC::encode(IPC::Encoder& encoder, Color const& color)

View file

@ -242,29 +242,8 @@ public:
return Color(min(255, (int)((float)red() * amount)), min(255, (int)((float)green() * amount)), min(255, (int)((float)blue() * amount)), alpha());
}
Vector<Color> shades(u32 steps, float max = 1.f) const
{
float shade = 1.f;
float step = max / steps;
Vector<Color> shades;
for (u32 i = 0; i < steps; i++) {
shade -= step;
shades.append(this->darkened(shade));
}
return shades;
}
Vector<Color> tints(u32 steps, float max = 1.f) const
{
float shade = 1.f;
float step = max / steps;
Vector<Color> tints;
for (u32 i = 0; i < steps; i++) {
shade += step;
tints.append(this->lightened(shade));
}
return tints;
}
Vector<Color> shades(u32 steps, float max = 1.f) const;
Vector<Color> tints(u32 steps, float max = 1.f) const;
constexpr Color inverted() const
{

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Vector.h>
#include <LibGfx/Filters/FastBoxBlurFilter.h>
namespace Gfx {

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/FlyString.h>
#include <AK/Vector.h>
#include <LibJS/Heap/Cell.h>
namespace JS {

View file

@ -5,6 +5,7 @@
*/
#include "ParsedCookie.h"
#include <AK/Function.h>
#include <AK/StdLibExtras.h>
#include <AK/Vector.h>
#include <LibIPC/Decoder.h>
@ -280,12 +281,12 @@ Optional<Core::DateTime> parse_date_time(StringView date_string)
return to_uint(token, year);
};
auto is_delimeter = [](char ch) {
Function<bool(char)> is_delimiter = [](char ch) {
return ch == 0x09 || (ch >= 0x20 && ch <= 0x2f) || (ch >= 0x3b && ch <= 0x40) || (ch >= 0x5b && ch <= 0x60) || (ch >= 0x7b && ch <= 0x7e);
};
// 1. Using the grammar below, divide the cookie-date into date-tokens.
Vector<StringView> date_tokens = date_string.split_view_if(is_delimeter);
Vector<StringView> date_tokens = date_string.split_view_if(is_delimiter);
// 2. Process each date-token sequentially in the order the date-tokens appear in the cookie-date.
bool found_time = false;

View file

@ -7,6 +7,7 @@
#include "DNSName.h"
#include <AK/Random.h>
#include <AK/Vector.h>
#include <ctype.h>
namespace LookupServer {

View file

@ -12,6 +12,7 @@
#include <AK/StringBuilder.h>
#include <AK/StringView.h>
#include <AK/Types.h>
#include <AK/Vector.h>
#include <ctype.h>
namespace Shell {