/* * Copyright (c) 2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include namespace Kernel { class KString { AK_MAKE_NONCOPYABLE(KString); AK_MAKE_NONMOVABLE(KString); public: static OwnPtr try_create_uninitialized(size_t, char*&); static NonnullOwnPtr must_create_uninitialized(size_t, char*&); static OwnPtr try_create(StringView const&); static NonnullOwnPtr must_create(StringView const&); void operator delete(void*); OwnPtr try_clone() const; bool is_empty() const { return m_length == 0; } size_t length() const { return m_length; } char const* characters() const { return m_characters; } StringView view() const { return { characters(), length() }; } private: explicit KString(size_t length) : m_length(length) { } size_t m_length { 0 }; char m_characters[0]; }; } namespace AK { template<> struct Formatter : Formatter { void format(FormatBuilder& builder, Kernel::KString const& value) { Formatter::format(builder, value.characters()); } }; }