Commit graph

3028 commits

Author SHA1 Message Date
Andreas Kling 7ac7a73758 Revert "AK: Disallow constness laundering in RefPtr and NonnullRefPtr"
This reverts commit 3c7a0ef1ac.

This broke Jakt, which will need some adjustments to its code generation
before we can commit to being this strict.
2023-02-21 09:22:18 +01:00
Andreas Kling 3c7a0ef1ac AK: Disallow constness laundering in RefPtr and NonnullRefPtr
Until now, it was possible to assign a RP<T const> or NNRP<T const>
to RP<T> or NNRP<T>. This meant that the constness of the T was lost.

We had a lot of code that relied on this sloppiness, and by the time
you see this commit, I hopefully found and fixed all of it. :^)
2023-02-21 00:54:04 +01:00
Andreas Kling e08c55dd8d AK: Make String const-correct internally 2023-02-21 00:54:04 +01:00
Andreas Kling a56dfd5c77 AK: Make Deprecated{Fly,}String and StringImpl const-correct 2023-02-21 00:54:04 +01:00
Andreas Kling b2b942b4ec AK: Stop NonnullPtrVector from making accessed elements const 2023-02-21 00:54:04 +01:00
nipos 5b147f29ab AK/StackInfo: Add support for NetBSD 2023-02-20 18:44:36 +01:00
Andrew Kaster a2ef168d75 AK: Allow zero-valued signed size types in format strings 2023-02-19 13:49:07 +01:00
nipos c42e949f5b AK/StackInfo: Add support for OpenBSD pthreads 2023-02-19 11:44:45 +01:00
Sam Atkins b5eb2ee478 AK: Make FlyString(String) constructor implicit
This stops us needing a lot of ugly `FlyString { ... }` wrappers. THis
is the behavior that `DeprecatedFlyString(DeprecatedString)` has so it
should be fine.
2023-02-19 00:51:16 +01:00
Lucas CHOLLET 856d0202f2 LibGfx: Rename JPGLoader to JPEGLoader
The patch also contains modifications on several classes, functions or
files that are related to the `JPGLoader`.

Renaming include:
 - JPGLoader{.h, .cpp}
 - JPGImageDecoderPlugin
 - JPGLoadingContext
 - JPG_DEBUG
 - decode_jpg
 - FuzzJPGLoader.cpp
 - Few string literals or texts
2023-02-18 23:56:24 +01:00
Nico Weber a30e364f1a AK: Fix printing of negative FixedPoint values
Fixes #17514 by comparing to 0 before truncating the fractional part.
2023-02-18 19:34:10 +01:00
Andreas Kling d0697d350d AK: Fix 64-bit alignment issue in shared-superstring substrings
Thanks to Timothy Flynn for the test!

Fixes #17141
2023-02-18 09:12:46 -05:00
Jelle Raaijmakers 4cd3a84c4b AK: Remove unused rehash_for_collision 2023-02-17 22:29:51 -07:00
Jelle Raaijmakers c08d137fcd AK: Reimplement HashTable with smart linear probing
Instead of rehashing on collisions, we use Robin Hood hashing: a simple
linear probe where we keep track of the distance between the bucket and
its ideal position. On insertion, we allow a new bucket to "steal" the
position of "rich" buckets (those near their ideal position) and move
them further down.

On removal, we shift buckets back up into the freed slot, decrementing
their distance while doing so.

This behavior automatically optimizes the number of required probes for
any value, and removes the need for periodic rehashing (except when
expanding the capacity).
2023-02-17 22:29:51 -07:00
Jelle Raaijmakers bc76cba7c2 AK: Remove unused HashTable.h include from StringImpl 2023-02-17 22:29:51 -07:00
Ali Mohammad Pur 9c61fed37c AK: Add an input() accessor to GenericLexer
It's sometimes useful to get the input from the lexer instead of wiring
it all the way down to where it's needed.
2023-02-18 06:55:46 +03:30
Jelle Raaijmakers f4342c9118 AK: Add AK::SIMD::exp_approximate
This approximation tries to generate values within 0.1% of their actual
expected value. Microbenchmarks indicate that this iterative SIMD
version can be up to 60x faster than `AK::SIMD::exp`.
2023-02-18 01:45:00 +01:00
kleines Filmröllchen d00a6ca11f AK+LibWeb: Implement Variant equality operator
And make use of it for CSS StyleValues.
2023-02-17 16:22:56 +00:00
Sam Atkins 1453ac79e7 AK: Add StringBuilder::to_fly_string() 2023-02-15 12:48:26 -05:00
Sam Atkins a35fa553dd AK: Let FlyStrings be assigned from Strings 2023-02-15 12:48:26 -05:00
Sam Atkins abc01cc9fe AK+Tests+LibWeb: Make URL::complete_url() take a StringView
All it does is pass this to `URLParser::parse()` which takes a
StringView, so we might as well take one here too.
2023-02-15 12:48:26 -05:00
Ali Mohammad Pur 2a276c86d4 Shell: Start implementing a POSIX-compliant parser
The parser is still very much a work-in-progress, but it can currently
parse most of the basic bits, the only *completely* unimplemented things
in the parser are:
- heredocs (io_here)
- alias expansion
- arithmetic expansion

