Commit Graph

306 Commits

Author SHA1 Message Date
Andreas Kling
9f7c11710f printf: Treat %g as %f for now. 2019-06-18 09:46:39 +02:00
Andreas Kling
aa3df518e7 AK: Rename JsonObject::to_string() and pals to serialized().
And the variant that serializes into a StringBuilder is called serialize().
2019-06-18 09:37:47 +02:00
Andreas Kling
15fa4f1c55 AK: ScopeGuard.h needs StdLibExtras.h 2019-06-18 09:31:14 +02:00
Andreas Kling
4ee39d6292 AK: Override StringImpl's operator delete to silence valgrind. 2019-06-18 09:26:36 +02:00
Andreas Kling
92cda74724 AK: Fix leak in JsonValue::operator=(JsonValue&&).
Amusingly I introduced this leak while explaining that this type of leak is
a common bug, and saying I'm used to looking for it. :^)
2019-06-18 09:22:19 +02:00
Andreas Kling
4147394dcb AK: Add JsonValue(const char*).
This should obviously become a string, but if we don't have it, constructing
from a string literal ends up creating a boolean value.
2019-06-18 09:11:31 +02:00
Andreas Kling
1a761ea4fd AK: Add JsonValue(unsigned) ctor and as_string(). 2019-06-18 08:55:58 +02:00
Andreas Kling
114768562a AK: Including <AK/kstdio.h> should pull in <stdio.h> etc on host builds. 2019-06-18 08:53:26 +02:00
Andreas Kling
28a4963242 AK: Make ASSERT_NOT_REACHED() work nicely in host builds. 2019-06-18 08:52:21 +02:00
Andreas Kling
ee347effac AK: Use a single StringBuilder throughout JSON serialization. 2019-06-17 21:36:54 +02:00
Andreas Kling
04a8fc9bd7 AK: Add some classes for JSON encoding.
This patch adds JsonValue, JsonObject and JsonArray. You can use them to
build up a JsonObject and then serialize it to a string via to_string().

This patch only implements encoding, no decoding yet.
2019-06-17 19:47:35 +02:00
Andreas Kling
01d1aee922 AK: Make RetainPtr and Retained more friendly towards const pointers.
Also add operator T&'s to Retained since it's nice to be able to pass them
to a function that takes a T&.
2019-06-15 18:45:44 +02:00
Andreas Kling
bfaa74f076 AK/Tests: Test Queue<String> with large number of elements. 2019-06-15 10:39:19 +02:00
Andreas Kling
c699d9d79d AK: Add a simple Queue<T> class.
The underlying data structure is a singly-linked list of Vector<T>.
We never shift any of the vector contents around, but we batch the memory
allocations into 1000-element segments.
2019-06-15 10:35:35 +02:00
Andreas Kling
9443957c14 PaintBrush: Speed up the bucket tool with smarter use of Vector.
Put together a pretty well-performing queue using a Vector and an offset.
By using the new Vector::shift_left(int) instead of Vector::take_first()
we can avoid shifting the vector contents every time and instead only
do it every so often.

Maybe this could be generalized into a separate class, I'm not sure if it's
the best algorithm though, it's just what I came up with right now. :^)
2019-06-14 21:50:28 +02:00
Andreas Kling
a12751695e AK/Tests: Add a simple EXPECT_EQ macro and use it for the String test. 2019-06-14 17:52:51 +02:00
Andreas Kling
3557f277f6 AK/Tests: Add some macros for testing. 2019-06-14 17:38:17 +02:00
Andreas Kling
0589ef2886 AK/Tests: Add a couple more String tests. 2019-06-14 07:40:36 +02:00
Andreas Kling
255c7562ba AK: Massage it into building on my host system without breaking Serenity. 2019-06-14 06:43:56 +02:00
Andreas Kling
b7cca76ca2 AK: Add an extremely primitive unit test for String.
This builds for the host system rather than for Serenity.
We need to improve on it a *lot*, but at least it's a place to start.
2019-06-14 06:42:21 +02:00
Sergey Bugaev
1a697f70db AK: Add more StringView utilities for making substrings.
These two allow making a new substring view starting from,
or starting after, an existing substring view.

