Commit graph

1285 commits

Author SHA1 Message Date
Andreas Kling 9dafbc82ff AK: Add JsonObject::remove() 2020-09-06 16:09:09 +02:00
asynts 4c317a94c7 LibCompress: Simplify logic in deflate implementation. 2020-09-06 12:54:45 +02:00
asynts 6de63782c7 Streams: Consistent behaviour when reading from stream with error.
The streaming operator doesn't short-circuit, consider the following
snippet:

    void foo(InputStream& stream) {
        int a, b;
        stream >> a >> b;
    }

If the first read fails, the second is called regardless. It should be
well defined what happens in this case: nothing.
2020-09-06 12:54:45 +02:00
asynts 359fcf348f AK: Add Buffered<T> which wraps a stream, adding input buffering. 2020-09-06 12:54:45 +02:00
asynts b011f87d34 AK: Add log stream operator overload for Span. 2020-09-06 12:54:45 +02:00
Muhammad Zahalqa fad0c8e712
AK: Make all DoublyLinkedList search methods use Traits<T>::equals (#3404) 2020-09-05 14:17:14 +02:00
asynts 7efd2a6d59 AK: Add OutputMemoryStream class. 2020-09-01 17:25:26 +02:00
asynts 3a2658951b AK: Add DuplexMemoryStream::copy_into_contiguous_buffer. 2020-09-01 17:25:26 +02:00
asynts b68a873067 AK: Move memory streams into their own header. 2020-09-01 17:25:26 +02:00
asynts f9516a99bf AK: Remove history from DuplexMemoryStream.
That feature was really only useful for Compress::DeflateDecompressor
but that is now using CircularDuplexBuffer instead.
2020-09-01 17:25:26 +02:00
asynts 9ce4475907 Streams: Distinguish recoverable and fatal errors. 2020-09-01 17:25:26 +02:00
AnotherTest 441807f96d AK: Add is_any_of(StringView) to GenericLexer 2020-08-31 23:05:58 +02:00
Nico Weber f2135d7d00 AK: Make %llx work in printf 2020-08-30 17:37:20 +02:00
Sergey Bugaev be6cce5530 AK: Add String::copy_characters_to_buffer()
This is a strcpy()-like method with actually sane semantics:

* It accepts a non-empty buffer along with its size in bytes.
* It copies as much of the string as fits into the buffer.
* It always null-terminates the result.
* It returns, as a non-discardable boolean, whether the whole string has been
copied.

Intended usage looks like this:

bool fits = string.copy_characters_to_buffer(buffer, sizeof(buffer));

and then either

if (!fits) {
    fprintf(stderr, "The name does not fit!!11");
    return nullptr;
}

or, if you're sure the buffer is large enough,

// I'm totally sure it fits because [reasons go here].
ASSERT(fits);

or if you're feeling extremely adventurous,

(void)fits;

but don't do that, please.
2020-08-30 17:35:27 +02:00
Tom 80560d1be3 AK: Fix FixedArray zero bytes allocations 2020-08-30 17:30:48 +02:00
Tom f5bc7dbfda AK: Fix ByteBuffer zero bytes allocations 2020-08-30 17:30:48 +02:00
Andreas Kling 8ecc3d31d1 AK: Add missing declaration in StringImpl.cpp 2020-08-30 10:48:08 +02:00
asynts e7df17d146 AK: Stream operators for String for generic streams.
I think this should really be a member function of InputStream instead,
but I don't want to include String in Stream.h. This will do for now...
2020-08-30 09:56:10 +02:00
asynts deb85c47b5 AK: Add Optional::emplace method. 2020-08-30 09:56:10 +02:00
Ben Wiederhake 1ef26e0c09 AK: Provide off-switch for dbg() output 2020-08-30 09:43:49 +02:00
Ben Wiederhake 184b454e2f AK: Unbreak building with extra debug macros 2020-08-30 09:43:49 +02:00
asynts e68b158a52 AK: Don't swap endianness when writing endian wrappers to stream. 2020-08-29 17:44:34 +02:00
asynts 1b3169f405 AK: Define MakeUnsigned and MakeSigned for char.
For some weird reason the C++ standard considers char, signed char and
unsigned char *three* different types. On the other hand int is just an
alias for signed int, meaning that int, signed int and unsigned int are
just *two* different types.

https://stackoverflow.com/a/32856568/8746648
2020-08-27 15:49:01 +02:00
Ben Wiederhake 9f7ec33180 Meta: Force semi-colon after MAKE_AK_NONXXXABLE()
Before, we had about these occurrence counts:
COPY: 13 without, 33 with
MOVE: 12 without, 28 with

Clearly, 'with' was the preferred way. However, this introduced double-semicolons
all over the place, and caused some warnings to trigger.

This patch *forces* the usage of a semi-colon when calling the macro,
by removing the semi-colon within the macro. (And thus also gets rid
of the double-semicolon.)
2020-08-27 10:12:04 +02:00
Ben Wiederhake e5807d17b2 Tests: Document 'missing' tests
It's up for grabs. Anyone wants to write them? :)
2020-08-27 10:12:04 +02:00
asynts 71cbf72e8a AK: Add InputBitStream class. 2020-08-26 21:07:53 +02:00
asynts a82fead38a AK: Add CircularDuplexStream class. 2020-08-26 21:07:53 +02:00
asynts 8e08d9f70a AK: Fix the signature of binary_search. 2020-08-26 21:07:53 +02:00
asynts 18b3de7555 AK: Add stream operators for Optional. 2020-08-26 21:07:53 +02:00
Nico Weber 1ab8939077 AK+LibC+LibCore: Have fewer implementations of day_of_week
The implementation in LibC did a timestamp->day-of-week conversion
which looks like a valuable thing to have. But we only need it in
time_to_tm, where we already computed year/month/day -- so let's
consolidate on the day_of_week function in DateTime (which is
getting extracted to AK).
2020-08-26 08:52:07 +02:00
Nico Weber 2236385e1f AK+LibC+LibCore: Add a days_in_year function 2020-08-26 08:52:07 +02:00
Nico Weber a7a18b478e AK+LibC+LibCore: Have fewer implementations of days_in_month 2020-08-26 08:52:07 +02:00
Nico Weber c85e679e2d AK+LibCore+Kernel: Have fewer implementations of day_of_year
The JS tests pointed out that the implementation in DateTime
had an off-by-one in the month when doing the leap year check,
so this change fixes that bug.
2020-08-26 08:52:07 +02:00
Nico Weber 9b17082899 AK+LibC+Kernel: Have fewer implementations of year_to_days_in_epoch
I believe the implementation in RTC.cpp had an off-by-one
in the year passed to is_leap_year(). If that's true, then this
fixes that too.
2020-08-26 08:52:07 +02:00
Nico Weber 84ed257959 AK+LibC+LibCore+Kernel: Have fewer implementations of is_leap_year 2020-08-26 08:52:07 +02:00
Ben Wiederhake 0e27a6e39e AK: Demonstrate and fix Checked
Specifically:
- post-increment actually implemented pre-increment
- helper-templates that provided operator{+,-,*,/}() couldn't possibly work,
  because the interface of add (etc) were incompatible (not taking a Checked<>,
  and returning void)
2020-08-26 00:55:13 +02:00
asynts 10c6f062b3 AK: Add Endian.h header to replace NetworkOrdered.h. 2020-08-25 16:22:14 +02:00
Paul Scharnofske 88a2c245e5
AK: TestSuite: Define assert macros with do { } while(0). (#3292)
Consider the following scenario:

    if(condition)
        FOO();
    else
        bar();

Suppose FOO is defined as follows:

    #define FOO() { bar(); baz(); }

Then it expands to the following:

    if(condition)
        // Syntax error, we are not allowed to put a semicolon at the end.
        { bar(); baz(); };
    else
        bar();

If we define FOO as follows:

    #define FOO() do { bar(); baz(); } while(false)

Then it expands to the following:

    if(condition)
        do { bar(); baz(); } while(false);
    else
        bar();

Which is correct.
2020-08-25 16:20:52 +02:00
Tom d89582880e Kernel: Switch singletons to use new Singleton class
MemoryManager cannot use the Singleton class because
MemoryManager::initialize is called before the global constructors
are run. That caused the Singleton to be re-initialized, causing
it to create another MemoryManager instance.

Fixes #3226
2020-08-25 09:48:48 +02:00
AnotherTest 5b5ba91335 AK: Add URL::create_with_data() to create data URLs 2020-08-24 18:21:33 +02:00
Ben Wiederhake 2adc3c61a2 AK: Document that String{,Impl} contains NUL-terminator 2020-08-24 00:45:03 +02:00
Ben Wiederhake 01dabb65f2 AK: Remove redundant declaration in String.cpp
It already includes AK/Memory.h, which includes Kernel/StdLib.h, which.
declares strstr().
2020-08-24 00:45:03 +02:00
Ben Wiederhake 0944f56181 AK: Fix human_readable_size corner cases
In particular: consistent rounding and extreme values.

Before, rounding was something like 'away from 0.999...', which led to
surprising corner cases in which the value was rounded up.

Now, rounding is always 'down'.
This even works for 0xffffffff, and also for 0xffffffffffffffffULL on 64-bit.
2020-08-23 11:24:55 +02:00
Ben Wiederhake f697d35fb1 AK: Add tests for human_readable_size() 2020-08-23 11:24:55 +02:00
Ben Wiederhake 53abc626c2 AK: Print RHS and LHS in EXPECT_EQ if we can
This makes error messages more useful during debugging.

Old:

    START Running test compare_views
    FAIL: ../AK/Tests/TestStringView.cpp:59: EXPECT_EQ(view1, "foobar") failed

New:

    START Running test compare_views
    FAIL: ../AK/Tests/TestStringView.cpp:59: EXPECT_EQ(view1, "foobar") failed: LHS="foo", RHS="foobar"
2020-08-23 11:24:55 +02:00
Peter Elliott c68537271c AK: Add operator== to AK::Optional
The semantics:
- two Optionals are equal if they are both None
- two Optionals are equal if they are both Some, and their values are
  operator==
2020-08-23 01:05:22 +02:00
Ben Wiederhake 2a2630edc9 Meta: Fix wrong 'using namespace X' usages
Apart from causing All AK:: and Crypto:: symbols being suddenly visible even though
they might not be supposed to be, the style guide also says this is wrong:

https://github.com/SerenityOS/serenity/blob/master/Documentation/CodingStyle.md#using-statements
2020-08-23 00:53:16 +02:00
Ben Wiederhake 04f494fc44 AK: Prefer snprintf over sprintf 2020-08-22 20:55:10 +02:00
Ben Wiederhake 0240baa42d AK+Kernel: Support snprintf
In contrast to sprintf, which might overflow the given buffer.

I feel bad about the code duplication, but that is a pre-existing issue.
2020-08-22 20:55:10 +02:00
asynts c2be38e50f AK: TestSuite: Terminate when ASSERT_NOT_REACHED is called.
Previously, it would just print something with 'FAIL' to stderr which
would be picked up by CTest. However, some code assumes that
ASSERT_NOT_REACHED() doesn't return, for example:

    bool foo(int value) {
        switch(value) {
        case 0:
            return true;
        case 1:
            return false;
        default:
            ASSERT_NOT_REACHED();
        }

        // warning: control reaches end of non-void function
    }
2020-08-22 20:52:19 +02:00
Ben Wiederhake b4f26c2b31 AK: Prevent confusing silent misuse of Userspace<T> 2020-08-22 17:18:14 +02:00
Ben Wiederhake a6314f2ce6 AK: Fix description of DistinctNumeric around operator bool 2020-08-22 17:18:14 +02:00
Ben Wiederhake 4acdb60ba3 AK: Prevent confusing silent misuse of ByteBuffer
Thankfully, this hasn't happened in any other code yet, but it happened
while I was trying something out. Using '==' on two ByteBuffers to check
whether they're equal seemed straight-forward, so I ran into the trap.
2020-08-22 17:18:14 +02:00
Ben Wiederhake 901ed9b85d AK: Demonstrate surprising ByteBuffer behavior
This seems to be because ByteBuffer implements 'operator bool', and C++
considers bool to be an integer type. Thus, when trying to find a way to
evaluate '==', it attempts integer promotion, which in turn finds 'operator bool'.

This explains why all non-empty buffers seem to be equal, but different from the
empty one. Also, why comparison seems to be implemented.
2020-08-22 17:18:14 +02:00
Andreas Kling 8925ad3fa0 Revert "Kernel: Move Singleton class to AK"
This reverts commit f0906250a1.
2020-08-22 16:34:49 +02:00
Andreas Kling 68580d5a8d Revert "AK: Get rid of make_singleton function"
This reverts commit 5a98e329d1.
2020-08-22 16:34:14 +02:00
asynts d2121ab7c7 AK: Make some tweaks in TestSuite.h. 2020-08-22 10:46:56 +02:00
asynts 207b9774e0 AK: Remove <chrono> requirement from TestSuite.h. 2020-08-22 10:46:56 +02:00
asynts 20a7d2c61b AK: Remove exceptions from TestSuite.h.
Serenity is build with -fno-exceptions, this is an effort to make
TestSuite.h useable in the userland.
2020-08-22 10:46:56 +02:00
asynts d5999c3811 AK: Move include <AK/TestSuite.h> to the top.
clang-format automatically sorts include statements that are in a
'block'. Adding a whitespace prevents this. It is crutial that
<AK/TestSuite.h> is included first because it redefines some macros.
2020-08-22 10:46:56 +02:00
asynts 39b464dcfd AK: Remove test case that doesn't test anything.
Currently, there is no way to check that an assert fails. This test
passes regardless of the assert. (AK/HashTable.h:93)
2020-08-22 10:46:56 +02:00
Tom 5a98e329d1 AK: Get rid of make_singleton function
Just default the InitFunction template argument.
2020-08-22 10:46:24 +02:00
Tom f0906250a1 Kernel: Move Singleton class to AK 2020-08-22 10:46:24 +02:00
Nico Weber 064159d215 LibWeb: Use GenericLexer in WrapperGenerator 2020-08-21 16:01:48 +02:00
AnotherTest 9cc996b1e5 AK: Add Stream::offset_of(ReadonlyBytes) 2020-08-21 16:00:42 +02:00
AnotherTest 67f7f6840d AK+LibC+Kernel: Move the implementation of memmem to AK 2020-08-21 16:00:42 +02:00
asynts 8bbb7e25e6 LibCompress: Turn the DEFLATE implementation into a stream.
Previously, the implementation would produce one Vector<u8> which
would contain the whole decompressed data. That can be a lot and
even exhaust memory.

With these changes it is still necessary to store the whole input data
in one piece (I am working on this next,) but the output can be read
block by block. (That's not optimal either because blocks can be
arbitrarily large, but it's good for now.)
2020-08-20 16:28:31 +02:00
asynts 30abadcff9 AK: Add DuplexMemoryStream class.
This class is similar to BufferStream because it is possible to both
read and write to it. However, it differs in the following ways:

  - DuplexMemoryStream keeps a history of 64KiB and discards the rest,
    BufferStream always keeps everything around.

  - DuplexMemoryStream tracks reading and writing seperately, the
    following is valid:

        DuplexMemoryStream stream;
        stream << 42;
        int value;
        stream >> value;

    For BufferStream it would read:

        BufferStream stream;
        stream << 42;
        int value;
        stream.seek(0);
        stream >> value;

In the future I would like to replace all usages of BufferStream with
InputMemoryStream, OutputMemoryStream (doesn't exist yet) and
DuplexMemoryStream. For now I just add DuplexMemoryStream though.
2020-08-20 16:28:31 +02:00
asynts a15556638d AK: Remove unnecessary FIXME comments from Stream.h. 2020-08-20 16:28:31 +02:00
asynts bc332aca33 AK: Rename error() to has_error() for streams. 2020-08-20 16:28:31 +02:00
asynts 6d15318560 AK: Remove fatal() from InputStream.
Fatal errors can not be handeled and lead to an assertion error when the
stream is destroyed. It makes no sense to delay the assertion failure,
instead of setting m_fatal, an assertion should be done directly.
2020-08-20 16:28:31 +02:00
asynts 31e7f435cb AK: Rename TestMemoryStream.cpp to TestStream.cpp. 2020-08-20 16:28:31 +02:00
asynts ebce4ead40 AK: Add StringView(ReadonlyBytes) constructor. 2020-08-20 16:28:31 +02:00
asynts b1fc8d2b38 AK: Span: Fix signature of copy_to() and copy_trimmed_to().
Two changes were made

 1. copy_to() and copy_trimmed_to() now return how many bytes were
    copied.

 2. The argument was changed to Span<typename RemoveConst<T>::Type>
    because the following would not work:

        ReadonlyBytes bytes0;
        Bytes bytes1;

        // Won't work because this calls Span<const u8>::copy_to(Span<u8>)
        // but the method was defined as Span<const u8>::copy_to(Span<const u8>)
        bytes0.copy_to(bytes1);
2020-08-20 16:28:31 +02:00
asynts df21487794 AK: Span: Allow slicing with zero length.
Previously, the following would not work:

    Bytes{}.slice(0);

because it was asserted that `start < size()`.
2020-08-20 16:28:31 +02:00
Brian Gianforcaro ff0c7da75d AK: Add SFINAE fallback for AK C++ concepts use, for Coverity compiler
The Coverity compiler doesn't support C++2a yet, and thus doesn't
even recognize concept keywords. To allow serenity to be built and
analyzed on such compilers, add a fallback underdef to perform
the same template restriction based on AK::EnableIf<..> meta
programming.

Note: Coverity does seem to (annoyingly) define __cpp_concepts, even
though it doesn't support them, so we need to further check for
__COVERITY__ explicitly.
2020-08-17 09:17:57 +02:00
asynts aef6f00195 AK: Always call memmove in Span instead of memcpy.
https://github.com/SerenityOS/serenity/pull/3166#discussion_r471031704
2020-08-17 00:00:14 +02:00
Nico Weber f47dbb6a58 AK: Use IEC prefixes in human_readable_format
Windows uses "KB", "MB", "GB" as powers of two.
macOS uses "kB", "MB", "GB" as powers of ten.

"k", "M", "G" are standard SI prefixes that normally refer to powers of
ten.

The IEC introduced "KiB", "MiB", "GiB" to unambiguously refer to
powers of two. It admittedly hasn't caught on that much, but it
does have the advantage that it's unabigious what it means.
So let's use it for user-visible sizes in SerenityOS.

(Linux does all of the above in different places, depending on app and
toolkit.)
2020-08-16 16:33:28 +02:00
Nico Weber aa97166739 Everywhere: Consolidate human_readable_size() implementations
Let's use the one in AK/NumberFormat.h everywhere.

It has slightly different behavior than some of the copies this
removes, but it's probably nice to have uniform human readable
size outputs across the system.
2020-08-16 16:33:28 +02:00
Nico Weber 430b265cd4 AK: Rename KB, MB, GB to KiB, MiB, GiB
The SI prefixes "k", "M", "G" mean "10^3", "10^6", "10^9".
The IEC prefixes "Ki", "Mi", "Gi" mean "2^10", "2^20", "2^30".

Let's use the correct name, at least in code.

Only changes the name of the constants, no other behavior change.
2020-08-16 16:33:28 +02:00
Muhammad Zahalqa a68650a7b4
AK: HashTable add a constructor that allows preallocation of capacity + Use in CppLexer. (#3147)
1. Add general utility to get array number of elements.
2. Add Needed API to AK::HashTable
3. Refactor CppLexer initialization
2020-08-16 11:04:00 +02:00
asynts fff581cd72 AK: Rename span() to bytes() when appropriate.
I originally defined the bytes() method for the String class, because it
made it obvious that it's a span of bytes instead of span of characters.

This commit makes this more consistent by defining a bytes() method when
the type of the span is known to be u8.

Additionaly, the cast operator to Bytes is overloaded for ByteBuffer and
such.
2020-08-15 21:21:18 +02:00
asynts 525d51bbb5 AK: Add slice() overload to Span. 2020-08-15 21:21:18 +02:00
asynts 36080c5964 AK: Add fill() method to Span. 2020-08-15 21:21:18 +02:00
asynts 78849bbb48 AK: Add copy_to() and move_to() methods to AK::Span. 2020-08-15 21:21:18 +02:00
asynts 8e7dfebf11 AK: Add bytes() method to FixedArray. 2020-08-15 21:21:18 +02:00
asynts d4fe63d2ce AK: Remove incorrect static assert in Span.h.
This assertion was added to prevent accitentally using stuff like
Span<int*> instead of Span<int>. But there can be spans of pointers.
2020-08-15 21:21:18 +02:00
Itamar 310063fed8 Meta: Install source files at /usr/src/serenity 2020-08-15 15:06:35 +02:00
Andreas Kling 6b8807be6e AK: Fix obvious bad vector access in IPv4Address::from_string()
Fixes #3137.
2020-08-14 15:10:58 +02:00
Andreas Kling 28c68fb241 AK: Fix bad vector access in two-part IPv4 address parsing 2020-08-13 21:12:59 +02:00
Panagiotis Vasilopoulos dcfc54d767 AK: Add initial support for obscure IPv4 address notations
This change aims to add support for obscure IPv4 address notations, such as 1.1 (which should be equal to 1.0.0.1), or the hypothetical address 1 (which is equal to 0.0.0.1). This is supported on other platforms as well, such as Linux, Windows, *BSD, and even Haiku.
2020-08-13 19:02:47 +02:00
Ben Wiederhake 5fe6ca75ca AK: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, add forgotten
header to Base64.cpp, which would cause an issue later when we enable -Wmissing-declarations.
2020-08-12 20:40:59 +02:00
AnotherTest caedd05bd8 AK: Span<T>::operator=(const T&) => Span<T>::operator=(const Span<T>&) 2020-08-11 21:37:10 +02:00
Linus Groh 62ea2c5437 AK: Add test case for duplicate JsonObject keys 2020-08-10 14:48:45 +02:00
Linus Groh f649009887 AK: Don't keep equal JsonObject keys in the order vector twice
Fixes #3069.
2020-08-10 14:48:45 +02:00
Ben Wiederhake cc6d5242d1 AK: Implement and test DistinctNumeric class
This template class allows for easy generation of incompatible numeric types.
This is useful whenever code has to handle heterogenous data (like meters and
seconds) but the underlying data types are compatible (like int and int).

The motivation comes from the Kernel's inconsistent use of pid_t for process and
thread IDs even though the ID spaces are incompatible, and translating forth/back
is nontrivial.

Other uses could be units (as described above), or incompatible index systems.
A popular use in real life is image manipulation, when there are multiple
coordinate systems.
2020-08-10 11:51:45 +02:00
Ben Wiederhake 54c6886108 AK: TestSuite's main should return 0 2020-08-10 11:51:45 +02:00
Nico Weber 6613a4cb8c disasm: Insert symbol names in disassembly stream
The symbol name insertion scheme is different from objdump -d's.
Compare the output on Build/Userland/id:

* disasm:

        ...
        _start (08048305-0804836b):
        08048305  push ebp
        ...
        08048366  call 0x0000df56

        0804836b  o16 nop
        0804836d  o16 nop
        0804836f  nop

        (deregister_tm_clones (08048370-08048370))

        08048370  mov eax, 0x080643e0
        ...
        _ZN2AK8Utf8ViewC1ERKNS_6StringE (0805d9b2-0805d9b7):
        _ZN2AK8Utf8ViewC2ERKNS_6StringE (0805d9b2-0805d9b7):
        0805d9b2  jmp 0x00014ff2

        0805d9b7  nop

* objdump -d:

        08048305 <_start>:
         8048305:	55                   	push   %ebp
        ...
         8048366:	e8 9b dc 00 00       	call   8056006 <exit>
         804836b:	66 90                	xchg   %ax,%ax
         804836d:	66 90                	xchg   %ax,%ax
         804836f:	90                   	nop

        08048370 <deregister_tm_clones>:
         8048370:	b8 e0 43 06 08       	mov    $0x80643e0,%eax
        ...
        0805d9b2 <_ZN2AK8Utf8ViewC1ERKNS_6StringE>:
         805d9b2:	e9 eb f6 ff ff       	jmp    805d0a2 <_ZN2AK10StringViewC1ERKNS_6StringE>
         805d9b7:	90                   	nop

Differences:

1. disasm can show multiple symbols that cover the same instructions.
   I've only seen this happen for C1/C2 (and D1/D2) ctor/dtor pairs,
   but it could conceivably happen with ICF as well.

2. disasm separates instructions that do not belong to a symbol with
   a newline, so that nop padding isn't shown as part of a function
   when it technically isn't.

3. disasm shows symbols that are skipped (due to having size 0)
   in parenthesis, separated from preceding and following instructions.
2020-08-10 11:48:10 +02:00
Nico Weber 0586924bbd LibELF+Lagom: Work towards getting LibELF in Lagom
Mostly -Wformat fixes, some of which pointed out real (if benign) bugs.
2020-08-09 21:12:54 +02:00
Benoît Lormeau 7b356c33cb
AK: Add a GenericLexer and extend the JsonParser with it (#2696) 2020-08-09 11:34:26 +02:00
Brian Gianforcaro 9f685ac30a AK: Add static_ptr_cast support for the Userspace<T> pointer type
When using Userspace<T> there are certain syscalls where being able
to cast between types is needed. You should be able to easily cast
away the Userspace<T> wrapper, but it's perfectly safe to be able to
cast the internal type that is being wrapped.
2020-08-07 16:18:36 +02:00
asynts 3fb62e8c63 AK: Remove unnecessary clang-format off comments. 2020-08-07 15:57:51 +02:00
Andreas Kling 3055f73d48 AK+Kernel+LibC: Add vdbgprintf()
This is like dbgprintf() except it takes a va_list instead of ...
2020-08-06 13:36:06 +02:00
Andreas Kling 0d6597df2b AK: Remove Stream::operator bool()
This was only used in one place, and that caused a bug, so I'm removing
this for now since there are no more uses.
2020-08-06 11:37:33 +02:00
asynts b3d1a05261 Refactor: Expose const_cast by removing ByteBuffer::warp(const void*, size_t)
This function did a const_cast internally which made the call side look
"safe". This method is removed completely and call sites are replaced
with ByteBuffer::wrap(const_cast<void*>(data), size) which makes the
behaviour obvious.
2020-08-06 10:33:16 +02:00
asynts ac9f6fd1f8 LibDebug: Use InputMemoryStream instead of BufferStream.
This removes another call to ByteBuffer::wrap(const void*, size_t).
2020-08-06 10:33:16 +02:00
asynts 5bfa7749c3 AK: Add InputStream abstraction and InputMemoryStream implementation. 2020-08-06 10:33:16 +02:00
asynts 75cde94c6a AK: Add String constructor from ReadonlyBytes. 2020-08-06 10:33:16 +02:00
asynts 42b4880653 AK: Rename Tests/Span.cpp to Tests/TestSpan.cpp. 2020-08-06 10:33:16 +02:00
asynts 5f7427ba4b AK: Add Integral and FloatingPoint concepts. 2020-08-06 10:33:16 +02:00
asynts 05abfc0e1f AK: Rename MakeUnsigned::type to MakeUnsigned::Type.
Also renames MakeSigned::type to MakeSigned::Type.
2020-08-06 10:33:16 +02:00
Muhammad Zahalqa 9495eeb075
AK: Make min/max behave like the STL for equivalent inputs (#2976)
min(a, b) now returns a if both are equivalent.
max(a, b) now returns a if both are equivalent.
2020-08-06 09:58:45 +02:00
Andreas Kling 3ba0164ce0 AK: Fix broken symlink used by JSON test 2020-08-06 00:05:52 +02:00
Nico Weber ce95628b7f Unicode: Try s/codepoint/code_point/g again
This time, without trailing 's'. Ran:

    git grep -l 'codepoint' | xargs sed -ie 's/codepoint/code_point/g
2020-08-05 22:33:42 +02:00
Nico Weber 19ac1f6368 Revert "Unicode: s/codepoint/code_point/g"
This reverts commit ea9ac3155d.
It replaced "codepoint" with "code_points", not "code_point".
2020-08-05 22:33:42 +02:00
Brian Gianforcaro a7ea7b3a66 AK: Decorate AK::Result<V, E> with [[nodiscard]] 2020-08-05 17:29:44 +02:00
Brian Gianforcaro adb83d3adc AK: Decorate AK::TriState with [[nodiscard]]
TriState is another type of return code, it's value should always be
observed.
2020-08-05 17:29:01 +02:00
Brian Gianforcaro 3319803bd9 AK: Decorate atomic compare exchange operations with [[nodiscard]]
All CAS operations should always check return values, so they are
robust to failure in the event of conflict in parallel operation.
2020-08-05 17:28:44 +02:00
Brian Gianforcaro f34fcdedef AK: Decorate AK::NonnullOwnPtr::leak_ptr() with [[nodiscard]] 2020-08-05 16:12:00 +02:00
Brian Gianforcaro fa625a2690 AK: Decorate AK::OwnPtr::leak_ptr() with [[nodiscard]]
We should always leak to an observed variable, otherwise
it's an actual leak. This is similar to AK::RefPtr::leak_ref()
which is also marked as [[nodiscard]].
2020-08-05 16:12:00 +02:00
Brian Gianforcaro a7a7e6245f AK: Decorate Optional<T> with [[nodisard]] 2020-08-05 12:27:15 +02:00
Brian Gianforcaro 125eab998f AK: Fix StringUtils tests to actually observe return value.
Noticed this while playing around with making Optional<T>
nodiscard.
2020-08-05 12:18:54 +02:00
Brian Gianforcaro 88092376f3 AK: Use AK relative include style for InlineLinkedList.h
This is the style that seems to be used in the rest of AK.
2020-08-05 12:13:50 +02:00
Brian Gianforcaro efb0805d8e AK: Add SinglyLinkedListWithCount<T>, a singulary linked list with count
There are use cases where a linked list is useful but it's also worth
the overhead to maintain a count so you can quickly answer queries of
the size of the list.
2020-08-05 09:34:22 +02:00
Andreas Kling 000ef0ec3d Revert "AK: Let the compiler provide the default new and delete operators"
This reverts commit 45b05e9734.

I forgot about the Toolchain build again. :^(
2020-08-04 21:16:07 +02:00
Andreas Kling 45b05e9734 AK: Let the compiler provide the default new and delete operators
...except in kernelspace.
2020-08-04 19:05:48 +02:00
Uma Sankar e799da1fb6
AK: Remove an unused variable in the Span test (#2985) 2020-08-04 10:26:45 +02:00
Andreas Kling ea9ac3155d Unicode: s/codepoint/code_point/g
Unicode calls them "code points" so let's follow their style.
2020-08-03 19:06:41 +02:00
Tom df52061cdb AK: Add more time convenience functions and comparison operators 2020-08-03 18:23:00 +02:00
Tom df3c8267d4 AK: Fix adding timeval/timespec
tv_usec and tv_nsec should always be less than one second.
2020-08-03 15:59:11 +02:00
Muhammad Zahalqa 615ba0f368
AK: Fix overflow and mixed-signedness issues in binary_search() (#2961) 2020-08-02 21:10:35 +02:00
Brian Gianforcaro 6e54d0c072 AK: Remove relative_paths test from TestLexicalPath
This test appears to be testing functionality that doesn't
exist. Just remove it.

Closes old bug #2388

CC @bugaevc
2020-08-02 20:48:37 +02:00
Andreas Kling 9bcf0b70cb AK: Hack Userspace<T> to not break Qt Creator syntax highlighting
This is a very cheesy patch and I don't like it, but as Qt Creator does
not grok C++20 concepts yet, this makes it possible to still use syntax
highlighting.

We'll remove this hack the moment it stops being a problem. Note that
it doesn't actually affect the build since we use GCC, not Clang.
2020-08-02 11:01:00 +02:00
Emanuele Torre 6c1ba09fbd AK: In Userspace.h, #if defined(KERNEL) => #ifdef KERNEL 2020-08-01 10:44:42 +02:00
Emanuele Torre 5bf994d2d9 AK: Use C++20 concepts to only allow Userspace wrappers of pointers
It was a bit odd that you could create a Userspace<int> and that
Userspace<int>::ptr() returned an int instead of an int*.

Let's use C++20 concepts to only allow creating Userspace objects with
pointer types. :^)
2020-08-01 10:44:42 +02:00
AnotherTest 6131417904 AK: Make MappedFile store why it is invalid
This makes AK::MappedFile save the errno either open() or mmap() failed
with.
2020-08-01 08:39:26 +02:00
AnotherTest fd64be02e0 AK: Add StringView::contains(StringView) 2020-08-01 08:39:26 +02:00
Andreas Kling 628b3badfb Kernel+AK: Add and use Userspace<T>::unsafe_userspace_ptr()
Since we already have the type information in the Userspace template,
it was a bit silly to cast manually everywhere. Just add a sufficiently
scary-sounding getter for a typed pointer.

Thanks @alimpfard for pointing out that I was being silly with tossing
out the type.

In the future we may want to make this API non-public as well.
2020-07-31 20:56:48 +02:00
Andreas Kling e39a410546 AK: Add Userspace<T>, a wrapper for userspace pointers
This will be used in the kernel to wrap pointers into userspace memory
without convenient direct access. The idea is to use the compiler to
enforce that we don't dereference userspace pointers.
2020-07-31 16:26:44 +02:00
Ben Wiederhake 17248ab6fe AK: On failed mmap, don't claim that there's a readable page 2020-07-31 11:34:06 +02:00
AnotherTest 681bb1fb23 AK: Add (more) tests for String(View)::split*
This patchset adds some tests for String(View)::split*, hopefully
documenting their behaviour in some cases.
2020-07-30 18:47:41 +02:00
Andreas Kling ebd2e7d9f5 AK: Tweak String::is_one_of() and FlyString::is_one_of()
Switch the comparisons from "other == *this" to "*this == other".
2020-07-28 18:55:47 +02:00
Peter Elliott e57a432118 AK: Make String::substring() return non-null for 0-length strings
This also makes String::split() give non-null strings when keep_empty is
true.
2020-07-28 17:07:22 +02:00
asynts abe925e4b0 AK: Change the signature of AK::encode_base64() to use Span. 2020-07-27 19:58:09 +02:00
asynts 5fa0fdb219 AK: Rename Span::subspan() to Span::slice(). 2020-07-27 19:58:09 +02:00
asynts 8d2dba022e AK: Add offset() method to Span. 2020-07-27 19:58:09 +02:00
asynts a922abd9d7 AK: Add span() / bytes() methods to container types. 2020-07-27 19:58:09 +02:00
asynts c42450786c AK: Add implicit conversion from nullptr to Span. 2020-07-27 19:58:09 +02:00
asynts 2b57891e07 AK: Add constructors to Bytes and ReadonlyBytes that take void pointers. 2020-07-27 19:58:09 +02:00
asynts 7036a9b6f7 AK: Define conversion from Span<T> to Span<const T> correctly.
I accidently wrote `Span<RemoveConst<T>>` when I meant
`Span<RemoveConst<T>::Type>`.

Changing that wouldn't be enough though, this constructor can only be
defined if T is not const, otherwise it would redefine the copy
constructor.  This can be avoided by overloading the cast operator.
2020-07-27 19:58:09 +02:00
Andreas Kling 1366557094 AK+LibC: Always use REP MOVSB/STOSB for memcpy()/memset()
There's no great advantage to using MMX instructions here on modern
processors, since REP MOVSB/STOSB are optimized in microcode anyway
and tend to run much faster than MMX/SSE/AVX variants.

This also makes it much easier to implement high-level emulation of
memcpy/memset in UserspaceEmulator once we get there. :^)
2020-07-27 15:54:39 +02:00
Andreas Kling ce2c5b375c AK: Add global is<T>() and downcast<T>()
Let's unify the is<T>/to<T> implementations that currently exist in
separate versions in LibCore and LibWeb.
2020-07-26 17:51:00 +02:00
asynts 707d92db61 Refactor: Change the AK::binary_search signature to use AK::Span. 2020-07-26 16:49:06 +02:00
asynts ac9c2bc492 AK: Implement Span which represents a contiguous sequence of objects.
This makes it possible to pass one object rather than pointer and length
individually.
2020-07-26 16:49:06 +02:00
Ben Wiederhake 8c14219fb1 AK: Fix print_double
Fixes #2776.

This fixes, among other things, JSON serialization.

The underlying bug was that 'print_double' defined fraction_length
as a function argument with a default value, whereas
printf_internal *always* provided a value, even if nothing was read.
The 'use 6 by default' logic has been moved to printf_internal instead.
2020-07-25 12:32:55 +02:00
Andreas Kling cd4bc81dbb AK: Add a couple more helper templates to StdLibExtras 2020-07-24 02:38:17 +02:00
Nico Weber 3f45e9ab1e Lagom: Add LibGemini, LibGfx
They are dependencies of LibWeb and might be useful for
running test-web on GitHub actions one day.
2020-07-23 23:02:28 +02:00
Nico Weber 5ba8aba197 AK: Make encode_base64 take a ByteBuffer and return a String
That makes the interface symmetric with decode_base64 and it's
what all current callers want (except for one, which is buggy).
2020-07-22 19:22:00 +02:00
Luke a5ecb9bd6b AK: Add case insensitive version of starts_with 2020-07-21 01:08:32 +02:00
Andreas Kling 70cb4491d7 AK: Use "signed char" as the opposite of "unsigned char"
I totally forgot about the C++ basics here. There are three distinct
types: "char", "signed char" and "unsigned char". Whether "char" is
signed or unsigned is implementation specific.
2020-07-18 17:57:40 +02:00
Nico Weber 59596ff816 LexicalPath: Simplify a loop
No behavior change.
2020-07-15 20:16:38 +02:00
Matthew Olsson c831fb17bf LibJS: Add StringIterator 2020-07-13 15:07:29 +02:00
Nico Weber 552789902a AK: Make LexicalPath keep everything before the last dot as title
Previously, TextEditor would put "foo.txt" in the Save As dialog
for files named "foo.bar.txt". Now, it puts "foo.bar.txt" instead.
2020-07-13 15:00:14 +02:00
Nico Weber 97cea9e61c AK: Give String::index_of() an optional second "start" argument 2020-07-13 15:00:14 +02:00
Tom dadd53e4f2 AK: HashTable/HashMap return whether action was performed for set/remove
This allows performing an action based on whether something
was actually added or removed without having to look it up
prior to calling set() or remove().
2020-07-09 21:58:07 +02:00
Andreas Kling ecd4c6718e AK: Fix JsonValue copy constructor behavior for 64-bit values
The fact that JsonValues can contain 64-bit values isn't a JavaScript
compatible behavior in the first place, but as long as we're supporting
this, we should make sure it works correctly.
2020-07-06 18:38:08 +02:00
Andreas Kling 2c4a168404 AK: Remove debug spam in SharedBuffer::create_from_shbuf_id() 2020-07-05 16:36:28 +02:00
Sergey Bugaev 6111cfda73 AK: Make Vector::unstable_remove() return the removed value
...and rename it to unstable_take(), to align with other take...() methods.
2020-07-05 12:26:27 +02:00
Andreas Kling 11c4a28660 Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
Andreas Kling f7577585a6 AK: Add Weakable::revoke_weak_ptrs()
This allows you to clear all the WeakPtrs pointing at a Weakable *now*
instead of waiting until the Weakable is destroyed.
2020-07-04 16:23:52 +02:00
Tom 038dd9f30e AK: Serialize entire log statements
Prior to this, we wrote to the log every time the << operator
was used, which meant that only these parts of the log statement
were serialized. If the thread was preempted, or especially with
multiple CPUs the debug output was hard to decipher. Instead, we
buffer up the log statements. To avoid allocations we'll attempt
to use stack space, which covers most log statements.
2020-07-03 19:32:34 +02:00
Tom 137e1dc7bd AK: Fixes for atomic pointers 2020-07-03 19:32:34 +02:00
Tom 16783bd14d Kernel: Turn Thread::current and Process::current into functions
This allows us to query the current thread and process on a
per processor basis
2020-07-01 12:07:01 +02:00
AnotherTest 7b72001667 Inspector: Expand and show properties in a TreeView
This allows the inspector to show arbitrary json structures.
2020-07-01 11:18:19 +02:00
Andreas Kling 72eb13d8e4 AK: Inline the basics of VectorIterator
Inlining these allows the compiler to optimize out the assertions in
favor of a static range check in many cases.
2020-06-23 19:48:02 +02:00
Nico Weber 9256757b59 AK: Add timespec_add and timespec_sub 2020-06-22 16:00:20 +02:00
LepkoQQ b1c99c1891 AK: Fix JsonParser double encoding multibyte utf-8 chararcters 2020-06-20 17:04:03 +02:00
Tom Lebreux e14c8b2707 AK: Add tests for Base64 decoder 2020-06-18 23:21:41 +02:00
Tom Lebreux 79529ffd47 AK: Add a simple and inefficient Base64 encoder
The test cases are taken from RFC 4648.
2020-06-18 23:21:41 +02:00
Andreas Kling 35329400b8 AK: Implement a slightly better FlyString::operator==(String)
This was showing up in Browser profiles, which is silly, so write a new
version that doesn't create a temporary String object.

There are a whole bunch of these and long-term it would be nice to find
a way to share all the very similar logic instead of duplicating it.
2020-06-16 19:19:30 +02:00
Hüseyin ASLITÜRK df8fd4e8c8 Test: Fix json parse test from unicode string 2020-06-16 13:15:17 +02:00
Hüseyin ASLITÜRK 0aad21fff2 AK: JsonParser, replace char type to u32 for code point 2020-06-16 13:15:17 +02:00
Kevin Meyer e0f4fdc9b4 AK: Assert non-empty Utf32View, when initialized with non-zero length
This was useful in debugging a nullptr dereference, which was happening
through later, but was caused by this inconsistent initialization.
2020-06-15 22:32:18 +02:00
Matthew Olsson e8e728454c AK: JsonParser improvements
- Parsing invalid JSON no longer asserts
    Instead of asserting when coming across malformed JSON,
    JsonParser::parse now returns an Optional<JsonValue>.
- Disallow trailing commas in JSON objects and arrays
- No longer parse 'undefined', as that is a purely JS thing
- No longer allow non-whitespace after anything consumed by the initial
  parse() call. Examples of things that were valid and no longer are:
    - undefineddfz
    - {"foo": 1}abcd
    - [1,2,3]4
- JsonObject.for_each_member now iterates in original insertion order
2020-06-13 12:43:22 +02:00
Andreas Kling fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
Sergey Bugaev f1566ed4c6 AK: Remove useless casts 2020-06-12 16:08:45 +02:00
Sergey Bugaev 3ff651323c AK: Ensure RefCounted types are never copied or moved
Before this, it has been possible to assign a RefCounted object to another
RefCounted object. Hilariosly (or sadly), that copied the refcount among
the other fields, meaning the target value ended up with a wrong refcount.

Ensure this never happens by disallowing copies and moves for RefCounted types.
2020-06-12 16:08:45 +02:00
Sergey Bugaev 0ff3c1c34d AK: Assert refcount doesn't overflow
We don't really have a good way to prevent this kind of overflow,
but let's at least immediately panic in this case.
2020-06-12 16:08:45 +02:00
Sergey Bugaev c80e657dda AK: Switch RefCounted to atomic refcounting
This fixes all sorts of race conditions, primarily in the kernel, where till
now it's been possible to obtain either double free or use-after-free by
exploiting refcounting races.
2020-06-12 16:08:45 +02:00
Sergey Bugaev 583108004c AK: Use unsigned int for refcount
And while fixing all the tests that look at ref_count(),
sneak in a fix for the test suite name.
2020-06-12 16:08:45 +02:00
Sergey Bugaev 0466810638 AK: Ensure we never use OwnPtr<> with RefCounted types 2020-06-12 16:08:45 +02:00
Sergey Bugaev 5624f8d8ee AK: ALWAYS_INLINE most Atomic<T> methods 2020-06-12 16:08:45 +02:00
Sergey Bugaev 4d65466f02 AK: Fix missing ptrdiff_t in non-Serenity builds
We have to include <stddef.h> to get its definition.
2020-06-12 16:08:45 +02:00
Andreas Kling ff6de8a169 AK: URL should urldecode data: URL payloads
Otherwise we can end up with percent-encoded nonsense in base64 data
which does not decode correctly.
2020-06-10 17:45:34 +02:00
Andreas Kling 86eeac86a4 AK: Add basic percent encoder/decoder (urlencode and urldecode) 2020-06-07 21:05:05 +02:00
Andreas Kling 83ee76a53e AK: Add StringView::{begin,end} so we can range-for over StringViews 2020-06-07 21:05:05 +02:00
Andreas Kling ec83555b87 AK: Don't try to complete relative data: URLs 2020-06-07 19:09:03 +02:00
Sergey Bugaev 9e046bcef1 AK: Fix printf("%c", 0)
It was me who has broken this, sorry ;(
2020-06-06 14:42:31 +02:00
Andreas Kling 23dad305e9 AK: Allow default-constructing Utf8View and Utf8CodepointIterator 2020-06-04 21:12:17 +02:00
Andreas Kling d4bbc00901 AK: Add StringBuilder::append_codepoint(u32)
Also, implement append(Utf32View) using it.
2020-06-04 21:12:17 +02:00
Tom 93b9832fac AK: Add atomic free functions
This allows for using atomic operations on any variables,
not only those wrapped in AK::Atomic<T>
2020-06-04 18:15:23 +02:00
Hüseyin ASLITÜRK 8e9776165f AK: JSON, Escape spacial character in string serialization 2020-06-03 21:52:40 +02:00
Andreas Kling f249f07699 AK: Add operator== and hash traits for URL 2020-06-01 21:50:07 +02:00
Sergey Bugaev c3db694d9b AK: Always inline some Checked methods
Once again, we need to hint the compiler that it should inline the function, and
then it is able to eliminate the assertion.
2020-05-31 21:38:50 +02:00
Andreas Kling 4e80f22cc0 AK: Make some StringView constructors constexpr 2020-05-30 17:47:50 +02:00
Andreas Kling 1ef5d609d9 AK+LibC: Add TODO() as an alternative to ASSERT_NOT_REACHED()
I've been using this in the new HTML parser and it makes it much easier
to understand the state of unfinished code branches.

TODO() is for places where it's okay to end up but we need to implement
something there.

ASSERT_NOT_REACHED() is for places where it's not okay to end up, and
something has gone wrong.
2020-05-30 11:31:49 +02:00
Andreas Kling 643464c455 AK: Make {String,FlyString}::is_one_of() const
Also, make the zero-argument variant private since it's not meant to be
called by clients directly.
2020-05-30 11:31:49 +02:00
Marcin Gasperowicz 9a4ee9aa1a Lagom: Adjust AK, LibCore and LibTLS to build on MacOS 2020-05-30 00:36:13 +02:00
Paul Redmond 4d4e578edf Ports: Fix CMake-based ports
The SDL port failed to build because the CMake toolchain filed pointed
to the old root. Now the toolchain file assumes that the Root is in
Build/Root.

Additionally, the AK/ and Kernel/ headers need to be installed in the
root too.
2020-05-29 20:21:10 +02:00
Emanuele Torre 937d0be762 Meta: Add a script check the presence of "#pragma once" in header files
.. and make travis run it.

I renamed check-license-headers.sh to check-style.sh and expanded it so
that it now also checks for the presence of "#pragma once" in .h files.

It also checks the presence of a (single) blank line above and below the
"#pragma once" line.

I also added "#pragma once" to all the files that need it: even the ones
we are not check.
I also added/removed blank lines in order to make the script not fail.

I also ran clang-format on the files I modified.
2020-05-29 07:59:45 +02:00
AnotherTest f9bf2c7e78 AK: Add StringView::split_view() taking a StringView
Since the task of splitting a string via another is pretty common, we
might as well have this overload of split_view() as well.
2020-05-28 11:01:08 +02:00
Andreas Kling 9a113b0229 AK: Add a simple randomness API
This can be used in code that builds on non-Serenity platforms.
2020-05-27 12:25:46 +02:00
Andreas Kling 16accb71a3 AK: Mark some popular String member functions ALWAYS_INLINE
I don't wanna see String::length() in a profile, jeez. :^)
2020-05-26 22:49:06 +02:00
Sergey Bugaev 602c3fdb3a AK: Rename FileSystemPath -> LexicalPath
And move canonicalized_path() to a static method on LexicalPath.

This is to make it clear that FileSystemPath/canonicalized_path() only
perform *lexical* canonicalization.
2020-05-26 14:35:10 +02:00
Brian Gianforcaro 27360f1f20 Build: Fix cmake test runner, so it knows when tests fail
The CMake runner looks at the return code if you don't set
the pattern. Since the AK test suite setup doesn't use return
codes, we were missing test failures.
2020-05-26 13:38:20 +02:00
Brian Gianforcaro 71deafe476 AK: Temporarily disable failing relative_paths tests in FileSystemPath suite
It appears this got broken in a3e4dfdf98.
I filed a tracking bug https://github.com/SerenityOS/serenity/issues/2388
2020-05-26 13:38:20 +02:00
Brian Gianforcaro e5045b62b8 AK: Expand string tests to include ends_with case insensitivity 2020-05-26 13:17:19 +02:00
Brian Gianforcaro 129462cca7 AK: Unify FlyString/StringView::ends_with implementation on StringUtils::ends_with
This creates a unified implementation of ends_with with case sensitivity
across String/StringView/FlyString.
2020-05-26 13:17:19 +02:00
Brian Gianforcaro 332f96e7ca AK: Add case insensitive String::ends_with support
FileSystemPath::has_extension was jumping through hoops and allocating
memory to do a case insensitive comparison needlessly. Extend the
existing String::ends_with method to allow the caller to specify the
case sensitivity required.
2020-05-26 13:17:19 +02:00
Brian Gianforcaro 8e4b858b3f AK: Move String::ends_with implementation to StringUtils
Centralizing so it can be used by other string implementations
2020-05-26 13:17:19 +02:00
Andreas Kling 5e77517e6e AK: Add String::is_one_of(...)
This allows you to compare a string against an arbitrary number of
other strings with a single call.
2020-05-25 19:51:23 +02:00
Andreas Kling dd924b730a Kernel+LibC: Fix various build issues introduced by ssize_t
Now that ssize_t is derived from size_t, we have to
2020-05-23 15:27:33 +02:00
Andreas Kling 8fe4512f8e AK: Fix inconsistent signature for dbgputstr() 2020-05-23 15:25:43 +02:00
Andreas Kling 4177953530 AK: Simplify Types.h a little bit 2020-05-23 15:25:43 +02:00
Andreas Kling e90ecdda48 AK: Add MakeSigned<T> helper template 2020-05-23 15:25:43 +02:00
Andreas Kling 6cefb96e98 AK: Allow NumericLimits.h to compile in a kernel context
We explicitly disallow floating point numbers during kernel compilation
so we have to #ifdef out those parts here.
2020-05-23 15:25:43 +02:00
FalseHonesty b1e4f70173 AK: Fix URL::complete_url behaviour for when a fragment is passed
Previously, passing a fragment string ("#section3") to the complete_url
method would result in a URL that looked like
"file:///home/anon/www/#section3" which was obviously incorrect. Now the
result looks like "file:///home/anon/www/afrag.html#section3".
2020-05-23 11:53:25 +02:00
Sergey Bugaev a3e4dfdf98 AK: Fix .. handling in FileSystemPath
We shouldn't just drop leading ..-s for relative paths. At the same time,
we should handle paths like

    ../foo/../../bar

correctly: the first .. after the foo cancels out the foo, but the second
one should get treated as a leading one and not get dropped.

Note that since this path resolution is purely lexical, it's never going to be
completely correct with respect to symlinks and other filesystem magic. Better
don't use it when dealing with files.
2020-05-22 23:55:35 +02:00
Andreas Kling a1db1e6664 AK: Make JsonValue and JsonObjectSerializer speak int/long/long long
While width-oriented integer types are nicer from the programmer's
perspective, we have to accept that C++ thinks in int/long/long long.
2020-05-22 13:57:23 +02:00
Hüseyin ASLITÜRK 738235574f AK: StringUtils, add "convert_to_uint_from_hex" method
New method to convert hex string unsigned integer.
2020-05-21 01:19:42 +02:00
Andreas Kling b55b26a2bc Revert "AK: Add InitializerList, an implementation of std::initializer_list"
This reverts commit 0a2cab0928.
2020-05-20 16:24:26 +02:00
Andreas Kling bded472ec4 Revert "AK+LibC: Move non-placement new/delete into LibC"
This reverts commit 2c82347393.
2020-05-20 16:24:26 +02:00
Andreas Kling 67cc7d09a2 Revert "AK: Add AtomicRef, for atomically accesing a reference to a varaible"
This reverts commit aff594f1e7.
2020-05-20 16:24:26 +02:00
Andreas Kling 8876bfc3ac Revert "AK: Don't demangle in serenity :("
This reverts commit 4361a50225.
2020-05-20 16:24:26 +02:00
Andreas Kling e10183a6c5 AK: Include Platform.h in RefCounted.h so we have ALWAYS_INLINE
Otherwise Lagom doesn't build on my host machine.
2020-05-20 14:13:39 +02:00
Sergey Bugaev d2b500fbcb AK+Kernel: Help the compiler inline a bunch of trivial methods
If these methods get inlined, the compiler is able to statically eliminate most
of the assertions. Alas, it doesn't realize this, and believes inlining them to
be too expensive. So give it a strong hint that it's not the case.

This *decreases* the kernel binary size.
2020-05-20 14:11:13 +02:00
Andrew Kaster 4361a50225 AK: Don't demangle in serenity :(
In order to remove libstdc++ completely, we need to give up on their
implementation of abi::__cxa_demangle. The demangler logic will actually
have to be quite complex, and included in both the kernel and userspace.

A definite fixme for the future, to parse the mangled names into real
deal names.
2020-05-20 08:37:50 +02:00
Andrew Kaster aff594f1e7 AK: Add AtomicRef, for atomically accesing a reference to a varaible
This is distintly different from Atomic<T*>, because we want to
atomically access a variable that the atomic object itself does not own.
2020-05-20 08:37:50 +02:00
Andrew Kaster 2c82347393 AK+LibC: Move non-placement new/delete into LibC
This allows operator new and operator delete to be available to anyone
that links -lc (everyone) rather than just people that include
kmalloc.h (almost no one).
2020-05-20 08:37:50 +02:00
Andrew Kaster 0a2cab0928 AK: Add InitializerList, an implementation of std::initializer_list
Use the AK version of std::initializer_list in AK::Vector, but only
when in serenity. When building AK for a non-serenity target, the header
<initializer_list> should be always available.
2020-05-20 08:37:50 +02:00
Sergey Bugaev 000a9cad34 AK: Fix Checked::multiplication_would_overflow() signature
The two-argument version doesn't need an extra template parameter.
2020-05-20 08:31:31 +02:00
Andreas Kling 7207276697 AK: Make Utf32View::substring_view() with 0 length not crash
Just make it hand out a zero-length Utf32View :^)
2020-05-18 16:48:54 +02:00
AnotherTest a4e0b585fe AK: Add a way to get the number of valid bytes in a Utf8View 2020-05-18 11:31:43 +02:00
Andreas Kling 86242f9c18 AK: Add StringBuilder::append(Utf32View)
This encodes the incoming UTF-32 sequence as UTF-8.
2020-05-17 22:35:25 +02:00
Andreas Kling 00b5614ce2 AK: Add a very basic Utf32View class
This allows you to wrap a { const u32* codepoints, size_t length } in a
simple object.
2020-05-17 22:35:25 +02:00
Conrad Pankoff b5b08fba92 AK: Make sure URL retains trailing slash if present in complete_url 2020-05-17 16:35:42 +02:00
Andreas Kling 6cde7e4d20 AK: Add Utf8View::length_in_codepoints() 2020-05-17 13:05:39 +02:00
Conrad Pankoff 4214680e76 AK: Set default port in URL to 1965 for gemini protocol 2020-05-17 12:41:38 +02:00
Linus Groh b193670967 AK: Handle "protocol relative URLs" in URL::complete_url() 2020-05-16 21:47:16 +02:00
Linus Groh ad3871b64e AK: Fix URL's operator<<() and use it 2020-05-16 21:47:16 +02:00