mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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:
parent
e52f987020
commit
5f7d008791
Notes:
sideshowbarker
2024-07-18 01:18:19 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/5f7d008791f
27 changed files with 88 additions and 51 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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); }
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
1
AK/URL.h
1
AK/URL.h
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <Kernel/KLexicalPath.h>
|
||||
|
||||
namespace Kernel::KLexicalPath {
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <AK/BinarySearch.h>
|
||||
#include <AK/Span.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <cstring>
|
||||
#include <new>
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <AK/DisjointChunks.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
TEST_CASE(basic)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
TEST_CASE(basic_optional)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <LibTest/TestCase.h>
|
||||
|
||||
#include <AK/StringUtils.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
TEST_CASE(matches_null)
|
||||
{
|
||||
|
|
|
@ -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" }));
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <LibTest/TestCase.h>
|
||||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibC/regex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGfx/Filters/FastBoxBlurFilter.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
|
||||
namespace JS {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "DNSName.h"
|
||||
#include <AK/Random.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <ctype.h>
|
||||
|
||||
namespace LookupServer {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue