diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-05-11 15:48:37 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-18 21:02:07 +0200 |
commit | f51b0729f519116c288b9bd9a1251daf66d7fa49 (patch) | |
tree | 039941ee62e1c459fbb731c93d3bc86f17086d08 | |
parent | df29d58e19e1325badeacee51e5674ff6b9e1416 (diff) | |
download | serenity-f51b0729f519116c288b9bd9a1251daf66d7fa49.zip |
AK: Implement StringBuilder::append_as_lowercase(char ch)
This patch adds a convenience method to AK::StringBuilder which converts
ASCII uppercase characters to lowercase before appending them.
-rw-r--r-- | AK/StringBuilder.cpp | 8 | ||||
-rw-r--r-- | AK/StringBuilder.h | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index b05488e00d..5678d1de79 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -120,6 +120,14 @@ void StringBuilder::append(const Utf32View& utf32_view) } } +void StringBuilder::append_as_lowercase(char ch) +{ + if (ch >= 'A' && ch <= 'Z') + append(ch + 0x20); + else + append(ch); +} + void StringBuilder::append_escaped_for_json(const StringView& string) { for (auto ch : string) { diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h index 1ad64d4f39..bc0470a211 100644 --- a/AK/StringBuilder.h +++ b/AK/StringBuilder.h @@ -28,6 +28,7 @@ public: void append(const char*, size_t); void appendvf(const char*, va_list); + void append_as_lowercase(char); void append_escaped_for_json(const StringView&); template<typename... Parameters> |