2020-02-14 23:41:10 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-02-14 23:41:10 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-16 06:51:55 +03:00
|
|
|
#include <AK/DefaultDelete.h>
|
2022-12-18 04:06:29 +03:00
|
|
|
#include <AK/SinglyLinkedListSizePolicy.h>
|
2020-02-20 15:18:42 +03:00
|
|
|
#include <AK/Types.h>
|
|
|
|
|
2020-02-14 23:41:10 +03:00
|
|
|
namespace AK {
|
|
|
|
|
2021-05-14 21:53:04 +03:00
|
|
|
namespace Detail {
|
|
|
|
template<size_t inline_capacity>
|
2020-02-16 04:01:18 +03:00
|
|
|
class ByteBuffer;
|
2021-05-14 21:53:04 +03:00
|
|
|
}
|
|
|
|
|
2023-01-25 22:06:16 +03:00
|
|
|
class BigEndianInputBitStream;
|
|
|
|
class BigEndianOutputBitStream;
|
2023-03-10 15:22:42 +03:00
|
|
|
class Bitmap;
|
2022-11-14 21:25:18 +03:00
|
|
|
using ByteBuffer = Detail::ByteBuffer<32>;
|
2022-12-09 00:44:46 +03:00
|
|
|
class CircularBuffer;
|
2023-03-10 18:37:52 +03:00
|
|
|
class ConstrainedStream;
|
2023-03-16 12:23:24 +03:00
|
|
|
class CountingStream;
|
2023-03-10 15:22:42 +03:00
|
|
|
class DeprecatedFlyString;
|
|
|
|
class DeprecatedString;
|
|
|
|
class DeprecatedStringCodePointIterator;
|
2023-03-13 18:30:34 +03:00
|
|
|
class Duration;
|
2021-11-16 02:41:28 +03:00
|
|
|
class Error;
|
2023-01-11 16:26:49 +03:00
|
|
|
class FlyString;
|
2021-08-18 14:22:38 +03:00
|
|
|
class GenericLexer;
|
2020-02-14 23:41:10 +03:00
|
|
|
class IPv4Address;
|
|
|
|
class JsonArray;
|
|
|
|
class JsonObject;
|
|
|
|
class JsonValue;
|
2023-03-10 15:22:42 +03:00
|
|
|
class LexicalPath;
|
2023-01-25 22:06:16 +03:00
|
|
|
class LittleEndianInputBitStream;
|
|
|
|
class LittleEndianOutputBitStream;
|
2023-06-01 21:48:35 +03:00
|
|
|
class SearchableCircularBuffer;
|
2023-01-22 07:09:11 +03:00
|
|
|
class SeekableStream;
|
2023-03-10 15:22:42 +03:00
|
|
|
class StackInfo;
|
2023-01-22 07:09:11 +03:00
|
|
|
class Stream;
|
2023-03-10 15:22:42 +03:00
|
|
|
class String;
|
2020-02-14 23:41:10 +03:00
|
|
|
class StringBuilder;
|
|
|
|
class StringImpl;
|
|
|
|
class StringView;
|
|
|
|
class URL;
|
2023-03-14 00:06:22 +03:00
|
|
|
class UnixDateTime;
|
2021-07-19 16:02:13 +03:00
|
|
|
class Utf16View;
|
2023-02-20 22:04:42 +03:00
|
|
|
class Utf32CodePointIterator;
|
2020-05-17 21:01:45 +03:00
|
|
|
class Utf32View;
|
2022-02-23 23:05:27 +03:00
|
|
|
class Utf8CodePointIterator;
|
2020-02-15 01:28:34 +03:00
|
|
|
class Utf8View;
|
2020-08-25 15:57:02 +03:00
|
|
|
|
2020-07-25 17:00:26 +03:00
|
|
|
template<typename T>
|
|
|
|
class Span;
|
|
|
|
|
2020-09-06 22:13:34 +03:00
|
|
|
template<typename T, size_t Size>
|
2020-09-12 01:43:11 +03:00
|
|
|
struct Array;
|
2020-09-06 22:14:08 +03:00
|
|
|
|
|
|
|
template<typename Container, typename ValueType>
|
|
|
|
class SimpleIterator;
|
|
|
|
|
2023-02-05 20:59:03 +03:00
|
|
|
template<typename T>
|
|
|
|
using ReadonlySpan = Span<T const>;
|
|
|
|
|
|
|
|
using ReadonlyBytes = ReadonlySpan<u8>;
|
2020-07-25 17:00:26 +03:00
|
|
|
using Bytes = Span<u8>;
|
|
|
|
|
2021-01-04 02:43:10 +03:00
|
|
|
template<typename T, AK::MemoryOrder DefaultMemoryOrder>
|
2020-02-16 04:01:18 +03:00
|
|
|
class Atomic;
|
|
|
|
|
2022-12-18 04:06:29 +03:00
|
|
|
template<typename T, typename TSizeCalculationPolicy = DefaultSizeCalculationPolicy>
|
2020-02-14 23:41:10 +03:00
|
|
|
class SinglyLinkedList;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class DoublyLinkedList;
|
|
|
|
|
2020-02-20 15:18:42 +03:00
|
|
|
template<typename T, size_t capacity>
|
2020-02-14 23:41:10 +03:00
|
|
|
class CircularQueue;
|
|
|
|
|
2020-02-16 04:01:18 +03:00
|
|
|
template<typename T>
|
|
|
|
struct Traits;
|
|
|
|
|
2021-06-13 17:26:08 +03:00
|
|
|
template<typename T, typename TraitsForT = Traits<T>, bool IsOrdered = false>
|
2020-02-16 04:01:18 +03:00
|
|
|
class HashTable;
|
|
|
|
|
2021-06-13 17:26:08 +03:00
|
|
|
template<typename T, typename TraitsForT = Traits<T>>
|
|
|
|
using OrderedHashTable = HashTable<T, TraitsForT, true>;
|
|
|
|
|
2022-12-09 19:39:56 +03:00
|
|
|
template<typename K, typename V, typename KeyTraits = Traits<K>, typename ValueTraits = Traits<V>, bool IsOrdered = false>
|
2020-02-16 04:01:18 +03:00
|
|
|
class HashMap;
|
|
|
|
|
2022-12-09 19:39:56 +03:00
|
|
|
template<typename K, typename V, typename KeyTraits = Traits<K>, typename ValueTraits = Traits<V>>
|
|
|
|
using OrderedHashMap = HashMap<K, V, KeyTraits, ValueTraits, true>;
|
2021-06-13 17:26:08 +03:00
|
|
|
|
2020-02-14 23:41:10 +03:00
|
|
|
template<typename T>
|
|
|
|
class Badge;
|
|
|
|
|
2021-07-11 18:16:13 +03:00
|
|
|
template<typename T>
|
|
|
|
class FixedArray;
|
|
|
|
|
2021-12-28 04:18:53 +03:00
|
|
|
template<size_t precision, typename Underlying = i32>
|
|
|
|
class FixedPoint;
|
|
|
|
|
2020-02-14 23:41:10 +03:00
|
|
|
template<typename>
|
|
|
|
class Function;
|
|
|
|
|
|
|
|
template<typename Out, typename... In>
|
|
|
|
class Function<Out(In...)>;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class NonnullRefPtr;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class NonnullOwnPtr;
|
|
|
|
|
2020-02-15 00:29:06 +03:00
|
|
|
template<typename T>
|
|
|
|
class Optional;
|
|
|
|
|
2022-05-07 13:50:54 +03:00
|
|
|
#ifdef KERNEL
|
2020-02-14 23:41:10 +03:00
|
|
|
template<typename T>
|
2022-08-19 21:53:40 +03:00
|
|
|
class NonnullLockRefPtr;
|
|
|
|
|
2022-05-07 13:50:54 +03:00
|
|
|
template<typename T>
|
2022-08-19 21:53:40 +03:00
|
|
|
struct LockRefPtrTraits;
|
|
|
|
|
|
|
|
template<typename T, typename PtrTraits = LockRefPtrTraits<T>>
|
|
|
|
class LockRefPtr;
|
2022-05-07 13:50:54 +03:00
|
|
|
#endif
|
2020-02-14 23:41:10 +03:00
|
|
|
|
2022-08-19 21:53:40 +03:00
|
|
|
template<typename T>
|
|
|
|
class RefPtr;
|
|
|
|
|
2022-12-16 06:51:55 +03:00
|
|
|
template<typename T, typename TDeleter = DefaultDelete<T>>
|
2020-02-14 23:41:10 +03:00
|
|
|
class OwnPtr;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class WeakPtr;
|
|
|
|
|
2020-02-25 16:49:47 +03:00
|
|
|
template<typename T, size_t inline_capacity = 0>
|
2021-06-08 16:24:06 +03:00
|
|
|
requires(!IsRvalueReference<T>) class Vector;
|
2020-02-14 23:41:10 +03:00
|
|
|
|
2021-11-16 02:41:28 +03:00
|
|
|
template<typename T, typename ErrorType = Error>
|
|
|
|
class [[nodiscard]] ErrorOr;
|
|
|
|
|
2020-02-14 23:41:10 +03:00
|
|
|
}
|
|
|
|
|
2022-11-26 14:18:30 +03:00
|
|
|
#if USING_AK_GLOBALLY
|
2020-09-06 22:14:08 +03:00
|
|
|
using AK::Array;
|
2020-02-16 04:01:18 +03:00
|
|
|
using AK::Atomic;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::Badge;
|
2023-01-25 22:06:16 +03:00
|
|
|
using AK::BigEndianInputBitStream;
|
|
|
|
using AK::BigEndianOutputBitStream;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::Bitmap;
|
|
|
|
using AK::ByteBuffer;
|
2020-07-25 17:00:26 +03:00
|
|
|
using AK::Bytes;
|
2022-12-09 00:44:46 +03:00
|
|
|
using AK::CircularBuffer;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::CircularQueue;
|
2023-03-10 18:37:52 +03:00
|
|
|
using AK::ConstrainedStream;
|
2023-03-16 12:23:24 +03:00
|
|
|
using AK::CountingStream;
|
2023-01-09 03:23:00 +03:00
|
|
|
using AK::DeprecatedFlyString;
|
2022-12-04 21:02:33 +03:00
|
|
|
using AK::DeprecatedString;
|
2023-01-27 18:26:57 +03:00
|
|
|
using AK::DeprecatedStringCodePointIterator;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::DoublyLinkedList;
|
2023-03-13 18:30:34 +03:00
|
|
|
using AK::Duration;
|
2021-11-16 02:41:28 +03:00
|
|
|
using AK::Error;
|
|
|
|
using AK::ErrorOr;
|
2021-07-11 18:16:13 +03:00
|
|
|
using AK::FixedArray;
|
2021-12-28 04:18:53 +03:00
|
|
|
using AK::FixedPoint;
|
2023-03-18 17:56:25 +03:00
|
|
|
using AK::FlyString;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::Function;
|
2021-08-18 14:22:38 +03:00
|
|
|
using AK::GenericLexer;
|
2020-02-16 04:01:18 +03:00
|
|
|
using AK::HashMap;
|
|
|
|
using AK::HashTable;
|
2020-02-20 15:18:42 +03:00
|
|
|
using AK::IPv4Address;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::JsonArray;
|
|
|
|
using AK::JsonObject;
|
|
|
|
using AK::JsonValue;
|
2023-03-10 15:22:42 +03:00
|
|
|
using AK::LexicalPath;
|
2023-01-25 22:06:16 +03:00
|
|
|
using AK::LittleEndianInputBitStream;
|
|
|
|
using AK::LittleEndianOutputBitStream;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::NonnullOwnPtr;
|
|
|
|
using AK::NonnullRefPtr;
|
2020-02-15 00:29:06 +03:00
|
|
|
using AK::Optional;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::OwnPtr;
|
2020-07-25 17:00:26 +03:00
|
|
|
using AK::ReadonlyBytes;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::RefPtr;
|
2023-06-01 21:48:35 +03:00
|
|
|
using AK::SearchableCircularBuffer;
|
2023-01-22 07:09:11 +03:00
|
|
|
using AK::SeekableStream;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::SinglyLinkedList;
|
2020-07-25 17:00:26 +03:00
|
|
|
using AK::Span;
|
2020-11-08 15:48:16 +03:00
|
|
|
using AK::StackInfo;
|
2023-01-22 07:09:11 +03:00
|
|
|
using AK::Stream;
|
AK: Introduce the new String, replacement for DeprecatedString
DeprecatedString (formerly String) has been with us since the start,
and it has served us well. However, it has a number of shortcomings
that I'd like to address.
Some of these issues are hard if not impossible to solve incrementally
inside of DeprecatedString, so instead of doing that, let's build a new
String class and then incrementally move over to it instead.
Problems in DeprecatedString:
- It assumes string allocation never fails. This makes it impossible
to use in allocation-sensitive contexts, and is the reason we had to
ban DeprecatedString from the kernel entirely.
- The awkward null state. DeprecatedString can be null. It's different
from the empty state, although null strings are considered empty.
All code is immediately nicer when using Optional<DeprecatedString>
but DeprecatedString came before Optional, which is how we ended up
like this.
- The encoding of the underlying data is ambiguous. For the most part,
we use it as if it's always UTF-8, but there have been cases where
we pass around strings in other encodings (e.g ISO8859-1)
- operator[] and length() are used to iterate over DeprecatedString one
byte at a time. This is done all over the codebase, and will *not*
give the right results unless the string is all ASCII.
How we solve these issues in the new String:
- Functions that may allocate now return ErrorOr<String> so that ENOMEM
errors can be passed to the caller.
- String has no null state. Use Optional<String> when needed.
- String is always UTF-8. This is validated when constructing a String.
We may need to add a bypass for this in the future, for cases where
you have a known-good string, but for now: validate all the things!
- There is no operator[] or length(). You can get the underlying data
with bytes(), but for iterating over code points, you should be using
an UTF-8 iterator.
Furthermore, it has two nifty new features:
- String implements a small string optimization (SSO) for strings that
can fit entirely within a pointer. This means up to 3 bytes on 32-bit
platforms, and 7 bytes on 64-bit platforms. Such small strings will
not be heap-allocated.
- String can create substrings without making a deep copy of the
substring. Instead, the superstring gets +1 refcount from the
substring, and it acts like a view into the superstring. To make
substrings like this, use the substring_with_shared_superstring() API.
One caveat:
- String does not guarantee that the underlying data is null-terminated
like DeprecatedString does today. While this was nifty in a handful of
places where we were calling C functions, it did stand in the way of
shared-superstring substrings.
2022-12-01 15:27:43 +03:00
|
|
|
using AK::String;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::StringBuilder;
|
|
|
|
using AK::StringImpl;
|
|
|
|
using AK::StringView;
|
2020-02-16 04:01:18 +03:00
|
|
|
using AK::Traits;
|
2023-03-14 00:06:22 +03:00
|
|
|
using AK::UnixDateTime;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::URL;
|
2021-07-19 16:02:13 +03:00
|
|
|
using AK::Utf16View;
|
2023-02-20 22:04:42 +03:00
|
|
|
using AK::Utf32CodePointIterator;
|
2020-05-17 21:01:45 +03:00
|
|
|
using AK::Utf32View;
|
2022-02-23 23:05:27 +03:00
|
|
|
using AK::Utf8CodePointIterator;
|
2020-02-15 01:28:34 +03:00
|
|
|
using AK::Utf8View;
|
2020-02-14 23:41:10 +03:00
|
|
|
using AK::Vector;
|
2022-08-19 21:53:40 +03:00
|
|
|
|
2022-11-26 14:18:30 +03:00
|
|
|
# ifdef KERNEL
|
2022-08-19 21:53:40 +03:00
|
|
|
using AK::LockRefPtr;
|
|
|
|
using AK::LockRefPtrTraits;
|
|
|
|
using AK::NonnullLockRefPtr;
|
2022-11-26 14:18:30 +03:00
|
|
|
# endif
|
|
|
|
|
2022-08-19 21:53:40 +03:00
|
|
|
#endif
|