summaryrefslogtreecommitdiff
path: root/AK/String.cpp
AgeCommit message (Collapse)Author
2022-04-20AK: Explicitly instantiate String::to_uint<unsigned long{, long}>()Ali Mohammad Pur
Instead of just to_uint<u64>().
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-02-25AK: Add String::split_view(Function<bool(char)>)Andreas Kling
This allows you to split around a custom separator, and enables expressive code like this: string.split_view(is_ascii_space);
2022-01-29AK: Implement String's comparison operators in terms of StringView'sDaniel Bertalan
2022-01-24Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOrSam Atkins
Apologies for the enormous commit, but I don't see a way to split this up nicely. In the vast majority of cases it's a simple change. A few extra places can use TRY instead of manual error checking though. :^)
2022-01-16AK: Fix logic in String::operator>(const String&)Matt Jacobson
Null strings should not compare greater than non-null strings. Add tests for >, <, >=, and <= comparison involving null strings.
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
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-12AK: Escape '"' in escape_html_entitiesPeter Elliott
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-06Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safeAli Mohammad Pur
2021-09-01AK: Pass AK::Format TypeErasedFormatParams by reference in AK::StringBrian Gianforcaro
This silences a overeager warning in sonar cloud, warning that slicing could occur with `VariadicFormatParams` which derives from `TypeErasedFormatParams`. Reference: https://sonarcloud.io/project/issues?id=SerenityOS_serenity&issues=AXuVPBW3k92xXUF3qXTE&open=AXuVPBW3k92xXUF3qXTE This is a continuation of f0b3aa033134b788a28fe8cf8ff6028d0e7941e8.
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-12AK: Add contains(char) method to StringJean-Baptiste Boric
2021-07-04AK: Add generation of roman numerals to AK::StringTobias Christiansen
We now can generate roman numbers using String::roman_number_from() similar to String::bijective_base_from().
2021-07-02AK: Add input bounds checking to String::substring()Max Wipfli
This checks for overflow in String::substring(). It also rearranges some declarations in the header.
2021-07-02AK: Add String::find_last() and inline String::find() methodsMax Wipfli
This adds the String::find_last() as wrapper for StringUtils::find_last, which is another step in harmonizing the String and StringView APIs where possible. This also inlines the find() methods, as they are simple wrappers around StringUtils functions without any additional logic.
2021-07-02AK: Implement StringView::find_all()Max Wipfli
This implements the StringView::find_all() method by re-implemeting the current method existing for String in StringUtils, and using that implementation for both String and StringView. The rewrite uses memmem() instead of strstr(), so the String::find_all() argument type has been changed from String to StringView, as the null byte is no longer required.
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-06-29AK: Ensure StringBuilder capacity in String::reverseIdan Horowitz
2021-06-18AK: Add a way to disable the trimming of whitespace in to_*intsin-ack
This behavior might not always be desirable, and so this patch adds a way to disable it.
2021-06-03AK: Allow inlining more string functionsGunnar Beutner
2021-05-25AK: Add String::repeated(StringView, size_t count)Matthew Olsson
2021-05-24AK+Everywhere: Consolidate String::index_of() and String::find()Andreas Kling
We had two functions for doing mostly the same thing. Combine both of them into String::find() and use that everywhere. Also add some tests to cover basic behavior.
2021-05-19AK: Add String::find_all() and String::count()Maciej Zygmanowski
2021-05-01AK: Move bijective-base-conversion into AK/StringTobias Christiansen
This allows everybody to create a String version of their number in a arbitrary bijective base. Bijective base meaning that the mapping doesn't have a 0. In the usual mapping to the alphabet the follower after 'Z' is 'AA'. The mapping using the (uppercase) alphabet is used as a standard but can be overridden specifying 'base' and 'map'. The code was directly yanked from the Spreadsheet.
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-21AK: Remove String::format()Andreas Kling
There are no more clients of this function, everyone has been converted to String::formatted().
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-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-02-21AK: Add String{,Utils}::to_snakecase()Linus Groh
This is an improved version of WrapperGenerator's snake_name(), which seems like the kind of thing that could be useful elsewhere but would end up getting duplicated - so let's add this to AK::String instead, like to_{lowercase,uppercase}().
2021-02-08Everywhere: Remove unnecessary headers 2/4Ben Wiederhake
Arbitrarily split up to make git bisect easier. These unnecessary #include's were found by combining an automated tool (which determined likely candidates) and some brain power (which decided whether the #include is also semantically superfluous).
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-12AK: Simplify constructors and conversions from nullptr_tLenny Maiorani
Problem: - Many constructors are defined as `{}` rather than using the ` = default` compiler-provided constructor. - Some types provide an implicit conversion operator from `nullptr_t` instead of requiring the caller to default construct. This violates the C++ Core Guidelines suggestion to declare single-argument constructors explicit (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit). Solution: - Change default constructors to use the compiler-provided default constructor. - Remove implicit conversion operators from `nullptr_t` and change usage to enforce type consistency without conversion.
2020-12-30AK: Move String::number entirely to header fileAndrew Kaster
Use SFINAE to enforce the fact that it's supposed to only be called for Arithmetic types, rather than counting on the linker to tell us that an instantiation of String::number(my_arg) was not found. This also adds String::number for floating point types as a side-effect.
2020-12-27LibJS: Implement (mostly) spec compliant version of Number.toString()Stephan Unverwerth
2020-12-21AK: Generalize AK::String::to_int() for more typesSahan Fernando
2020-12-10AK: Add String::substring(start)Andreas Kling
This is a convenience API when you just want the rest of the string starting at some index. We already had substring_view() in the same flavor, so this is a complement to that.
2020-12-09AK: Add String::substring_view(size_t).asynts
2020-11-15Everywhere: Add missing <AK/ByteBuffer.h> includesAndreas Kling
All of these files were getting ByteBuffer.h from someone else and then using it. Let's include it explicitly.
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-10-05AK: Move StringImpl::operator== implementation into StringImplNico Weber
2020-10-03Everywhere: Fix more typosLinus Groh
2020-10-02AK+Format: Do some housekeeping in the format implementation.asynts
2020-09-27AK: Move trim_whitespace() into StringUtils and add it to StringViewAnotherTest
No behaviour change; also patches use of `String::TrimMode` in LibJS.
2020-09-23AK: Resolve format related circular dependencies properly.asynts
With this commit, <AK/Format.h> has a more supportive role and isn't used directly. Essentially, there now is a public 'vformat' function ('v' for vector) which takes already type erased parameters. The name is choosen to indicate that this function behaves similar to C-style functions taking a va_list equivalent. The interface for frontend users are now 'String::formatted' and 'StringBuilder::appendff'.
2020-09-22AK: Use format in String::number.asynts