ladybird/Userland/Libraries/LibJS/Runtime/Utf16String.h
Linus Groh 6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00

61 lines
1.4 KiB
C++

/*
* Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <AK/Types.h>
#include <AK/Vector.h>
namespace JS {
namespace Detail {
class Utf16StringImpl : public RefCounted<Utf16StringImpl> {
public:
~Utf16StringImpl() = default;
static NonnullRefPtr<Utf16StringImpl> create();
static NonnullRefPtr<Utf16StringImpl> create(Vector<u16, 1>);
static NonnullRefPtr<Utf16StringImpl> create(StringView);
static NonnullRefPtr<Utf16StringImpl> create(Utf16View const&);
Vector<u16, 1> const& string() const;
Utf16View view() const;
private:
Utf16StringImpl() = default;
explicit Utf16StringImpl(Vector<u16, 1> string);
Vector<u16, 1> m_string;
};
}
class Utf16String {
public:
Utf16String();
explicit Utf16String(Vector<u16, 1>);
explicit Utf16String(StringView);
explicit Utf16String(Utf16View const&);
Vector<u16, 1> 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;
DeprecatedString to_utf8() const;
u16 code_unit_at(size_t index) const;
size_t length_in_code_units() const;
bool is_empty() const;
private:
NonnullRefPtr<Detail::Utf16StringImpl> m_string;
};
}