Commit graph

21272 commits

Author SHA1 Message Date
Andreas Kling 407d6cd9e4 AK: Rename Utf8CodepointIterator => Utf8CodePointIterator 2021-06-01 09:45:52 +02:00
Max Wipfli 628c7f094f LibGUI+Shell+bt+ls: Use proper APIs for creating file URLs
This patch replaces ad-hoc generation of file URL strings with using
URL::create_with_file_scheme().
2021-06-01 09:28:05 +02:00
Max Wipfli 5caaa52bee AK: Add hostname parameter to URL::create_with_file_scheme()
This adds a hostname parameter as the third parameter to
URL::create_with_file_scheme(). If the hostname is "localhost", it will
be ignored (as per the URL specification).

This can for example be used by ls(1) to create more conforming file
URLs.
2021-06-01 09:28:05 +02:00
Max Wipfli ce80188d6f LibHTTP: Percent encode/decode request URI
This percent encodes/decodes the request URI when creating or parsing
raw HTTP requests. This is necessary because AK::URL now contains
percent decoded data, meaning we have to re-encode it for creating
raw requests.
2021-06-01 09:28:05 +02:00
Max Wipfli c7857f3572 Tests: Add more tests for AK::URL
This adds more tests for AK::URL. Furthermore, this also changes some
tests to conform to what the reworked URL class does (and the URL
specification mostly expects).
2021-06-01 09:28:05 +02:00
Max Wipfli ebf074ca29 AK: Rewrite URL::compute_validity() to conform to new parser
This rewrites the URL validation check to be more specific, so it can
more accurately detect if a user of URL class constructs invalid URLs by
hand.
2021-06-01 09:28:05 +02:00
Max Wipfli 522ef53b98 AK: Remove deprecated m_path member variable from URL
The m_path member variable has been superseded by m_paths. Thus, it has
been removed. The path() getter will continue to exist as a convenience
method for getting the path joined together as a string.
2021-06-01 09:28:05 +02:00
Max Wipfli b7c6af0a04 AK: Replace URL::to_string() with new serialize() implementation 2021-06-01 09:28:05 +02:00
Max Wipfli 1c4854824b LibWeb: Remove usage of URL::set_path() in FrameLoader
This replaces a call to URL::set_path() with URL::set_paths(), as
set_path() will be deprecated and removed.
2021-06-01 09:28:05 +02:00
Max Wipfli 915cce5b74 Spreadsheet: Remove usage of URL::set_path()
This replaces a call to URL::set_path() with URL::set_paths(), as
set_path() will be deprecated and removed.
2021-06-01 09:28:05 +02:00
Max Wipfli 81f03e7a5d AK: Replace old URL parser with new URLParser::parse()
This replaces the old URL::parse() and URL::complete_url() parsing
mechanisms with the new spec-compliant URLParser::parse().
2021-06-01 09:28:05 +02:00
Max Wipfli 1697f3c35b AK: Add spec-compliant URL serialization methods
This adds URL serialization methods which are more in line with the
specification.

