2021-08-09 08:58:31 -04:00
|
|
|
/*
|
2023-01-06 11:00:24 -05:00
|
|
|
* Copyright (c) 2021-2023, Tim Flynn <trflynn89@serenityos.org>
|
2021-08-09 08:58:31 -04:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
#include <AK/ByteString.h>
|
2021-08-09 08:58:31 -04:00
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
|
|
|
#include <AK/RefCounted.h>
|
|
|
|
|
#include <AK/Types.h>
|
2023-01-06 11:00:24 -05:00
|
|
|
#include <AK/Utf16View.h>
|
2021-08-09 08:58:31 -04:00
|
|
|
#include <AK/Vector.h>
|
2023-01-07 13:59:10 -05:00
|
|
|
#include <LibJS/Runtime/Completion.h>
|
2021-08-09 08:58:31 -04:00
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
namespace Detail {
|
|
|
|
|
|
|
|
|
|
class Utf16StringImpl : public RefCounted<Utf16StringImpl> {
|
|
|
|
|
public:
|
|
|
|
|
~Utf16StringImpl() = default;
|
|
|
|
|
|
2023-08-08 18:54:20 +02:00
|
|
|
[[nodiscard]] static NonnullRefPtr<Utf16StringImpl> create();
|
|
|
|
|
[[nodiscard]] static NonnullRefPtr<Utf16StringImpl> create(Utf16Data);
|
|
|
|
|
[[nodiscard]] static NonnullRefPtr<Utf16StringImpl> create(StringView);
|
|
|
|
|
[[nodiscard]] static NonnullRefPtr<Utf16StringImpl> create(Utf16View const&);
|
2021-08-09 08:58:31 -04:00
|
|
|
|
2023-01-06 11:00:24 -05:00
|
|
|
Utf16Data const& string() const;
|
2021-08-09 08:58:31 -04:00
|
|
|
Utf16View view() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Utf16StringImpl() = default;
|
2023-01-06 11:00:24 -05:00
|
|
|
explicit Utf16StringImpl(Utf16Data string);
|
2021-08-09 08:58:31 -04:00
|
|
|
|
2023-01-06 11:00:24 -05:00
|
|
|
Utf16Data m_string;
|
2021-08-09 08:58:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Utf16String {
|
|
|
|
|
public:
|
2023-08-08 18:54:20 +02:00
|
|
|
[[nodiscard]] static Utf16String create();
|
|
|
|
|
[[nodiscard]] static Utf16String create(Utf16Data);
|
|
|
|
|
[[nodiscard]] static Utf16String create(StringView);
|
|
|
|
|
[[nodiscard]] static Utf16String create(Utf16View const&);
|
2021-08-09 08:58:31 -04:00
|
|
|
|
2023-01-06 11:00:24 -05:00
|
|
|
Utf16Data const& string() const;
|
2021-08-09 08:58:31 -04:00
|
|
|
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;
|
|
|
|
|
|
2023-08-08 18:54:20 +02:00
|
|
|
[[nodiscard]] String to_utf8() const;
|
2023-12-16 17:49:34 +03:30
|
|
|
[[nodiscard]] ByteString to_byte_string() const;
|
2021-08-09 08:58:31 -04:00
|
|
|
u16 code_unit_at(size_t index) const;
|
|
|
|
|
|
|
|
|
|
size_t length_in_code_units() const;
|
|
|
|
|
bool is_empty() const;
|
|
|
|
|
|
|
|
|
|
private:
|
2023-01-07 12:24:05 -05:00
|
|
|
explicit Utf16String(NonnullRefPtr<Detail::Utf16StringImpl>);
|
|
|
|
|
|
2021-08-09 08:58:31 -04:00
|
|
|
NonnullRefPtr<Detail::Utf16StringImpl> m_string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|