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.
This commit is contained in:
Idan Horowitz 2022-02-16 00:23:34 +02:00 committed by Andreas Kling
parent 43e5c326e2
commit 8f093e91e0
2 changed files with 15 additions and 2 deletions

View file

@ -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)
{

View file

@ -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;