Age | Commit message (Collapse) | Author |
|
This implementation preserves consecutive spaces in the orginal string.
|
|
This implements StringUtils::find_any_of() and uses it in
String::find_any_of() and StringView::find_any_of(). All uses of
find_{first,last}_of have been replaced with find_any_of(), find() or
find_last(). find_{first,last}_of have subsequently been removed.
|
|
This removes StringView::find_first_of(char) and find_last_of(char) and
replaces all its usages with find and find_last respectively. This is
because those two methods are functionally equivalent.
find_{first,last}_of should only be used if searching for multiple
different characters, which is never the case with the char argument.
This also adds the [[nodiscard]] to the remaining find_{first,last}_of
methods.
|
|
This patch reimplements the StringView::find methods in StringUtils, so
they can also be used by String. The methods now also take an optional
start parameter, which moves their API in line with String's respective
methods.
This also implements a StringView::find_ast(char) method, which is
currently functionally equivalent to find_last_of(char). This is because
find_last_of(char) will be removed in a further commit.
|
|
This patch refactors StringImpl::to_{lower,upper}case to use the new
static methods StringImpl::create_{lower,upper}cased if they have to use
to create a new StringImpl. This allows implementing StringView's
to_{lower,upper}case_string using the same methods.
It also replaces the usage of hand-written to_ascii_lowercase() and
similar methods with those from CharacterTypes.h.
|
|
StringView::lines() supports line-separators β\nβ, β\rβ, and β\r\nβ.
The method will drop an entire line if it is surrounded by β\rβ
and β\nβ separators on the left and right sides respectively.
|
|
This required moving string_hash() to its own header so that everyone
can see it.
|
|
Problem:
- Much of the `GenericLexer` can be `constexpr`, but is not.
Solution:
- Make it `constexpr` and de-duplicate code.
- Extend some of `StringView` with `constexpr` to support.
- Add tests to ensure `constexpr` behavior.
Note:
- Construction of `StringView` from pointer and length is not
`constexpr`-compatible at the moment because the VERIFY cannot be,
yet.
|
|
SPDX License Identifiers are a more compact / standardized
way of representing file license information.
See: https://spdx.dev/resources/use/#identifiers
This was done with the `ambr` search and replace tool.
ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
|
|
We had an unusual optimization in AK::StringView where constructing
a StringView from a String would cause it to remember the internal
StringImpl pointer of the String.
This was used to make constructing a String from a StringView fast
and copy-free.
I tried removing this optimization and indeed we started seeing a
ton of allocation traffic. However, all of it was due to a silly
pattern where functions would take a StringView and then go on
to create a String from it.
I've gone through most of the code and updated those functions to
simply take a String directly instead, which now makes this
optimization unnecessary, and indeed a source of bloat instead.
So, let's get rid of it and make StringView a little smaller. :^)
|
|
The find_last_of implementations were breaking out of the search loop
too early for single-character string views. This caused a crash in
CookieJar setting a cookie on google.com - CookieJar::default_path knew
there was at least one "/" in a string view, but find_last_of returned
nullopt, so dereferencing the optional caused a crash.
Fixes #6273
|
|
|
|
This is basically just for consistency, it's quite strange to see
multiple AK container types next to each other, some with and some
without the namespace prefix - we're 'using AK::Foo;' a lot and should
leverage that. :^)
|
|
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)
Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.
We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
|
|
Problem:
- The implementation of `find_first_of` is coupled to the
implementation of `StringView`.
Solution:
- Decouple the implementation of `find_first_of` from the class by
using a generic `find` algorithm.
|
|
This fixes #4926.
|
|
I personally mistook `find_first_of(StringView)` to be analogous to this
so let's add a `find()` method that actually searches the string.
|
|
|
|
|
|
Also, rewrite StringUtils::match(), because the old implementation was
fairly broken, e.g. "acdcxb" would *not* match "a*?b".
|
|
|
|
|
|
|
|
|
|
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
|
|
Since the task of splitting a string via another is pretty common, we
might as well have this overload of split_view() as well.
|
|
StringUtils::ends_with
This creates a unified implementation of ends_with with case sensitivity
across String/StringView/FlyString.
|
|
StringUtils::equals_ignoring_case() already operates on a StringView&,
so StringView should have the method directly without having to go
through a temporary String (which also has the method).
|
|
This allows easy creation of a new string from an existing StringView.
Can be used e.g. for output with printf(..., view.to_string().characters())
instead of writing printf(..., String{view}.characters()).
|
|
These methods search from the beginning or end of a string for the
first character in the input StringView and returns the position in
the string of the first match. Note that this is not a substring match.
Each comes with single char overloads for efficiency.
|
|
|
|
String.h no longer pulls in StringView.h. We do this by moving a bunch
of String functions out-of-line.
|
|
FlyString is a flyweight string class that wraps a RefPtr<StringImpl>
known to be unique among the set of FlyStrings. The class is very
unoptimized at the moment.
When to use FlyString:
- When you want O(1) string comparison
- When you want to deduplicate a lot of identical strings
When not to use FlyString:
- For strings that don't need either of the above features
- For strings that are likely to be unique
|
|
Move the "fast memcpy" stuff out of StdLibExtras.h and into Memory.h.
This will break a ton of things that were relying on StdLibExtras.h
to include a bunch of other headers. Fix will follow immediately after.
This makes it possible to include StdLibExtras.h from Types.h, which is
the main point of this exercise.
|
|
Provide wrappers in String and StringView. Add some tests for the
implementations.
|
|
Provide wrappers in the String and StringView classes, and add some tests.
|
|
Now that Vector uses size_t, we can remove a whole bunch of redundant
casts to size_t.
|
|
This is simply meant to be a more efficient implementation in the
case that we only need to check a single character.
|
|
You can now #include <AK/Forward.h> to get most of the AK types as
forward declarations.
Header dependency explosion is one of the main contributors to compile
times at the moment, so this is a step towards smaller include graphs.
|
|
As suggested by Joshua, this commit adds the 2-clause BSD license as a
comment block to the top of every source file.
For the first pass, I've just added myself for simplicity. I encourage
everyone to add themselves as copyright holders of any file they've
added or modified in some significant way. If I've added myself in
error somewhere, feel free to replace it with the appropriate copyright
holder instead.
Going forward, all new source files should include a license header.
|
|
If the last character was the separator and keep_empty is true, the
previous if statement would have already appended the last empty part,
so no need to do this again.
This was even more problematic, because the result of split_view() is
expected to consist of true substrings that are usable with the
StringView::substring_view_starting_*_substring() methods, not of
equal strings located elsewhere.
Fixes https://github.com/SerenityOS/serenity/issues/970
See https://github.com/SerenityOS/serenity/pull/938
|
|
We expect the result to be usable with the
StringView::substring_view_starting_*_substring() methods.
See https://github.com/SerenityOS/serenity/pull/938
|
|
|
|
Using int was a mistake. This patch changes String, StringImpl,
StringView and StringBuilder to use size_t instead of int for lengths.
Obviously a lot of code needs to change as a result of this.
|
|
|
|
Previously, MDDocument only split on Unix-style line endings. This adds
a new function to StringView which handles LF, CR and CRLF.
|
|
|
|
|
|
This was a workaround to be able to build on case-insensitive file
systems where it might get confused about <string.h> vs <String.h>.
Let's just not support building that way, so String.h can have an
objectively nicer name. :^)
|
|
This grabs the hash from the underlying StringImpl if there is one,
otherwise it's computed on the fly.
|