Also make use of one of them in the kernel.
2019-06-14 06:24:02 +02:00
Sergey Bugaev
3e326de8fa AK: Fix nullptr dereference in String::matches().
In case cp and mp were never set, we should not try
to use them.
2019-06-14 06:24:02 +02:00
Sergey Bugaev
e585ed48b0 AK: Fix String::matches() with non-null-terminated StringViews.
StringView character buffer is not guaranteed to be null-terminated;
in particular it will not be null-terminated when making a substring.
This means it is not correct to check whether we've reached the end
of a StringView by comparing the next character to null; instead, we
need to do an explicit length (or pointer) comparison.
2019-06-14 06:24:02 +02:00
Conrad Pankoff
f7dce4765c AK: Add find_first_{set,unset} and grow methods to Bitmap 2019-06-12 15:38:17 +02:00
Andreas Kling
e673bb921e AK: Delete the Badge copy and move constructors. 2019-06-11 23:47:51 -07:00
Andreas Kling
cdb44be703 StringView: Store a StringImpl* rather than a String*. 2019-06-08 23:55:13 +02:00
Andreas Kling
6a51093ab1 AK: Add String::operator==(const char*).
Without this function, comparing a String to a const char* will instantiate
a temporary String which is obviously not great.

Also add some missing null checks to StringView::operator==(const char*).
2019-06-08 18:32:09 +02:00
Andreas Kling
de65c960e9 Kernel: Tweak some String&& => const String&.
String&& is just not very practical. Also return const String& when the
returned string is a member variable. The call site is free to make a copy
if he wants, but otherwise we can avoid the retain count churn.
2019-06-07 20:58:12 +02:00
Andreas Kling
de9edb0169 StringView: operator==(const char*) needs to stop when the view ends.
We were comparing past the end of the view, which was clearly not correct.
2019-06-07 19:22:58 +02:00
Andreas Kling
a0bde822ee AK: Add IterationDecision.h. 2019-06-07 17:14:16 +02:00
Andreas Kling
39d1a9ae66 Meta: Tweak .clang-format to not wrap braces after enums. 2019-06-07 17:13:23 +02:00
Andreas Kling
9145917bf0 ELF: Run clang-format on everything. 2019-06-07 17:12:30 +02:00
Andreas Kling
e42c3b4fd7 Kernel: Rename LinearAddress => VirtualAddress. 2019-06-07 12:56:50 +02:00
Andreas Kling
b34b084619 AK: Run clang-format on everything. 2019-06-07 11:46:22 +02:00
Andreas Kling
7ad8790d80 LibGUI: Run clang-format on everything. 2019-06-07 11:46:02 +02:00
Andreas Kling
98eeb8f22d AK: Rename printf.cpp to PrintfImplementation.h. 2019-06-07 11:41:11 +02:00
Andreas Kling
69a6ce90df AK: Add a ScopeGuard helper that invokes a callback when destroyed.
This is useful when you want to ensure some little thing happens when you
exit a certain scope.

This patch makes use of it in LibC's netdb code to make sure we close the
connection to the LookupServer.
2019-06-07 09:19:15 +02:00
Andreas Kling
29a9430246 AK: Make timeval_add() and timeval_sub() take references. 2019-06-06 18:02:28 +02:00
Conrad Pankoff
419e886497 AK: Add String::starts_with to match String::ends_with 2019-06-04 04:58:35 -07:00
Conrad Pankoff
042895317d AK: Add AKString::split_limit to split strings with a limit
This is a small change to the existing split() functionality to support
the case of splitting a string and stopping at a certain number of
tokens. This is useful for parsing e.g. key/value pairs, where the value
may contain the delimiter you're splitting on.
2019-06-04 10:16:45 +02:00
Andreas Kling
ccc6e69a29 LibC: Implement popen() and pclose().
I feel reasonably confident that I might have gotten these right. :^)
2019-06-03 21:17:58 +02:00
Robin Burchell
1024dfa81a StringViewize a bunch of things -- mostly LibGUI 2019-06-03 20:27:05 +02:00
Robin Burchell
f9ba7adae2 StringView: Make construction of String from a StringView containing a String cheaper
... at the cost of an additional pointer per view.
2019-06-03 20:27:05 +02:00
Robin Burchell
7bce096afd Take StringView in more places
We should work towards a pattern where we take StringView as function
arguments, and store String as member, to push the String construction
to the last possible moment.
2019-06-02 12:55:51 +02:00
Robin Burchell
b55b6cd7fc AK: Add implicit String -> StringView conversion
And tidy up existing view() users.
2019-06-02 12:55:51 +02:00
Andreas Kling
e24f18dd83 AK: Add a comment to String about the relationship with StringImpl. 2019-06-02 08:37:01 +02:00
Andreas Kling
b8e705da0e LibCore: CObjects without is<T> specialization shouldn't LARP as others. 2019-06-01 14:11:31 +02:00
Christopher Dumas
6a4cb25557 Terminal: Settings windows can be opened multiple times 2019-06-01 00:07:45 +02:00
Christopher Dumas
f8a02d4733 Terminal: Audible vs Visible beep option 2019-06-01 00:07:45 +02:00
Andreas Kling
3a1d5fa112 ELFLoader: Fix typo in segment naming.
Executable segments now get an "x" character in their region name.
2019-05-30 16:23:48 +02:00