2020-02-14 20:41:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-02-14 20:41:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-16 03:51:55 +00:00
|
|
|
#include <AK/DefaultDelete.h>
|
2022-12-18 01:06:29 +00:00
|
|
|
#include <AK/SinglyLinkedListSizePolicy.h>
|
2024-02-08 23:52:03 +00:00
|
|
|
#include <AK/StdLibExtras.h>
|
2020-02-20 12:18:42 +00:00
|
|
|
#include <AK/Types.h>
|
|
|
|
|
2020-02-14 20:41:10 +00:00
|
|
|
namespace AK {
|
|
|
|
|
2021-05-14 18:53:04 +00:00
|
|
|
namespace Detail {
|
|
|
|
template<size_t inline_capacity>
|
2020-02-16 01:01:18 +00:00
|
|
|
class ByteBuffer;
|
2021-05-14 18:53:04 +00:00
|
|
|
}
|
|
|
|
|
2023-11-27 07:56:50 +00:00
|
|
|
enum class TrailingCodePointTransformation : u8;
|
|
|
|
|
2023-01-25 19:06:16 +00:00
|
|
|
class BigEndianInputBitStream;
|
|
|
|
class BigEndianOutputBitStream;
|
2023-03-10 12:22:42 +00:00
|
|
|
class Bitmap;
|
2022-11-14 18:25:18 +00:00
|
|
|
using ByteBuffer = Detail::ByteBuffer<32>;
|
2022-12-08 21:44:46 +00:00
|
|
|
class CircularBuffer;
|
2023-03-10 15:37:52 +00:00
|
|
|
class ConstrainedStream;
|
2023-03-16 09:23:24 +00:00
|
|
|
class CountingStream;
|
2023-03-10 12:22:42 +00:00
|
|
|
class DeprecatedFlyString;
|
2023-12-16 14:19:34 +00:00
|
|
|
class ByteString;
|
2023-03-10 12:22:42 +00:00
|
|
|
class DeprecatedStringCodePointIterator;
|
2023-03-13 15:30:34 +00:00
|
|
|
class Duration;
|
2021-11-15 23:41:28 +00:00
|
|
|
class Error;
|
2023-01-11 13:26:49 +00:00
|
|
|
class FlyString;
|
2021-08-18 11:22:38 +00:00
|
|
|
class GenericLexer;
|
2020-02-14 20:41:10 +00:00
|
|
|
class IPv4Address;
|
|
|
|
class JsonArray;
|
|
|
|
class JsonObject;
|
|
|
|
class JsonValue;
|
2023-03-10 12:22:42 +00:00
|
|
|
class LexicalPath;
|
2023-01-25 19:06:16 +00:00
|
|
|
class LittleEndianInputBitStream;
|
|
|
|
class LittleEndianOutputBitStream;
|
2023-06-01 18:48:35 +00:00
|
|
|
class SearchableCircularBuffer;
|
2023-01-22 04:09:11 +00:00
|
|
|
class SeekableStream;
|
2023-03-10 12:22:42 +00:00
|
|
|
class StackInfo;
|
2023-01-22 04:09:11 +00:00
|
|
|
class Stream;
|
2023-03-10 12:22:42 +00:00
|
|
|
class String;
|
2020-02-14 20:41:10 +00:00
|
|
|
class StringBuilder;
|
|
|
|
class StringImpl;
|
|
|
|
class StringView;
|
2023-03-13 21:06:22 +00:00
|
|
|
class UnixDateTime;
|
2021-07-19 13:02:13 +00:00
|
|
|
class Utf16View;
|
2023-02-20 19:04:42 +00:00
|
|
|
class Utf32CodePointIterator;
|
2020-05-17 18:01:45 +00:00
|
|
|
class Utf32View;
|
2022-02-23 20:05:27 +00:00
|
|
|
class Utf8CodePointIterator;
|
2020-02-14 22:28:34 +00:00
|
|
|
class Utf8View;
|
2020-08-25 12:57:02 +00:00
|
|
|
|
2020-07-25 14:00:26 +00:00
|
|
|
template<typename T>
|
|
|
|
class Span;
|
|
|
|
|
2020-09-06 19:13:34 +00:00
|
|
|
template<typename T, size_t Size>
|
2020-09-11 22:43:11 +00:00
|
|
|
struct Array;
|
2020-09-06 19:14:08 +00:00
|
|
|
|
|
|
|
template<typename Container, typename ValueType>
|
|
|
|
class SimpleIterator;
|
|
|
|
|
2023-02-05 17:59:03 +00:00
|
|
|
template<typename T>
|
|
|
|
using ReadonlySpan = Span<T const>;
|
|
|
|
|
|
|
|
using ReadonlyBytes = ReadonlySpan<u8>;
|
2020-07-25 14:00:26 +00:00
|
|
|
using Bytes = Span<u8>;
|
|
|
|
|
2021-01-03 23:43:10 +00:00
|
|
|
template<typename T, AK::MemoryOrder DefaultMemoryOrder>
|
2020-02-16 01:01:18 +00:00
|
|
|
class Atomic;
|
|
|
|
|
2022-12-18 01:06:29 +00:00
|
|
|
template<typename T, typename TSizeCalculationPolicy = DefaultSizeCalculationPolicy>
|
2020-02-14 20:41:10 +00:00
|
|
|
class SinglyLinkedList;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class DoublyLinkedList;
|
|
|
|
|
2020-02-20 12:18:42 +00:00
|
|
|
template<typename T, size_t capacity>
|
2020-02-14 20:41:10 +00:00
|
|
|
class CircularQueue;
|
|
|
|
|
2020-02-16 01:01:18 +00:00
|
|
|
template<typename T>
|
|
|
|
struct Traits;
|
|
|
|
|
2021-06-13 14:26:08 +00:00
|
|
|
template<typename T, typename TraitsForT = Traits<T>, bool IsOrdered = false>
|
2020-02-16 01:01:18 +00:00
|
|
|
class HashTable;
|
|
|
|
|
2021-06-13 14:26:08 +00:00
|
|
|
template<typename T, typename TraitsForT = Traits<T>>
|
|
|
|
using OrderedHashTable = HashTable<T, TraitsForT, true>;
|
|
|
|
|
2022-12-09 16:39:56 +00:00
|
|
|
template<typename K, typename V, typename KeyTraits = Traits<K>, typename ValueTraits = Traits<V>, bool IsOrdered = false>
|
2020-02-16 01:01:18 +00:00
|
|
|
class HashMap;
|
|
|
|
|
2022-12-09 16:39:56 +00: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 14:26:08 +00:00
|
|
|
|
2020-02-14 20:41:10 +00:00
|
|
|
template<typename T>
|
|
|
|
class Badge;
|
|
|
|
|
2021-07-11 15:16:13 +00:00
|
|
|
template<typename T>
|
|
|
|
class FixedArray;
|
|
|
|
|
2021-12-28 01:18:53 +00:00
|
|
|
template<size_t precision, typename Underlying = i32>
|
|
|
|
class FixedPoint;
|
|
|
|
|
2020-02-14 20:41:10 +00: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-14 21:29:06 +00:00
|
|
|
template<typename T>
|
|
|
|
class Optional;
|
|
|
|
|
2022-08-19 18:53:40 +00:00
|
|
|
template<typename T>
|
|
|
|
class RefPtr;
|
|
|
|
|
2022-12-16 03:51:55 +00:00
|
|
|
template<typename T, typename TDeleter = DefaultDelete<T>>
|
2020-02-14 20:41:10 +00:00
|
|
|
class OwnPtr;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class WeakPtr;
|
|
|
|
|
2020-02-25 13:49:47 +00:00
|
|
|
template<typename T, size_t inline_capacity = 0>
|
2021-06-08 13:24:06 +00:00
|
|
|
requires(!IsRvalueReference<T>) class Vector;
|
2020-02-14 20:41:10 +00:00
|
|
|
|
2021-11-15 23:41:28 +00:00
|
|
|
template<typename T, typename ErrorType = Error>
|
|
|
|
class [[nodiscard]] ErrorOr;
|
|
|
|
|
2020-02-14 20:41:10 +00:00
|
|
|
}
|
|
|
|
|
2022-11-26 11:18:30 +00:00
|
|
|
#if USING_AK_GLOBALLY
|
2020-09-06 19:14:08 +00:00
|
|
|
using AK::Array;
|
2020-02-16 01:01:18 +00:00
|
|
|
using AK::Atomic;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::Badge;
|
2023-01-25 19:06:16 +00:00
|
|
|
using AK::BigEndianInputBitStream;
|
|
|
|
using AK::BigEndianOutputBitStream;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::Bitmap;
|
|
|
|
using AK::ByteBuffer;
|
2020-07-25 14:00:26 +00:00
|
|
|
using AK::Bytes;
|
2023-12-16 14:19:34 +00:00
|
|
|
using AK::ByteString;
|
2022-12-08 21:44:46 +00:00
|
|
|
using AK::CircularBuffer;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::CircularQueue;
|
2023-03-10 15:37:52 +00:00
|
|
|
using AK::ConstrainedStream;
|
2023-03-16 09:23:24 +00:00
|
|
|
using AK::CountingStream;
|
2023-01-09 00:23:00 +00:00
|
|
|
using AK::DeprecatedFlyString;
|
2023-01-27 15:26:57 +00:00
|
|
|
using AK::DeprecatedStringCodePointIterator;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::DoublyLinkedList;
|
2023-03-13 15:30:34 +00:00
|
|
|
using AK::Duration;
|
2021-11-15 23:41:28 +00:00
|
|
|
using AK::Error;
|
|
|
|
using AK::ErrorOr;
|
2021-07-11 15:16:13 +00:00
|
|
|
using AK::FixedArray;
|
2021-12-28 01:18:53 +00:00
|
|
|
using AK::FixedPoint;
|
2023-03-18 14:56:25 +00:00
|
|
|
using AK::FlyString;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::Function;
|
2021-08-18 11:22:38 +00:00
|
|
|
using AK::GenericLexer;
|
2020-02-16 01:01:18 +00:00
|
|
|
using AK::HashMap;
|
|
|
|
using AK::HashTable;
|
2020-02-20 12:18:42 +00:00
|
|
|
using AK::IPv4Address;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::JsonArray;
|
|
|
|
using AK::JsonObject;
|
|
|
|
using AK::JsonValue;
|
2023-03-10 12:22:42 +00:00
|
|
|
using AK::LexicalPath;
|
2023-01-25 19:06:16 +00:00
|
|
|
using AK::LittleEndianInputBitStream;
|
|
|
|
using AK::LittleEndianOutputBitStream;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::NonnullOwnPtr;
|
|
|
|
using AK::NonnullRefPtr;
|
2020-02-14 21:29:06 +00:00
|
|
|
using AK::Optional;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::OwnPtr;
|
2020-07-25 14:00:26 +00:00
|
|
|
using AK::ReadonlyBytes;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::RefPtr;
|
2023-06-01 18:48:35 +00:00
|
|
|
using AK::SearchableCircularBuffer;
|
2023-01-22 04:09:11 +00:00
|
|
|
using AK::SeekableStream;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::SinglyLinkedList;
|
2020-07-25 14:00:26 +00:00
|
|
|
using AK::Span;
|
2020-11-08 12:48:16 +00:00
|
|
|
using AK::StackInfo;
|
2023-01-22 04:09:11 +00: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 12:27:43 +00:00
|
|
|
using AK::String;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::StringBuilder;
|
|
|
|
using AK::StringImpl;
|
|
|
|
using AK::StringView;
|
2023-11-27 07:56:50 +00:00
|
|
|
using AK::TrailingCodePointTransformation;
|
2020-02-16 01:01:18 +00:00
|
|
|
using AK::Traits;
|
2023-03-13 21:06:22 +00:00
|
|
|
using AK::UnixDateTime;
|
2021-07-19 13:02:13 +00:00
|
|
|
using AK::Utf16View;
|
2023-02-20 19:04:42 +00:00
|
|
|
using AK::Utf32CodePointIterator;
|
2020-05-17 18:01:45 +00:00
|
|
|
using AK::Utf32View;
|
2022-02-23 20:05:27 +00:00
|
|
|
using AK::Utf8CodePointIterator;
|
2020-02-14 22:28:34 +00:00
|
|
|
using AK::Utf8View;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::Vector;
|
2022-08-19 18:53:40 +00:00
|
|
|
|
|
|
|
#endif
|