1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 08:40:44 +00:00
Commit Graph

2830 Commits

Author SHA1 Message Date
Sam Atkins
c7a66882f4 AK: Make NonnullPtrVectors shuffleable
AK::shuffle() doesn't work on these, because their operator[] returns a
reference to the pointed-at value, instead of to the NonnullPtr itself.
2023-01-22 21:31:36 +00:00
Nico Weber
aa9037eed4 AK: Add spec comments to Utf16CodePointIterator::operator*() 2023-01-22 21:30:44 +00:00
Timothy Flynn
ef275e25b8 AK: Reduce String's allocated data by one byte
This was copied from allocation_size_for_stringimpl, which had to ensure
the string is null-terminated. String makes no such guarantee.
2023-01-22 20:27:52 +00:00
Karol Kosek
2d976ab2a6 AK: Define is_trivially_serializable trait for Little and BigEndian<>
This will allow us get LittleEndian<> and BigEndian<> wrapped types
directly from Stream::read_value<>().
2023-01-22 20:58:42 +01:00
Timothy Flynn
12c8bc3e85 AK: Add a String factory to create a string from a single code point 2023-01-22 01:03:13 +00:00
Timothy Flynn
8aca8e82cb AK: Change String's default constructor to be constant
This allows creating expressions such as:

    constexpr Array<String, 10> {};
2023-01-22 01:03:13 +00:00
Andrew Kaster
7ab37ee22c Everywhere: Remove string.h include from AK/Traits.h and resolve fallout
A lot of places were relying on AK/Traits.h to give it strnlen, memcmp,
memcpy and other related declarations.

In the quest to remove inclusion of LibC headers from Kernel files, deal
with all the fallout of this included-everywhere header including less
things.
2023-01-21 10:43:59 -07:00
Tim Schumacher
63cf9b973d AK: Remove FileStream 2023-01-21 14:43:56 +01:00
martinfalisse
aec2dadfdd AK: Add split() for String 2023-01-21 14:35:00 +01:00
Timothy Flynn
4f5353cbb8 AK: Rename double_hash to rehash_for_collision
The name is currently quite confusing as it indicates it hashes doubles.
2023-01-21 10:36:14 +01:00
Timothy Flynn
60b56892ca AK: Add a type alias for DistinctNumeric's underlying type 2023-01-21 10:36:14 +01:00
Tim Schumacher
49b30d3013 AK: Remove InputBitStream and OutputBitStream 2023-01-21 00:45:33 +00:00
Tim Schumacher
d7eead4f4c AK: Remove DuplexMemoryStream 2023-01-20 20:48:40 +00:00
Timothy Flynn
c8e25a71e0 AK: Disable use of consteval in String::from_utf8_short_string for Apple
This causes an ICE on older versions of clang, and Apple's clang is
currently based on such a version.
2023-01-20 20:33:04 +00:00
Timothy Flynn
d48266a420 AK: Support creating known short string literals at compile time
In cases where we know a string literal will fit in the short string
storage, we can do so at compile time without needing to handle error
propagation. If the provided string literal is too long, a compilation
error will be emitted due to the failed VERIFY statement being a non-
constant expression.
2023-01-20 14:24:12 -05:00
Timothy Flynn
5063e218af AK: Move the AK::FixedPoint formatter to FixedPoint.h
This does not need to be defined in Format.h. This causes FixedPoint.h
to be included everywhere. This is particularly going to be an issue
when trying to include <CoreServices/CoreServices.h> on macOS. The macOS
SDK defines its own FixedPoint structure which will conflict with ours.
2023-01-19 11:29:48 +00:00
Peter Elliott
b217045f8f AK: Don't write trailing zeros with %g 2023-01-19 12:22:24 +01:00
konrad
9b12571a86 AK: Unify kernel debug messages, avoid printing time if unavailable 2023-01-18 22:58:42 +01:00
konrad
9f736d782c AK: Patch ArbitrarySizedEnum operators for missing constructor
Patch kindly provided by Ali on #aarch64 on Discord.

