summaryrefslogtreecommitdiff
path: root/AK/StringView.cpp
AgeCommit message (Collapse)Author
2023-03-10Everywhere: Rename equals_ignoring_case => equals_ignoring_ascii_caseAndreas Kling
Let's make it clear that these functions deal with ASCII case only.
2023-01-28AK: Add support for the new FlyString to StringViewTimothy Flynn
2023-01-09AK+Everywhere: Rename FlyString to DeprecatedFlyStringTimothy Flynn
DeprecatedFlyString relies heavily on DeprecatedString's StringImpl, so let's rename it to A) match the name of DeprecatedString, B) write a new FlyString class that is tied to String.
2023-01-02Everywhere: Remove unused includes of AK/Memory.hBen Wiederhake
These instances were detected by searching for files that include AK/Memory.h, but don't match the regex: \\b(fast_u32_copy|fast_u32_fill|secure_zero|timing_safe_compare)\\b This regex is pessimistic, so there might be more files that don't actually use any memory function. In theory, one might use LibCPP to detect things like this automatically, but let's do this one step after another.
2022-12-16AK: Synchronize explicit instantiations of to_int and to_uintTimothy Flynn
1. Ensure long and long long are instantiated for to_int. 2. Ensure long and long long are not instantiated for to_uint.
2022-12-07AK: Add StringView(String const&) constructorLinus Groh
This allows us to pass the new String type to functions that take a StringView directly, having to call bytes_as_string_view() every time gets old quickly.
2022-12-06Everywhere: Rename to_{string => deprecated_string}() where applicableLinus Groh
This will make it easier to support both string types at the same time while we convert code, and tracking down remaining uses. One big exception is Value::to_string() in LibJS, where the name is dictated by the ToString AO.
2022-12-06AK+Everywhere: Rename String to DeprecatedStringLinus Groh
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
2022-10-24AK: Add SplitBehavior::KeepTrailingSeparator with testsdemostanis
2022-10-24AK+Everywhere: Turn bool keep_empty to an enum in split* functionsdemostanis
2022-10-23AK: Add to_{double, float} convenience functions to all string typesdavidot
These are guarded with #ifndef KERNEL, since doubles (and floats) are not allowed in KERNEL mode. In StringUtils there is convert_to_floating_point which does have a template parameter incase you have a templated type.
2022-10-09AK+Everywhere: Fix data corruption due to code-point-to-char conversionBen Wiederhake
In particular, StringView::contains(char) is often used with a u32 code point. When this is done, the compiler will for some reason allow data corruption to occur silently. In fact, this is one of two reasons for the following OSS Fuzz issue: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=49184 This is probably a very old bug. In the particular case of URLParser, AK::is_url_code_point got confused: return /* ... */ || "!$&'()*+,-./:;=?@_~"sv.contains(code_point); If code_point is a large code point that happens to have the correct lower bytes, AK::is_url_code_point is then convinced that the given code point is okay, even if it is actually problematic. This commit fixes *only* the silent data corruption due to the erroneous conversion, and does not fully resolve OSS-Fuzz#49184.
2022-07-06AK: Use an enum instead of a bool for String::replace(all_occurences)DexesTTP
This commit has no behavior changes. In particular, this does not fix any of the wrong uses of the previous default parameter (which used to be 'false', meaning "only replace the first occurence in the string"). It simply replaces the default uses by String::replace(..., ReplaceMode::FirstOnly), leaving them incorrect.
2022-04-03AK: Add `StringView::copy_characters_to_buffer()`Tim Schumacher
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-02-16AK: Exclude StringView String APIs from the KernelIdan Horowitz
These APIs are only used by userland, and String is OOM-infallible, so let's just ifdef it out of the Kernel.
2022-01-29AK: Implement all comparison operators for StringViewDaniel Bertalan
2022-01-12AK: Implement StringView::for_each_split_viewBrian Gianforcaro
StringView::for_each_split_view allows you to process the splits in a StringView without needing to allocate a Vector<StringView> to store each of the parts. Since we migrated the implementation from the normal split_view path, we can also re-implement split_view in terms of for_each_split_view.
2022-01-12AK: Rewrite StringView::split_view(char..), using StringViewBrian Gianforcaro
2021-11-11Everywhere: Pass AK::StringView by valueAndreas Kling
2021-11-10AK+Everywhere: Stop including Vector.h from StringView.hAndreas Kling
Preparation for using Error.h from Vector.h. This required moving some things out of line.
2021-10-05AK: Expand to_int<i64> to to_int<long> and to_int<long long>Peter Elliott
This change also applys to to_uint On i686 u64 == long long but on x86_64 u64 == long. Therefor on either arch, one of the instantiations is missed. This change makes sure that all integer types have an instantiation.
2021-09-11AK: Replace the mutable String::replace API with an immutable versionIdan Horowitz
This removes the awkward String::replace API which was the only String API which mutated the String and replaces it with a new immutable version that returns a new String with the replacements applied. This also fixes a couple of UAFs that were caused by the use of this API. As an optimization an equivalent StringView::replace API was also added to remove an unnecessary String allocations in the format of: `String { view }.replace(...);`
2021-08-26AK: Implement method to convert a String/StringView to title caseTimothy Flynn
This implementation preserves consecutive spaces in the orginal string.
2021-07-02AK: Implement String::find_any_of() and StringView::find_any_of()Max Wipfli
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.
2021-07-02AK+Everywhere: Remove StringView::find_{first,last}_of(char) methodsMax Wipfli
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.
2021-07-02AK: Reimplement StringView::find methods in StringUtilsMax Wipfli
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.
2021-07-02AK: Implement StringView::to_{lower,upper}case_stringMax Wipfli
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.
2021-06-04AK: Don’t drop lines between \r and \n in StringView::lines() (#7662)R Smith
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.
2021-05-14AK: Make StringView::hash() constexprAndreas Kling
This required moving string_hash() to its own header so that everyone can see it.
2021-04-22AK/GenericLexer: constexpr where possibleLenny Maiorani
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.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
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 *
2021-04-17AK: Remove String-from-StringView optimizationAndreas Kling
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. :^)
2021-04-12AK: Fix StringView::find_last_of for one-character viewsTimothy Flynn
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
2021-04-12AK: Add a predicate variant of StringView::split_viewTimothy Flynn
2021-02-26Everywhere: Remove a bunch of redundant 'AK::' namespace prefixesLinus Groh
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. :^)
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...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.
2021-01-15StringView: Implement `find_first_of` in terms of `AK::find`Lenny Maiorani
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.
2021-01-12AK: Use StringView::find() in StringView::split_view()AnotherTest
This fixes #4926.
2021-01-12AK: Add String{View,}::find(StringView)AnotherTest
I personally mistook `find_first_of(StringView)` to be analogous to this so let's add a `find()` method that actually searches the string.
2021-01-11AK: Specialise convert_to_uint<T> and to_uint<T> for 'long' variantsAnotherTest
2020-12-21AK: Generalize AK::String::to_int() for more typesSahan Fernando
2020-10-29AK: Make String::matches() capable of reporting match positions tooAnotherTest
Also, rewrite StringUtils::match(), because the old implementation was fairly broken, e.g. "acdcxb" would *not* match "a*?b".
2020-10-22AK: Enhance String::contains to allow case-insensitive searchesTom
2020-09-21AK: Add StringView::substring_view(size_t) overload.asynts
2020-08-01AK: Add StringView::contains(StringView)AnotherTest
2020-07-21AK: Add case insensitive version of starts_withLuke
2020-06-12AK: Make string-to-number conversion helpers return OptionalAndreas Kling
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-05-28AK: Add StringView::split_view() taking a StringViewAnotherTest
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-26AK: Unify FlyString/StringView::ends_with implementation on ↡Brian Gianforcaro
StringUtils::ends_with This creates a unified implementation of ends_with with case sensitivity across String/StringView/FlyString.