summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Wipfli <mail@maxwipfli.ch>2021-05-11 15:48:37 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-18 21:02:07 +0200
commitf51b0729f519116c288b9bd9a1251daf66d7fa49 (patch)
tree039941ee62e1c459fbb731c93d3bc86f17086d08
parentdf29d58e19e1325badeacee51e5674ff6b9e1416 (diff)
downloadserenity-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.cpp8
-rw-r--r--AK/StringBuilder.h1
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>