Co-authored-by: Ali Mohammad Pur <mpfard@serenityos.org>
2023-01-18 22:58:42 +01:00
Timothy Flynn
537fcaf59e AK+LibUnicode: Provide Unicode-aware caseless String matching
The Unicode spec defines much more complicated caseless matching
algorithms in its Collation spec. This implements the "basic" case
folding comparison.
2023-01-18 14:43:40 +00:00
Sam Atkins
79547896b7 AK: Replace uses of JsonObject::get_deprecated()/get_ptr() 2023-01-17 19:52:52 -05:00
Sam Atkins
8d3b268cca AK: Add JsonObject::get...() methods that return Optional
`get()` is intended as a replacement for `get_deprecated()` and `get_ptr
()`. The former returns the same value for "key not found" and "key
found and contains `null`" which is ambiguous. The latter returns a raw
pointer which is spooky. Returning `Optional<JsonValue const&>` covers
all the previous uses for these.

The `get_foo()` methods are helpers to make user code less verbose. Most
of the time, we only want a specific type of value: if we want a number
and get a string, we respond the same as if the value was not there at
all. These make that easier to express.

This also adjusts the `has_i32()` method and friends to examine the
value instead of just looking at the underlying type.
2023-01-17 19:52:52 -05:00
Sam Atkins
d1ad63c466 AK: Move JsonObject implementation out of line 2023-01-17 19:52:52 -05:00
Sam Atkins
1dd6b7f5b7 AK+Everywhere: Rename JsonObject::get() to ::get_deprecated()
This is a preparatory step to making `get()` return `ErrorOr`.
2023-01-17 19:52:52 -05:00
Sam Atkins
efe4329f9f AK: Add JsonValue::{is,as}_integer() methods
The existing `is_i32()` and friends only check if `i32` is their
internal type, but a value such as `0` could be literally any integer
type internally. `is_integer<T>()` instead determines whether the
contained value is an integer and can fit inside T.
2023-01-17 19:52:52 -05:00
Timothy Flynn
d6ddca0c0f AK+LibUnicode: Provide Unicode-aware String titlecase transformation 2023-01-16 18:33:44 -05:00
Timothy Flynn
0a1874c203 AK: Export the OptionalNone helper structure 2023-01-16 10:12:37 +00:00
Tim Schumacher
d1711f1cef AK: Define our own concept of "trivially serializable"
While at it, rename the `read_trivial_value` and `write_trivial_value`
functions to `read_value` and `write_value` respectively, since we'll
add compatibility for non-trivial types down the line.
2023-01-15 23:06:31 -05:00
Lucas CHOLLET
3b824ec8c9 AK+Test: Fix a logic error in CircularBuffer::offset_of()
This error was introduced by 9a7accdd and had a significant impact on
`BufferedFile` behavior. Hence, we started seeing crash in test262.

By itself, the issue was a wrong calculation of the internal reading
spans when using the `read` and `until` parameters. Which can lead to
at worse crash in VERIFY and at least weird behaviors as missed needles
or detections out of bounds.

It was also accompanied by an erroneous test.

This patch fixes the bug, the test and also provides more tests.
2023-01-15 23:23:24 +00:00
Timothy Flynn
63c814fa2f AK: Add String::to_number 2023-01-15 01:00:20 +00:00
Timothy Flynn
cf0899f440 AK: Add String::contains 2023-01-15 01:00:20 +00:00
Timothy Flynn
bd9b65e82f AK: Add String::is_one_of for variadic string comparison 2023-01-15 01:00:20 +00:00
Timothy Flynn
9db9b2f9be AK: Add a somewhat naive implementation of String::reverse
This will reverse the String's code points (i.e. not just its bytes),
but is not aware of grapheme clusters.
2023-01-15 01:00:20 +00:00
Andrew Kaster
f5d253dcfa Everywhere: Fully qualify IsLvalueReference in TRY() macros
If USING_AK_GLOBALLY is not defined, the name IsLvalueReference might
not be available in the global namespace. Follow the pattern established
in LibTest to fully qualify AK types in macros to avoid this problem.
2023-01-15 00:56:31 +00:00
Lucas CHOLLET
9a7accddb7 AK: Add an optional starting offset to CircularBuffer::offset_of
This parameter allows to start searching after an offset. For example,
to resume a search.