There are a whole suite of bugs, and syntax highlighting is unreliable
at best.
For now, this is not attached anywhere, a future commit will enable it
for /bin/sh or a `Shell --posix` invocation.
2023-02-13 23:00:15 +03:30
Tim Schumacher 43f98ac6e1 Everywhere: Remove the AK:: qualifier from Stream usages 2023-02-13 00:50:07 +00:00
Tim Schumacher 874c7bba28 LibCore: Remove Stream.h 2023-02-13 00:50:07 +00:00
Ollrogge 361df6eff8 AK: Add conversion functions for packed DOS time format
This also adjusts the FATFS code to use the new functions and removes
the now redundant old conversion functions.
2023-02-12 13:13:15 -07:00
Kenneth Myhra 9d13537fc7 AK: Add function 'shallow_clone()' to HashMap
This makes a shallow clone of the HashMap, the items temselves are not
cloned in any way.
2023-02-12 00:18:09 +00:00
Nico Weber 0c4bbf5be3 AK: Move try_make_ref_counted() to NonnullRefPtr.h 2023-02-11 08:53:00 -05:00
Nico Weber 3c842d9d76 AK: Move try_make() to NonnullOwnPtr.h 2023-02-11 08:53:00 -05:00
Nico Weber ed198ee6ae AK: Move adopt_nonnull_ref_or_enomem() to NonnullRefPtr.h
Rewrite the implementation to not depend on OwnPtr.h.

No intended behavior change.
2023-02-11 10:36:48 +01:00
Nico Weber ca6090889a AK: Move adopt_nonnull_own_or_enomem() to NonnullOwnPtr.h
Rewrite the implementation to not depend on OwnPtr.h.

No intended behavior change.
2023-02-11 10:36:48 +01:00
MacDue c0b7ff3c4c AK: Always initialize vector capacity to inline_capacity
This ensures constructors that take a span or an initializer_list
don't allocate when there's already enough inline storage.
(Previously these constructors always allocated)
2023-02-11 00:03:14 +01:00
Luke Wilde d9d556fbab AK: Allow Vector<ByteBuffer>::contains_slow to accept (Readonly)Bytes
This is done by providing Traits<ByteBuffer>::equals functions for
(Readonly)Bytes, as the base GenericTraits<T>::equals is unable to
convert the ByteBuffer to (Readonly)Bytes to then use Span::operator==

This allows us to check if a Vector<ByteBuffer> contains a
(Readonly)Bytes without having to making a copy of it into a ByteBuffer
first. The initial use of this is in LibWeb with CORS-preflight, where
we check the split contents of the Access-Control headers with
Fetch::Infrastructure::Request::method() and static StringViews
such as "*"sv.bytes().
2023-02-10 22:18:19 +00:00
Tim Schumacher 332b253a47 AK: Provide is_errno for Kernel Errors
It wouldn't make much sense on its own (as the Kernel only has errno
Errors), but it's an easy fix for not having to ifdef away every single
usage of `is_errno` in code that is shared between Userland and Kernel.
2023-02-10 12:15:02 +01:00
Tim Schumacher be25602d44 AK: Allow explicitly copying Errors in the Kernel 2023-02-10 12:15:02 +01:00
Tim Schumacher cc8874b5aa AK: Fix a linting issue in Error.h
I'm not sure why, but `clang-format` gets unhappy if we touch the
adjacent line.
2023-02-10 12:15:02 +01:00
Liav A 048fb2c204 AK: Disallow returning of string literals for errors in kernel code
This code should not be used in the kernel - we should always propagate
proper errno codes in case we need to return those to userland so it
could decode it in a reasonable way.
2023-02-10 09:14:20 +00:00
Liav A ab27fce86f AK: Add a new method to propagate errno while printing errors in Kernel
This new method is meant to be used in both userspace and kernel code.
The idea is to allow printing of a verbose message and then returning an
errno code which is the proper mechanism for kernel code because we
should almost always assume that such error will be propagated back to
userspace in some way, so the userspace code could reasonably decode it.