The serialize_for_display() method should be used e.g. in the browser
address bar, and as per the spec should not display username and
password. Furthermore, it could decode most percent-encoded code points,
although that is not implemented yet.
2021-06-01 09:28:05 +02:00
Max Wipfli 0d0ed4962f AK: Add a new, spec-compliant URLParser
This adds a new URL parser, which aims to be compliant with the URL
specification (https://url.spec.whatwg.org/). It also contains a
rudimentary data URL parser.
2021-06-01 09:28:05 +02:00
Max Wipfli 8a938a3e25 AK: Add helper functions and private data URL constructor to URL
This adds a few helper functions and a private constructor to
instantiate a data URL to the URL class. These will be needed by the
upcoming URL parser.
2021-06-01 09:28:05 +02:00
Max Wipfli dd392dfa03 AK: Add member variables to the URL class
This adds the m_username, m_password, m_paths and m_cannot_be_a_base_url
member variables to the URL class. These are necessary for the upcoming
new URL parser.

The deprecated m_path variable shadows the m_paths variable if it is
non-null. This behavior will be removed once the old URL parser has been
removed.
2021-06-01 09:28:05 +02:00
Max Wipfli 0d41a7d39a AK: Remove URLParser
This removes URLParser, because its two exposed functions, urlencode()
and urldecode(), have been superseded by URL::percent_encode() and
URL::percent_decode(). This is in preparation for the introduction of a
new URL parser.
2021-06-01 09:28:05 +02:00
Max Wipfli a603e69599 AK+Everywhere: Replace usages of URLParser::urlencode() and urldecode()
This replaces all occurrences of those functions with the newly
implemented functions URL::percent_encode() and URL::percent_decode().
The old functions will be removed in a further commit.
2021-06-01 09:28:05 +02:00
Max Wipfli 2a6c9bc5f7 AK: Implement more conforming URL percent encode/decode mechanism
This adds a few new functions to percent encode/decode strings according
to the URL specification. The functions allow specifying a
PercentEncodeSet, which is defined by the specification. It will be used
to replace the current urlencode() and urldecode() functions in a
further commit.

This commit adds a few duplicate helper functions in the URL class, such
as is_digit() and is_ascii_digit(). This will be cleaned up as soon as
the upcoming new URL parser will replace the current one.
2021-06-01 09:28:05 +02:00
Max Wipfli 0e4f7aa8e8 AK: Add trim() method to String, StringView and StringUtils
The methods added make it possible to use the trim mechanism with
specified characters, unlike trim_whitespace(), which uses predefined
characters.
2021-06-01 09:28:05 +02:00
Max Wipfli 14506e8f5e AK: Implement Utf8CodepointIterator::peek(size_t)
This adds a peek method for Utf8CodepointIterator, which enables it to
be used in some parsing cases where peeking is necessary.

peek(0) is equivalent to operator*, expect that peek() does not contain
any assertions and will just return an empty Optional<u32>.

This also implements a test case for iterating UTF-8.
2021-06-01 09:28:05 +02:00
Max Wipfli 31f6ba0952 AK: Internally rename protocol to scheme in URL
This renames all references to protocol to scheme, which is the name
used by the URL standard (https://url.spec.whatwg.org/). Externally, all
methods referencing "protocol" were duplicated with "scheme". The old
methods still exist as compatibility.
2021-06-01 09:28:05 +02:00
Max Wipfli d6709ac87d AK: Omit unnecessary function parameter names in URL
This patch removes unnecessary function parameter names in declarations
of the URL class. It also changes parameter types from String to
StringView where applicable.
2021-06-01 09:28:05 +02:00
Andreas Kling d105747735 basename: Tidy up a little more
This looks a little nicer with a single outln() invocation. :^)
2021-06-01 09:13:17 +02:00
Andreas Kling 9388cf327f basename: Support suffix stripping
Allow passing an optional suffix argument to `basename` which is then
stripped from the resulting basename (unless the resulting basename is
identical to the suffix.)

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/basename.html
2021-06-01 09:05:15 +02:00
Andreas Kling 313e53dca0 LibCore: Add StringView overloads for Core::ArgsParser
These allow you to get StringView wrappers around on-stack string
arguments, which seems pretty nice. :^)
2021-06-01 09:02:43 +02:00
Andreas Kling dd9b8ee7ef Documentation: Add rule about "east const" to CodingStyle.md
Unfortunately we cannot enforce this with clang-format yet, as that
feature is not available. Until then, let's try to write new code
with this in mind, and convert old code as we go.
2021-06-01 08:55:47 +02:00
Gunnar Beutner 45117a4134 Hearts: Fix sorting for pick_low_points_high_value_card
Previously the function did not sort the hand at all which means we
wouldn't necessarily pick the card with the highest value.
2021-06-01 08:52:08 +02:00
Gunnar Beutner 63d3beb78c Hearts: Prefer to pass high value cards
Previously we'd prefer to pass high points cards. Instead we should
prefer to pass high value cards first.
2021-06-01 08:52:08 +02:00
Gunnar Beutner 8b9da08d5a Hearts: Pick better non-matching cards
When we don't have a matching card for the lead card rather than
always preferring to play hearts we should try to get rid of our
high value cards first if no other player has hearts cards higher
than what we have.
2021-06-01 08:52:08 +02:00
Gunnar Beutner 4a8d8da46c Hearts: Make debugging AI suggestions easier
When building Hearts with HEARTS_DEBUG we highlight the card the AI
would have picked. This makes comparing AI and human decisions easier.
2021-06-01 08:52:08 +02:00
Gunnar Beutner 2b2d992946 Hearts: Pick better cards when we're the third player
When we're the third player in a trick and we don't have a lower value
card we would previously pick a slightly higher value card. Instead
we should pick the highest value card unless there are points in the
current trick or the lead card is spades and the higher value card
we would've picked is higher than the queen and another player still
has the queen.