It is unfortunately a breaking change in API so this patch also modifies
one user and one test.
2023-01-14 16:20:30 -07:00
Lucas CHOLLET
34922c0cc0 AK: Default move operators for CircularBuffer
The previously defined operator was swap-based. With the defaulted
implementation, both integers are now copied, but it doesn't matter as
only the `ByteBuffer` allocates memory (i.e. non-null integers values
won't affect the destruction).
2023-01-14 16:15:31 -07:00
Ben Wiederhake
79b9dd6248 AK+Tests: Make CaseInsensitiveStringViewTraits work with HashMap again 2023-01-14 15:43:27 -07:00
Tim Schumacher
7526f9a8b7 AK: Remove CircularDuplexStream 2023-01-14 12:05:52 -05:00
MacDue
2366265c53 AK: Add StringBuilder::try_join()
This is a failable version of StringBuilder::join().
2023-01-14 12:37:00 +01:00
Tim Schumacher
d717a08003 AK: Add CircularBuffer::read_with_seekback 2023-01-13 17:34:45 -07:00
Timothy Flynn
afc0e461e1 AK+Everywhere: Disallow returning a reference from a fallible expression
This will silently make a copy. Rather than masking this behavior, let's
explicitly disallow it.
2023-01-13 18:50:47 -05:00
MacDue
9a120d7243 AK: Add support for "debug only" formatters
These are formatters that can only be used with debug print
functions, such as dbgln(). Currently this is limited to
Formatter<ErrorOr<T>>. With this you can still debug log ErrorOr
values (good for debugging), but trying to use them in any
String::formatted() call will fail (which prevents .to_string()
errors with the new failable strings being ignored).

You make a formatter debug only by adding a constexpr method like:
static constexpr bool is_debug_only() { return true; }
2023-01-13 21:09:26 +00:00
MacDue
92cea3216f AK: Don't inherit Formatter<ErrorOr<T>> for Formatter<IPv6Address> 2023-01-13 21:09:26 +00:00
MacDue
d5152c49a1 AK: Don't inherit Formatter<ErrorOr<T>> for Formatter<IPv4Address> 2023-01-13 21:09:26 +00:00
MacDue
514224c015 AK: Fix ignored .to_string() errors in IPv6Address 2023-01-12 23:29:57 +00:00
MacDue
35e1e12360 AK: Fix ignored .to_string() errors in IPv4Address 2023-01-12 23:29:57 +00:00
Timothy Flynn
1d4f287582 AK: Implement FlyString for the new String class
This implements a FlyString that will de-duplicate String instances. The
FlyString will store the raw encoded data of the String instance: If the
String is a short string, FlyString holds the String::ShortString bytes;
otherwise FlyString holds a pointer to the Detail::StringData.

FlyString itself does not know about String's storage or how to refcount
its Detail::StringData. It defers to String to implement these details.
2023-01-12 11:23:58 +01:00
Arda Cinar
283187afc5 AK+LibWeb: Move decode forgiving base64 under Web::Infra namespace
Since the forgiving base64 is part of the web infra standard
2023-01-10 17:54:01 +00:00
Arda Cinar
4ab2954210 AK: Expose Base64 tables from Base64.h
This change is necessary to move the forgiving base64 decoder to LibWeb
2023-01-10 17:54:01 +00:00
MacDue
668204041b AK: Add Span::first()
The missing sibling to Span::last()!
2023-01-10 10:25:58 +01:00