summaryrefslogtreecommitdiff
path: root/AK/String.cpp
AgeCommit message (Collapse)Author
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
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-24AK: Remove redundant declaration in String.cppBen Wiederhake
It already includes AK/Memory.h, which includes Kernel/StdLib.h, which. declares strstr().
2020-08-22AK: Prefer snprintf over sprintfBen Wiederhake
2020-07-28AK: Make String::substring() return non-null for 0-length stringsPeter Elliott
This also makes String::split() give non-null strings when keep_empty is true.
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-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-26AK: Move String::ends_with implementation to StringUtilsBrian Gianforcaro
Centralizing so it can be used by other string implementations
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-11AK: String::contains() should say no if needle or haystack is nullAndreas Kling
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.
2020-03-28AK: Add some string comparison operatorsAndreas Kling
Some of these are very inefficient. It's nice to have some optimization opportunities in the future though. :^)
2020-03-23AK: Reduce header dependency graph of String.hAndreas Kling
String.h no longer pulls in StringView.h. We do this by moving a bunch of String functions out-of-line.
2020-03-22AK: Add FlyString::to_lowercase() and LogStream operator<<(FlyString)Andreas Kling
2020-03-22AK: Add FlyString::equals_ignoring_case(StringView)Andreas Kling
And share the code with String by moving the logic to StringUtils. :^)
2020-03-08AK: Move memory stuff (fast memcpy, etc) to a separate headerAndreas Kling
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.
2020-03-02AK: Move to_int(), to_uint() implementations to StringUtils (#1338)howar6hill
Provide wrappers in String and StringView. Add some tests for the implementations.
2020-03-02AK: Move the wildcard-matching implementation to StringUtilshowar6hill
Provide wrappers in the String and StringView classes, and add some tests.
2020-03-01AK: Remove unnecessary casts to size_t, after Vector changesAndreas Kling
Now that Vector uses size_t, we can remove a whole bunch of redundant casts to size_t.
2020-02-15AK: Add String starts_with(char) & ends_with(char)Shannon Booth
This is simply meant to be a more efficient implementation in the case that we only need to check a single character.
2020-02-14AK: Add a forward declaration headerAndreas Kling
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.
2020-02-13AK: Move escape_html_entities() from LibHTML to AKAndreas Kling
This sort of thing can be useful to things that don't want to link with all of LibHTML.
2020-02-05AK: Break String::number() overloads into i/l/ll and u/ul/ullAndreas Kling
Now that we're trying to be more portable, we can't only rely on using i32/u32 and i64/u64 since different systems have different combinations of int/long/long long and unsigned/unsigned long/unsigned long long.
2020-01-22AK: Also add a keep_empty argument to String::split[_limit]()Sergey Bugaev
Just like String[View]::split_view() has already.
2020-01-18Meta: Add license header to source filesAndreas Kling
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.
2020-01-14AK: Fix String[View]::split_view() returning an extra empty partSergey Bugaev
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
2020-01-14AK: Don't return null from String[View]::substring_view()Sergey Bugaev
We expect the result to be usable with the StringView::substring_view_starting_*_substring() methods. See https://github.com/SerenityOS/serenity/pull/938
2019-12-30AK: Use stack buffers in String::number() to avoid some malloc() callsAndreas Kling
2019-12-18AK: Add String::equals_ignoring_case(StringView)Andreas Kling
2019-12-09AK: Use size_t for the length of stringsAndreas Kling
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.
2019-10-28AK: Add String::contains(String)Andreas Kling
This is just a wrapper around strstr() for now. There are many better ways to search for a string within a string, but I'm just adding a nice API at the moment. :^)
2019-10-19String: Define operator>(String)Andreas Kling
2019-10-07AK: Make String compile on platforms where size_t==u32Andreas Kling
This kind of thing is a bit annoying. On Serenity, size_t is the same size as u32, but not the same type. Because of "long" or whatever. This patch makes String not complain about duplicate overloads.