For userspace code however, this new method is meant to be a simple
wrapper for Error::from_string_view, because for most invocations, it's
much more useful to have a verbose & literal error than a errno code, so
we simply ignore that errno code completely in such context.
2023-02-10 09:14:20 +00:00
Timothy Flynn 8eb3d79129 AK: Disallow implicitly copying Error and ErrorOr instances
In the rare cases that a copy is actually needed, the Error::copy
factory will suffice.
2023-02-10 09:08:52 +00:00
Timothy Flynn 604d5f5bca AK+Everywhere: Do not implicitly copy variables in TRY macros
For example, consider cases where we want to propagate errors only in
specific instances:

    auto result = read_data(); // something like ErrorOr<ByteBuffer>
    if (result.is_error() && result.error().code() != EINTR)
        continue;
    auto bytes = TRY(result);

The TRY invocation will currently copy the byte buffer when the
expression (in this case, just a local variable) is stored into
_temporary_result.

This patch binds the expression to a reference to prevent such copies.
In less trival invocations (such as TRY(some_function()), this will
incur only temporary lifetime extensions, i.e. no functional change.
2023-02-10 09:08:52 +00:00
Timothy Flynn 4a916cd379 Everywhere: Remove needless copies of Error / ErrorOr instances
Either take the underlying objects with release_* methods or move() the
instances around.
2023-02-10 09:08:52 +00:00
Timothy Flynn 945f392392 AK: Add an explicit Error factory to copy an existing error
As of now, there is a default copy constructor on Error. A future commit
will make this non-public to prevent implicit copies, so to prepare for
that, this adds a factory for the few cases where a copy is really
needed.
2023-02-10 09:08:52 +00:00
Tim Schumacher e8d5e938de AK: Remove the deprecated Stream implementation :^) 2023-02-08 19:18:26 +00:00
MacDue 63b11030f0 Everywhere: Use ReadonlySpan<T> instead of Span<T const> 2023-02-08 19:15:45 +00:00
MacDue 8483efb399 AK: Add ReadonlySpan<T> as an alias for Span<T const>
This is a little clearer than Span<T const> where it looks like it's
the T not the underlying array that's const.
2023-02-08 19:15:45 +00:00
Tim Schumacher 220fbcaa7e AK: Remove the fallible constructor from FixedMemoryStream 2023-02-08 17:44:32 +00:00
Tim Schumacher 8b2f23d016 AK: Remove the fallible constructor from LittleEndianOutputBitStream 2023-02-08 17:44:32 +00:00
Tim Schumacher 0fee97916b AK: Remove the fallbile constructor from BigEndianOutputBitStream 2023-02-08 17:44:32 +00:00
Tim Schumacher 261d62438f AK: Remove the fallible constructor from LittleEndianInputBitStream 2023-02-08 17:44:32 +00:00
Tim Schumacher fa09152e23 AK: Remove the fallible constructor from BigEndianInputBitStream 2023-02-08 17:44:32 +00:00
Sam Atkins fe7b08dad7 Kernel: Protect Process::m_name with a spinlock
This also lets us remove the `get_process_name` and `set_process_name`
syscalls from the big lock. :^)
2023-02-06 20:36:53 +01:00
Andrew Kaster 012aaecccf AK: Always define ak_assertion_failed, even when NDEBUG is false
Just because we may compile serenity with or without NDEBUG doesn't
mean that consuming projects or Ports will share the setting.

Always define the custom assertion function so that we don't have to
keep the same debug settings between all projects.
2023-02-05 09:46:51 -07:00
MacDue d81a72ed78 AK: Allow propagating errors from StringView::for_each_split_view() 2023-02-05 16:40:51 +01:00
Andreas Kling ed3420dc10 AK: Make WeakPtr<T>::value() return NonnullRefPtr<T>
This API is only used by Jakt to implement weak reference unwrapping.
By making it return a NonnullRefPtr, it can be assigned to anything
that accepts a NonnullRefPtr, unlike the previous T* return type (since
that can also be null).
2023-02-05 15:38:19 +01:00
Lucas CHOLLET 79006c03b4 AK: Check the return type in IsCallableWithArguments
Template argument are checked to ensure that the `Out` type is equal or
convertible to the type returned by the invokee.

Compilation now fails on:
`Function<void()> f = []() -> int { return 0; };`

