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
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
class Bitmap;
|
|
|
|
using ByteBuffer = AK::Detail::ByteBuffer<32>;
|
2021-11-15 23:41:28 +00:00
|
|
|
class Error;
|
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;
|
2020-11-08 12:48:16 +00:00
|
|
|
class StackInfo;
|
2022-12-04 18:02:33 +00:00
|
|
|
class DeprecatedString;
|
2020-02-14 20:41:10 +00:00
|
|
|
class StringBuilder;
|
|
|
|
class StringImpl;
|
|
|
|
class StringView;
|
2021-02-13 10:33:28 +00:00
|
|
|
class Time;
|
2020-02-14 20:41:10 +00:00
|
|
|
class URL;
|
2020-03-22 09:12:55 +00:00
|
|
|
class FlyString;
|
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
|
|
|
class String;
|
2021-07-19 13:02:13 +00:00
|
|
|
class Utf16View;
|
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-05 10:14:44 +00:00
|
|
|
class InputStream;
|
|
|
|
class InputMemoryStream;
|
2020-08-18 16:04:17 +00:00
|
|
|
class DuplexMemoryStream;
|
2020-08-25 12:57:02 +00:00
|
|
|
class OutputStream;
|
2020-08-25 13:19:55 +00:00
|
|
|
class InputBitStream;
|
2021-03-01 15:43:54 +00:00
|
|
|
class OutputBitStream;
|
2020-09-15 10:08:00 +00:00
|
|
|
class OutputMemoryStream;
|
2020-08-25 12:57:02 +00:00
|
|
|
|
|
|
|
template<size_t Capacity>
|
|
|
|
class CircularDuplexStream;
|
2020-02-14 20:41:10 +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;
|
|
|
|
|
2022-08-19 18:53:40 +00:00
|
|
|
using ReadonlyBytes = Span<u8 const>;
|
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;
|
|
|
|
|
2020-02-14 20:41:10 +00:00
|
|
|
template<typename T>
|
|
|
|
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>;
|
|
|
|
|
|
|
|
template<typename K, typename V, typename KeyTraits = Traits<K>, bool IsOrdered = false>
|
2020-02-16 01:01:18 +00:00
|
|
|
class HashMap;
|
|
|
|
|
2021-06-28 09:02:18 +00:00
|
|
|
template<typename K, typename V, typename KeyTraits = Traits<K>>
|
2021-06-13 14:26:08 +00:00
|
|
|
using OrderedHashMap = HashMap<K, V, KeyTraits, true>;
|
|
|
|
|
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;
|
|
|
|
|
2021-02-20 16:39:58 +00:00
|
|
|
template<typename T, size_t inline_capacity = 0>
|
2022-08-19 18:53:40 +00:00
|
|
|
class NonnullOwnPtrVector;
|
2020-12-01 23:19:30 +00:00
|
|
|
|
2021-02-20 16:39:58 +00:00
|
|
|
template<typename T, size_t inline_capacity = 0>
|
2022-08-19 18:53:40 +00:00
|
|
|
class NonnullRefPtrVector;
|
2020-12-01 23:19:30 +00:00
|
|
|
|
2020-02-14 21:29:06 +00:00
|
|
|
template<typename T>
|
|
|
|
class Optional;
|
|
|
|
|
2022-05-07 10:50:54 +00:00
|
|
|
#ifdef KERNEL
|
2020-02-14 20:41:10 +00:00
|
|
|
template<typename T>
|
2022-08-19 18:53:40 +00:00
|
|
|
class NonnullLockRefPtr;
|
|
|
|
|
|
|
|
template<typename T, size_t inline_capacity = 0>
|
|
|
|
class NonnullLockRefPtrVector;
|
2020-09-23 16:17:43 +00:00
|
|
|
|
2022-05-07 10:50:54 +00:00
|
|
|
template<typename T>
|
2022-08-19 18:53:40 +00:00
|
|
|
struct LockRefPtrTraits;
|
|
|
|
|
|
|
|
template<typename T, typename PtrTraits = LockRefPtrTraits<T>>
|
|
|
|
class LockRefPtr;
|
2022-05-07 10:50:54 +00:00
|
|
|
#endif
|
2020-02-14 20:41:10 +00:00
|
|
|
|
2022-08-19 18:53:40 +00:00
|
|
|
template<typename T>
|
|
|
|
class RefPtr;
|
|
|
|
|
2020-02-14 20:41:10 +00:00
|
|
|
template<typename T>
|
|
|
|
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;
|
|
|
|
using AK::Bitmap;
|
|
|
|
using AK::ByteBuffer;
|
2020-07-25 14:00:26 +00:00
|
|
|
using AK::Bytes;
|
2020-08-25 12:57:02 +00:00
|
|
|
using AK::CircularDuplexStream;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::CircularQueue;
|
2022-12-04 18:02:33 +00:00
|
|
|
using AK::DeprecatedString;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::DoublyLinkedList;
|
2020-08-18 16:04:17 +00:00
|
|
|
using AK::DuplexMemoryStream;
|
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;
|
2020-05-17 18:01:45 +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-08-25 13:19:55 +00:00
|
|
|
using AK::InputBitStream;
|
2020-08-05 10:14:44 +00:00
|
|
|
using AK::InputMemoryStream;
|
|
|
|
using AK::InputStream;
|
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;
|
|
|
|
using AK::NonnullOwnPtr;
|
2020-12-01 23:19:30 +00:00
|
|
|
using AK::NonnullOwnPtrVector;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::NonnullRefPtr;
|
2020-12-01 23:19:30 +00:00
|
|
|
using AK::NonnullRefPtrVector;
|
2020-02-14 21:29:06 +00:00
|
|
|
using AK::Optional;
|
2021-03-01 15:43:54 +00:00
|
|
|
using AK::OutputBitStream;
|
2020-09-15 10:08:00 +00:00
|
|
|
using AK::OutputMemoryStream;
|
2020-08-25 12:57:02 +00:00
|
|
|
using AK::OutputStream;
|
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;
|
|
|
|
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;
|
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;
|
2021-02-13 10:33:28 +00:00
|
|
|
using AK::Time;
|
2020-02-16 01:01:18 +00:00
|
|
|
using AK::Traits;
|
2020-02-14 20:41:10 +00:00
|
|
|
using AK::URL;
|
2021-07-19 13:02:13 +00:00
|
|
|
using AK::Utf16View;
|
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
|
|
|
|
2022-11-26 11:18:30 +00:00
|
|
|
# ifdef KERNEL
|
2022-08-19 18:53:40 +00:00
|
|
|
using AK::LockRefPtr;
|
|
|
|
using AK::LockRefPtrTraits;
|
|
|
|
using AK::NonnullLockRefPtr;
|
|
|
|
using AK::NonnullLockRefPtrVector;
|
2022-11-26 11:18:30 +00:00
|
|
|
# endif
|
|
|
|
|
2022-08-19 18:53:40 +00:00
|
|
|
#endif
|