summaryrefslogtreecommitdiff
path: root/AK/StringView.h
AgeCommit message (Collapse)Author
2023-03-14AK: Rename CaseInsensitiveStringViewTraits to reflect intentgustrb
Now it is called `CaseInsensitiveASCIIStringViewTraits`, so we can be more specific about what data structure does it operate onto. ;)
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-03-09AK: Replace C-style castsSam Atkins
2023-02-05AK: Allow propagating errors from StringView::for_each_split_view()MacDue
2023-01-28AK: Add support for the new FlyString to StringViewTimothy Flynn
2023-01-28AK: Delete the StringView move-assignment operator for various typesTimothy Flynn
2023-01-14AK+Tests: Make CaseInsensitiveStringViewTraits work with HashMap againBen Wiederhake
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.
2022-12-20AK: Add DeprecatedString::find_last(StringView)Agustin Gianni
This adds the the method DeprecatedString::find_last() as wrapper for StringUtils::find_last for the StringView type.
2022-12-11AK: Add an identity implementation of StringView::from_string_literal()Ali Mohammad Pur
This is required for the Jakt runtime.
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-11-26AK: Make it possible to not `using` AK classes into the global namespaceAndreas Kling
This patch adds the `USING_AK_GLOBALLY` macro which is enabled by default, but can be overridden by build flags. This is a step towards integrating Jakt and AK types.
2022-11-06Everywhere: Remove redundant inequality comparison operatorsDaniel Bertalan
C++20 can automatically synthesize `operator!=` from `operator==`, so there is no point in writing such functions by hand if all they do is call through to `operator==`. This fixes a compile error with compilers that implement P2468 (Clang 16 currently). This paper restores the C++17 behavior that if both `T::operator==(U)` and `T::operator!=(U)` exist, `U == T` won't be rewritten in reverse to call `T::operator==(U)`. Removing `!=` operators makes the rewriting possible again. See https://reviews.llvm.org/D134529#3853062
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-14AK: Add StringView::find_last_notUndefine
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-10-04AK+Everywhere: Add AK_COMPILER_{GCC,CLANG} and use them most placesNico Weber
Doesn't use them in libc headers so that those don't have to pull in AK/Platform.h. AK_COMPILER_GCC is set _only_ for gcc, not for clang too. (__GNUC__ is defined in clang builds as well.) Using AK_COMPILER_GCC simplifies things some. AK_COMPILER_CLANG isn't as much of a win, other than that it's consistent with AK_COMPILER_GCC.
2022-09-27AK: Add StringView operator==(char)Lucas CHOLLET
2022-08-30AK: Add find_first_split_view() helper for StringView containerLiav A
Similar to the find_last_split_view() helper, but in this helper we search for the first split view instead of the last one.
2022-07-26AK: VERIFY() the index is in bounds in StringView::operator[]MacDue
That this did not already happen took me by surprise, as for most other similar containers/types in AK (e.g. Span) the index will be checked. This check not happening could easily let off-by-one indexing errors slip through the cracks.
2022-07-15AK: Add a helper to get the last split-groupHendiadyoin1
2022-07-12AK: Remove StringView(char const*) :^)sin-ack
This constructor relied on running strlen implicitly on its argument, thereby potentially causing out-of-bound reads (some of which were caught a few days ago). The removal of this constructor ensures that the caller must explicitly pass the size of the string by either: 1) Using operator""sv on literal strings; or 2) Calling strlen explicitly, making it clear that the size of the view is being calculated at runtime.
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-03-21AK: Add a case insensitive of is_one_of to String[View]Hendiadyoin1
2022-03-18AK: Mark the StringView user-defined literal as constevalTimothy Flynn
Even though the StringView(char*, size_t) constructor only runs its overflow check when evaluated in a runtime context, the code generated here could prevent the compiler from optimizing invocations from the StringView user-defined literal (verified on Compiler Explorer). This changes the user-defined literal declaration to be consteval to ensure it is evaluated at compile time.
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-30AK+Tests: Make null strings compare less than non-null stringsDaniel Bertalan
This behavior regressed in ca58c71faa6e31721b6094d380732d2aa6f3d791. Fixes #12213
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-11AK: Define a traits helper for case-insensitive StringView hashingTimothy Flynn
Currently, we define a CaseInsensitiveStringTraits structure for String. Using this structure for StringView involves allocating a String from that view, and a second string to convert that intermediate string to lowercase. This defines CaseInsensitiveStringViewTraits (and the underlying helper case_insensitive_string_hash) to avoid allocations.
2021-11-16AK: Verify that we are not overreaching in StringView's substring_view()Hendiadyoin1
2021-11-14AK: Mark StringView::find_any_of() as constAndrew Kaster
2021-11-14AK: Resolve clang-tidy readability-bool-conversion warningsAndrew Kaster
... In files included by Kernel/Process.cpp and Kernel/Thread.cpp
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-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-09-11AK: Make String::count not use strstr and take a StringViewIdan Horowitz
This was needlessly copying StringView arguments, and was also using strstr internally, which meant it was doing a bunch of unnecessary strlen calls on it. This also moves the implementation to StringUtils to allow API consistency between String and StringView.
2021-09-11AK: Forbid creating StringView from temporary FlyStringBen Wiederhake
2021-09-11AK: Forbid creating StringView from temporary ByteBufferBen Wiederhake
2021-09-04AK+LibRegex: Disable construction of views from temporary StringsIdan Horowitz
2021-08-26AK: Implement method to convert a String/StringView to title caseTimothy Flynn
This implementation preserves consecutive spaces in the orginal string.
2021-08-18AK+Kernel: StringView hash map Traits should not set peek type to StringBrian Gianforcaro
This typo / bug in the Traits<T> implementation for StringView caused AK::HashMap methods to return a `String` when looking up values out of a hash map of type HashTable<StringView,StringView>. This change fixes the typo, and fixes the only consumer, the kernel Commandline class.
2021-08-02AK: Fix declaration of {String,StringView}::is_one_ofTimothy Flynn
The declarations need to consume the variadic parameters as "Ts&&..." for the parameters to be forwarding references.
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.