/* * Copyright (c) 2021-2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace JS { namespace Detail { class Utf16StringImpl : public RefCounted { public: ~Utf16StringImpl() = default; static ThrowCompletionOr> create(VM&); static ThrowCompletionOr> create(VM&, Utf16Data); static ThrowCompletionOr> create(VM&, StringView); static ThrowCompletionOr> create(VM&, Utf16View const&); Utf16Data const& string() const; Utf16View view() const; private: Utf16StringImpl() = default; explicit Utf16StringImpl(Utf16Data string); Utf16Data m_string; }; } class Utf16String { public: static ThrowCompletionOr create(VM&); static ThrowCompletionOr create(VM&, Utf16Data); static ThrowCompletionOr create(VM&, StringView); static ThrowCompletionOr create(VM&, Utf16View const&); Utf16Data const& string() const; Utf16View view() const; Utf16View substring_view(size_t code_unit_offset, size_t code_unit_length) const; Utf16View substring_view(size_t code_unit_offset) const; ThrowCompletionOr to_utf8(VM&) const; u16 code_unit_at(size_t index) const; size_t length_in_code_units() const; bool is_empty() const; private: explicit Utf16String(NonnullRefPtr); NonnullRefPtr m_string; }; }