But this is allowed:
`Function<ErrorOr<int>()> f = []() -> int { return 0; };`
2023-02-04 18:47:02 -07:00
Lucas CHOLLET d9f632fee7 AK: Move the definition of IsCallableWithArguments to Function.h
It will allow us to use definitions from both `StdLibExtraDetails.h` and
`Concepts.h` at the same time.
2023-02-04 18:47:02 -07:00
Lucas CHOLLET e538fa203e AK: Add the ConvertibleTo concept 2023-02-04 18:47:02 -07:00
Tim Schumacher 47531a42a9 AK: Make LEB128 decoding work with read_value 2023-02-04 18:41:27 -07:00
Tim Schumacher 787f4d639a AK: Port LEB128 to the new AK::Stream 2023-02-04 18:41:27 -07:00
Tim Schumacher 31f59855b4 AK: Don't restore the stream offset when failing to read an LEB128
Pretty much no other read function does this, and getting rid of the
typename template parameter for the stream makes the transition to the
new AK::Stream a bit easier.
2023-02-04 18:41:27 -07:00
Tim Schumacher 371c51f934 AK: Make SeekableStream::truncate() take a size_t
Similar to the return values earlier, a signed value doesn't really make
sense here. Relying on the much more standard `size_t` makes it easier
to use Stream in all contexts.
2023-02-04 18:41:27 -07:00
nipos c31b547fae AK: Use constexpr instead of consteval on OpenBSD 2023-02-04 16:11:54 -07:00
Staubfinger da1023fcc5 AK: Add thresholds to quickselect_inline and Statistics::Median
I did a bit of Profiling and made the quickselect and median algorithms
use the best of option for the respective input size.
2023-02-03 19:04:15 +01:00
Staubfinger 6b9344e86c AK: Use AK:quickselect_inline to compute AK::Statistics::median
Quick select is an algorithm that is able to find the median
of a Vector without fully sorting it.
This replaces the old very naive implementation
for `AK::Statistics::median()` with `AK::quickselect_inline`
2023-02-03 19:04:15 +01:00
Staubfinger 607441de56 AK: Implement the quick select algorithm as AK::quickselect_inplace
This adds the quick select algorithm that finds
the kth smallest element for any collection.
Whilst doing so it also partially sorts the collection.
I have also included the option to use different pivoting functions
including median of medians which makes the quick select have
a truely linear time complexity at the costs of enormous overhead,
so this that only really useful for really large datasets.
The same was chosen to reflect the fact that it modifies
the collection in place during the selection process.
2023-02-03 19:04:15 +01:00
Sam Atkins 7d0529b89c AK: Remove JsonObject::get_deprecated() and ::get_ptr() :^) 2023-02-03 07:19:52 -05:00
Timothy Flynn 2af7447dfd AK: Define HashMap::take to find and remove a value from the map 2023-02-02 19:14:00 +00:00
Timothy Flynn f31bd190b0 AK: Ensure string types are actually considered hash-compatible
The AnyString concept is currently broken because it checks whether a
StringView is constructible from a type T. The StringView constructors,
however, only accept constant rvalue references - i.e. `T const&`.

