summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-02-16 00:23:34 +0200
committerAndreas Kling <kling@serenityos.org>2022-02-16 22:21:37 +0100
commit8f093e91e068cb2952a456566879bda81401c782 (patch)
treef426b127e44dc18408f457ae46f62168e44f0d73
parent43e5c326e2511dcc92a8e06c4429cc6bf447ab4a (diff)
downloadserenity-8f093e91e068cb2952a456566879bda81401c782.zip
AK: Exclude StringBuilder String APIs from the Kernel
These APIs are only used by userland, and String is OOM-infallible, so let's just ifdef it out of the Kernel.
-rw-r--r--AK/StringBuilder.cpp11
-rw-r--r--AK/StringBuilder.h6
2 files changed, 15 insertions, 2 deletions
diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp
index 22c31507b2..e537e57c19 100644
--- a/AK/StringBuilder.cpp
+++ b/AK/StringBuilder.cpp
@@ -8,13 +8,16 @@
#include <AK/Checked.h>
#include <AK/PrintfImplementation.h>
#include <AK/StdLibExtras.h>
-#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/StringView.h>
#include <AK/UnicodeUtils.h>
-#include <AK/Utf16View.h>
#include <AK/Utf32View.h>
+#ifndef KERNEL
+# include <AK/String.h>
+# include <AK/Utf16View.h>
+#endif
+
namespace AK {
inline ErrorOr<void> StringBuilder::will_append(size_t size)
@@ -87,6 +90,7 @@ ByteBuffer StringBuilder::to_byte_buffer() const
return ByteBuffer::copy(data(), length()).release_value_but_fixme_should_propagate_errors();
}
+#ifndef KERNEL
String StringBuilder::to_string() const
{
if (is_empty())
@@ -98,6 +102,7 @@ String StringBuilder::build() const
{
return to_string();
}
+#endif
StringView StringBuilder::string_view() const
{
@@ -125,6 +130,7 @@ void StringBuilder::append_code_point(u32 code_point)
MUST(try_append_code_point(code_point));
}
+#ifndef KERNEL
ErrorOr<void> StringBuilder::try_append(Utf16View const& utf16_view)
{
for (size_t i = 0; i < utf16_view.length_in_code_units();) {
@@ -140,6 +146,7 @@ void StringBuilder::append(Utf16View const& utf16_view)
{
MUST(try_append(utf16_view));
}
+#endif
ErrorOr<void> StringBuilder::try_append(Utf32View const& utf32_view)
{
diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h
index c7e81e8625..6abf6d99a2 100644
--- a/AK/StringBuilder.h
+++ b/AK/StringBuilder.h
@@ -22,7 +22,9 @@ public:
~StringBuilder() = default;
ErrorOr<void> try_append(StringView);
+#ifndef KERNEL
ErrorOr<void> try_append(Utf16View const&);
+#endif
ErrorOr<void> try_append(Utf32View const&);
ErrorOr<void> try_append_code_point(u32);
ErrorOr<void> try_append(char);
@@ -35,7 +37,9 @@ public:
ErrorOr<void> try_append(char const*, size_t);
void append(StringView);
+#ifndef KERNEL
void append(Utf16View const&);
+#endif
void append(Utf32View const&);
void append(char);
void append_code_point(u32);
@@ -52,8 +56,10 @@ public:
MUST(vformat(*this, fmtstr.view(), variadic_format_params));
}
+#ifndef KERNEL
[[nodiscard]] String build() const;
[[nodiscard]] String to_string() const;
+#endif
[[nodiscard]] ByteBuffer to_byte_buffer() const;
[[nodiscard]] StringView string_view() const;