Commit Graph

928 Commits

Author SHA1 Message Date
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