summaryrefslogtreecommitdiff
path: root/AK/String.h
AgeCommit message (Collapse)Author
2021-05-19AK: Add String::find_all() and String::count()Maciej Zygmanowski
2021-05-16AK+Userland: Remove nullability feature for the ByteBuffer typeGunnar Beutner
Nobody seems to use this particular feature, in fact there were some bugs which were uncovered by removing operator bool.
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-21AK: Decorate most of String's API's with [[nodiscard]]Andreas Kling
2021-04-10AK+Everywhere: Make StdLibExtras templates less wrapper-yAnotherTest
This commit makes the user-facing StdLibExtras templates and utilities arguably more nice-looking by removing the need to reach into the wrapper structs generated by them to get the value/type needed. The C++ standard library had to invent `_v` and `_t` variants (likely because of backwards compat), but we don't need to cater to any codebase except our own, so might as well have good things for free. :^)
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-23AK+Kernel+Userland: Enable some more compiletime format string checksAnotherTest
This enables format string checks for three more functions: - String::formatted() - Builder::appendff() - KBufferBuilder::appendff()
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-08AK: Add dbgln() format checkingAnotherTest
This checks the following things: - No unclosed braces in format string `dbgln("a:{}}", a)` where the '}}' would be interpreted as a literal '}' `dbgln("a:{", a)` where someone with a faulty keyboard like mine could generate - No extra closed braces in format string `dbgln("a:{{}", a)` where the '{{' would interpreted as a literal '{' `dbgln("a:}", a)` where someone with a faulty keyboard could generate - No references to nonexistent arguments `dbgln("a:{} b:{}", a)` where the value of `b` is not in the arguments list - No unconsumed argument `dbgln("a:{1}", not_used, 1)` where `not_used` is extraneous
2021-01-15AK: Add String::join() helper functionLinus Groh
This is a simple wrapper around StringBuilder::join().
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.
2021-01-11AK: Enable format string warnings for AK printf wrappersSahan Fernando
2021-01-03AK: Add String{,View}::is_whitespace()AnotherTest
+Tests!
2020-12-30AK: Replace some SFINAE with requires clauses, clean up existing onesAndrew Kaster
Add requires clauses to constraints on InputStream and OutputStream operator<< / operator>>. Make the constraint on String::number a requires clause instead of SFINAE. Also, fix some unecessary IsSame in Trie where specialized traits exist for the given use cases.
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-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-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
2020-09-14AK: Lower the requirements for InputStream::eof and rename it.asynts
Consider the following snippet: void foo(InputStream& stream) { if(!stream.eof()) { u8 byte; stream >> byte; } } There is a very subtle bug in this snippet, for some input streams eof() might return false even if no more data can be read. In this case an error flag would be set on the stream. Until now I've always ensured that this is not the case, but this made the implementation of eof() unnecessarily complicated. InputFileStream::eof had to keep a ByteBuffer around just to make this possible. That meant a ton of unnecessary copies just to get a reliable eof(). In most cases it isn't actually necessary to have a reliable eof() implementation. In most other cases a reliable eof() is avaliable anyways because in some cases like InputMemoryStream it is very easy to implement.
2020-09-08AK: Add generic SimpleIterator class to replace VectorIterator.asynts
2020-09-01Streams: Distinguish recoverable and fatal errors.asynts
2020-08-30AK: Add String::copy_characters_to_buffer()Sergey Bugaev
This is a strcpy()-like method with actually sane semantics: * It accepts a non-empty buffer along with its size in bytes. * It copies as much of the string as fits into the buffer. * It always null-terminates the result. * It returns, as a non-discardable boolean, whether the whole string has been copied. Intended usage looks like this: bool fits = string.copy_characters_to_buffer(buffer, sizeof(buffer)); and then either if (!fits) { fprintf(stderr, "The name does not fit!!11"); return nullptr; } or, if you're sure the buffer is large enough, // I'm totally sure it fits because [reasons go here]. ASSERT(fits); or if you're feeling extremely adventurous, (void)fits; but don't do that, please.
2020-08-30AK: Stream operators for String for generic streams.asynts
I think this should really be a member function of InputStream instead, but I don't want to include String in Stream.h. This will do for now...
2020-08-24AK: Document that String{,Impl} contains NUL-terminatorBen Wiederhake
2020-08-06AK: Add InputStream abstraction and InputMemoryStream implementation.asynts
2020-08-06AK: Add String constructor from ReadonlyBytes.asynts
2020-07-28AK: Tweak String::is_one_of() and FlyString::is_one_of()Andreas Kling
Switch the comparisons from "other == *this" to "*this == other".
2020-07-27AK: Add span() / bytes() methods to container types.asynts
2020-07-21AK: Add case insensitive version of starts_withLuke
2020-07-13AK: Give String::index_of() an optional second "start" argumentNico Weber
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-30AK: Make {String,FlyString}::is_one_of() constAndreas Kling
Also, make the zero-argument variant private since it's not meant to be called by clients directly.
2020-05-26AK: Mark some popular String member functions ALWAYS_INLINEAndreas Kling
I don't wanna see String::length() in a profile, jeez. :^)
2020-05-26AK: Add case insensitive String::ends_with supportBrian Gianforcaro
FileSystemPath::has_extension was jumping through hoops and allocating memory to do a case insensitive comparison needlessly. Extend the existing String::ends_with method to allow the caller to specify the case sensitivity required.
2020-05-25AK: Add String::is_one_of(...)Andreas Kling
This allows you to compare a string against an arbitrary number of other strings with a single call.
2020-05-13AK: Replace String::trim_spaces() with String::trim_whitespace()Linus Groh
As suggested by @awesomekling in a code review and (initially) ignored by me :^) Implementation is roughly based on LibJS's trim_string(), but with a fix for trimming all-whitespace strings.
2020-05-11AK: Add String::trim_spaces()Linus Groh
2020-04-13LibELF: Add find_demangled_functionItamar
Also, added AK::String::index_of and fixed a bug in ELF::Loader::symbol_ptr
2020-04-01AK: Add String::replace() functionalityEmanuel Sprung
This adds a replace functionality that replaces a string that contains occurences of a "needle" by a "replacement" value. With "all_occurences" enabled, all occurences are being replaced, otherwise only the first occurence is being replaced.