The rationale is that we have to take the trick anyway so we might as
well get rid of our highest value card. If the trailing player has a
lower value card of the same type we take the trick but don't gain
any points. If they don't have a card of the same type it doesn't
matter whether we play a high value or low value card.
2021-06-01 08:52:08 +02:00
Gunnar Beutner 38f8a6aabb Hearts: Pick better lead cards
Previously the AI would prefer playing a lead card for which no other
player had a card with a higher value even though it also had a card
for which a higher value card was still in play.
2021-06-01 08:52:08 +02:00
Jelle Raaijmakers 40ddb734ee LibPthread: Correct error check in sem_post and sem_wait 2021-06-01 08:29:56 +02:00
Itamar 8f6b496fed LibGUI: Add a FIXME about race in AutocompleteBox::apply_suggestion() 2021-06-01 08:28:27 +02:00
Itamar 7c2941d4ea LibGUI: Check that AutocompleteBox's selection row is valid
Previously we didn't check that the selection's row index is in a valid
range before attempting to access its data via the model.

This could cause an out-of-bounds access to the model's Vector of
suggestions.

I think this should fix #7404, but I can't verify it does because
I wasn't able to reproduce it on my machine.
2021-06-01 08:28:27 +02:00
Jelle Raaijmakers 7a4445a1fe LibGUI/TreeView: Select parent on collapse
When collapsing a tree that contains the current selection, the parent
node becomes selected instead.
2021-06-01 08:22:51 +02:00
Idan Horowitz 67a5e9f018 LibJS: Add left shift & right shift operator support for BigIntegers
Based on https://tc39.es/ecma262/#sec-numeric-types-bigint-leftShift
(This commit also includes the matching tests)
2021-05-31 19:50:29 +01:00
Luke 4ee58d36c0 Kernel/ACPI: Sprinkle links to the specification all over
The latest version of the ACPI specification (6.4) now has a web
version, making it possible to link directly to the relevant sections
of the specification.

I added links to the stuff that was easy to find.

The spec can be found here: https://uefi.org/specs/ACPI/6.4/index.html
2021-05-31 19:06:46 +01:00
Nick Miller 10ba6f254c Kernel: Rename instances of IO port 0xe9 to BOCHS_DEBUG_PORT 2021-05-31 19:06:13 +01:00
Oleg Kosenkov 971523621c
Ports: Add opentyrian and opentyrian-data 2021-05-31 19:01:49 +01:00
Egor Ananyin ed89cd93aa Ports: Add Simon Tatham's Puzzle Collection 2021-05-31 18:44:56 +01:00
Liav A 10c747f2be Documentation: Add explanation about AHCI locking 2021-05-31 18:28:25 +01:00
Linus Groh 1f62aaa193 lsof: Replace copy with reference in a for loop 2021-05-31 18:03:54 +01:00
Linus Groh 304752fccb cal: Remove unused variable declarations 2021-05-31 18:02:48 +01:00
Linus Groh 1eb048bed0 Userland: Remove a bunch of unused includes
As reported by CLion.
2021-05-31 18:01:53 +01:00
Linus Groh 16d51d78c0 Userland: Avoid a bunch of JsonObject copies
JsonValue::as_object() returns a reference.
2021-05-31 17:59:02 +01:00
Linus Groh a6248101e2 SpaceAnalyzer: Replace fprintf(stderr) with warnln() 2021-05-31 17:44:01 +01:00
Linus Groh 8625f089bf Debugger: Replace printf() with outln() 2021-05-31 17:44:01 +01:00
Linus Groh 5e48769487 Applets/Network: Replace fprintf(stderr) with dbgln()
This is an applet, so we're not going to see its stderr anyway.
2021-05-31 17:44:01 +01:00
Linus Groh 3a7574de82 LibX86: Replace fprintf(stderr) with warnln() 2021-05-31 17:43:54 +01:00