This also adds a test to ensure this continues to work.
2023-02-02 19:14:00 +00:00
Timothy Flynn 2f67f2ba3d AK: Return a constant reference from HashMap's constant get() override
We cannot return a mutable reference from a constant function.
2023-02-02 19:14:00 +00:00
Ben Wiederhake e147d0b572 AK: Fix all quadratic-time append-loops over ByteBuffer 2023-01-31 16:58:25 +01:00
Iman Seyed 0ebcc99e12 AK: Remove unused network ordered 'address' variable 2023-01-31 12:42:49 +01:00
Tim Schumacher 093cf428a3 AK: Move memory streams from LibCore 2023-01-29 19:16:44 -07:00
Tim Schumacher 22f0d04f43 AK: Provide a fallback definition for std::nothrow 2023-01-29 19:16:44 -07:00
Tim Schumacher 2470dd3bb5 AK: Move bit streams from LibCore 2023-01-29 19:16:44 -07:00
Tim Schumacher 94f139c111 AK: Move buffered streams from LibCore 2023-01-29 19:16:44 -07:00
Tim Schumacher 8464da1439 AK: Move Stream and SeekableStream from LibCore
`Stream` will be qualified as `AK::Stream` until we remove the
`Core::Stream` namespace. `IODevice` now reuses the `SeekMode` that is
defined by `SeekableStream`, since defining its own would require us to
qualify it with `AK::SeekMode` everywhere.
2023-01-29 19:16:44 -07:00
Tim Schumacher 5f2ea31816 AK: Move Handle from LibCore and name it MaybeOwned
The new name should make it abundantly clear what it does.
2023-01-29 19:16:44 -07:00
Tim Schumacher 5fa590de71 AK: Remove Buffered 2023-01-29 19:16:44 -07:00
Tim Schumacher ae64b68717 AK: Deprecate the old AK::Stream
This also removes a few cases where the respective header wasn't
actually required to be included.
2023-01-29 19:16:44 -07:00
Andreas Kling 230cb3b0cb AK: Add DeprecatedString::from_utf8()
This will be used in Jakt to help transition off of DeprecatedString.
2023-01-29 23:41:42 +01:00
Andreas Kling 6b497b8710 AK: Add two helpers to DeprecatedStringCodePointIterator 2023-01-29 23:41:42 +01:00
Linus Groh 9c08bb9555 AK: Remove try_ prefix from FixedArray creation functions 2023-01-28 22:41:36 +01:00
Timothy Flynn e96c64cdb4 AK: Add support for the new FlyString to StringView 2023-01-28 15:24:55 +00:00
Timothy Flynn b61f8cd130 AK: Delete the StringView move-assignment operator for various types 2023-01-28 15:24:55 +00:00
Andreas Kling 2dc657c77e AK: Add DeprecatedStringCodePointIterator
This is a safe iterator over the underlying code points. It will be used
in Jakt to assist in the migration away from DeprecatedString.
2023-01-28 09:50:52 +01:00
Timothy Flynn c59268d15b AK: Add String::trim 2023-01-28 00:13:46 +00:00
Timothy Flynn cccaa94767 AK: Add String::join 2023-01-28 00:13:46 +00:00
Timothy Flynn 79aaa2fe0f AK: Allow the kernel to have access to StringBuilder::to_string
This is mostly to prevent String.h from acquiring ifdef-soup. In any
case, it's fine for the kernel to see this symbol as it is fallible.
2023-01-28 00:13:46 +00:00
Linus Groh 6e7459322d AK: Remove StringBuilder::build() in favor of to_deprecated_string()
Having an alias function that only wraps another one is silly, and
keeping the more obvious name should flush out more uses of deprecated
strings.
No behavior change.
2023-01-27 20:38:49 +00:00
Sam Atkins 09a22ddb2a AK: Remove unimplemented methods 2023-01-27 20:33:18 +00:00
Sam Atkins df07c5be3a AK: Remove unused DateTimeLexer class 2023-01-27 20:33:18 +00:00
Timothy Flynn c35b1371a3 AK: Add an overload of String::find_byte_offset for StringView 2023-01-27 18:00:17 +00:00
Timothy Flynn 76fd5f2756 AK: Add convenience substring wrappers to String to exclude a length
These overloads exist on other string classes and are used throughout
the code base.
2023-01-24 16:23:50 -05:00
Timothy Flynn 427b82065c AK: Add a method to create a String with a repeated code point 2023-01-24 16:23:50 -05:00
Timothy Flynn d50724956e AK: Add a method to find the byte offset of a code point 2023-01-24 16:23:50 -05:00
Timothy Flynn 5e44b93af2 AK: Remove [[nodiscard]] attribute from String methods returning ErrorOr 2023-01-24 16:23:50 -05:00
Nico Weber 44de4d163b AK: Make HashMap::try_ensure work with a fallible construction callback
Co-authored-by: Timothy Flynn <trflynn89@pm.me>
2023-01-24 14:45:27 +00:00
Nico Weber 8b5b767465 AK: Print leading zeroes after the dot for FixedPoint numbers
As a nearby comment says, "This is a terrible approximation".
This doesn't make things less terrible, but it does make things
more correct in the given framework of terribleness.

Fixes #17156.
2023-01-24 13:24:21 +01:00
Nico Weber 9c5820326d AK: Make FixedPoint::create_raw public and constexpr 2023-01-23 18:09:23 +00:00
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
Timothy Flynn 6fcc1c7426 AK+LibUnicode: Provide Unicode-aware String case transformations
Since AK can't refer to LibUnicode directly, the strategy here is that
if you need case transformations, you can link LibUnicode and receive
them. If you try to use either of these methods without linking it, then
you'll of course get a linker error (note we don't do any fallbacks to
e.g. ASCII case transformations). If you don't need these methods, you
don't have to link LibUnicode.
2023-01-09 19:23:46 -07:00
Timothy Flynn f3db548a3d AK+Everywhere: Rename FlyString to DeprecatedFlyString
DeprecatedFlyString relies heavily on DeprecatedString's StringImpl, so
let's rename it to A) match the name of DeprecatedString, B) write a new
FlyString class that is tied to String.
2023-01-09 23:00:24 +00:00