summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-01-06 11:00:24 -0500
committerLinus Groh <mail@linusgroh.de>2023-01-08 12:13:15 +0100
commit425c168dedf0138cb5d5a96c1d5cccce80afe030 (patch)
tree43f41ce3639899e4e548e3c8d114e0dacf5de7f8 /Userland/Libraries/LibJS
parent39bda0073edb4a95d3192879157c48e094bd89af (diff)
downloadserenity-425c168dedf0138cb5d5a96c1d5cccce80afe030.zip
AK+LibJS+LibRegex: Define an alias for UTF-16 string data storage
Instead of writing out "Vector<u16, 1>" everywhere, let's have a name for it.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringConstructor.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringPrototype.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Utf16String.cpp15
-rw-r--r--Userland/Libraries/LibJS/Runtime/Utf16String.h15
6 files changed, 20 insertions, 20 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
index 4db6c8529b..ddf89aee18 100644
--- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
@@ -1233,7 +1233,7 @@ ThrowCompletionOr<DeprecatedString> get_substitution(VM& vm, Utf16View const& ma
auto replace_string = TRY(replacement_template.to_utf16_string(vm));
auto replace_view = replace_string.view();
- Vector<u16, 1> result;
+ Utf16Data result;
for (size_t i = 0; i < replace_view.length_in_code_units(); ++i) {
u16 curr = replace_view.code_unit_at(i);
diff --git a/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp b/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp
index cecc841b6e..c29c4b0cc8 100644
--- a/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp
+++ b/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp
@@ -180,7 +180,7 @@ void PrimitiveString::resolve_rope_if_needed() const
auto const& lhs_string = m_lhs->utf16_string();
auto const& rhs_string = m_rhs->utf16_string();
- Vector<u16, 1> combined;
+ Utf16Data combined;
combined.ensure_capacity(lhs_string.length_in_code_units() + rhs_string.length_in_code_units());
combined.extend(lhs_string.string());
combined.extend(rhs_string.string());
diff --git a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp
index 9fd6b22f3c..ca6e5130ea 100644
--- a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp
@@ -100,7 +100,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw)
// 22.1.2.1 String.fromCharCode ( ...codeUnits ), https://tc39.es/ecma262/#sec-string.fromcharcode
JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_char_code)
{
- Vector<u16, 1> string;
+ Utf16Data string;
string.ensure_capacity(vm.argument_count());
for (size_t i = 0; i < vm.argument_count(); ++i)
@@ -112,7 +112,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_char_code)
// 22.1.2.2 String.fromCodePoint ( ...codePoints ), https://tc39.es/ecma262/#sec-string.fromcodepoint
JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_code_point)
{
- Vector<u16, 1> string;
+ Utf16Data string;
string.ensure_capacity(vm.argument_count()); // This will be an under-estimate if any code point is > 0xffff.
for (size_t i = 0; i < vm.argument_count(); ++i) {
diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
index 9f2ccd6a2c..c43706bbb7 100644
--- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp
@@ -518,7 +518,7 @@ static ThrowCompletionOr<Value> pad_string(VM& vm, Utf16String string, PadPlacem
if (max_length <= string_length)
return PrimitiveString::create(vm, move(string));
- Utf16String fill_string(Vector<u16, 1> { 0x20 });
+ Utf16String fill_string(Utf16Data { 0x20 });
if (!vm.argument(1).is_undefined()) {
fill_string = TRY(vm.argument(1).to_utf16_string(vm));
if (fill_string.is_empty())
diff --git a/Userland/Libraries/LibJS/Runtime/Utf16String.cpp b/Userland/Libraries/LibJS/Runtime/Utf16String.cpp
index b9aacbaa5e..821dc88db4 100644
--- a/Userland/Libraries/LibJS/Runtime/Utf16String.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Utf16String.cpp
@@ -1,11 +1,10 @@
/*
- * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
+ * Copyright (c) 2021-2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/StringView.h>
-#include <AK/Utf16View.h>
#include <LibJS/Runtime/Utf16String.h>
namespace JS {
@@ -17,7 +16,7 @@ static NonnullRefPtr<Utf16StringImpl> the_empty_utf16_string()
return empty_string;
}
-Utf16StringImpl::Utf16StringImpl(Vector<u16, 1> string)
+Utf16StringImpl::Utf16StringImpl(Utf16Data string)
: m_string(move(string))
{
}
@@ -27,7 +26,7 @@ NonnullRefPtr<Utf16StringImpl> Utf16StringImpl::create()
return adopt_ref(*new Utf16StringImpl());
}
-NonnullRefPtr<Utf16StringImpl> Utf16StringImpl::create(Vector<u16, 1> string)
+NonnullRefPtr<Utf16StringImpl> Utf16StringImpl::create(Utf16Data string)
{
return adopt_ref(*new Utf16StringImpl(move(string)));
}
@@ -39,13 +38,13 @@ NonnullRefPtr<Utf16StringImpl> Utf16StringImpl::create(StringView string)
NonnullRefPtr<Utf16StringImpl> Utf16StringImpl::create(Utf16View const& view)
{
- Vector<u16, 1> string;
+ Utf16Data string;
string.ensure_capacity(view.length_in_code_units());
string.append(view.data(), view.length_in_code_units());
return create(move(string));
}
-Vector<u16, 1> const& Utf16StringImpl::string() const
+Utf16Data const& Utf16StringImpl::string() const
{
return m_string;
}
@@ -62,7 +61,7 @@ Utf16String::Utf16String()
{
}
-Utf16String::Utf16String(Vector<u16, 1> string)
+Utf16String::Utf16String(Utf16Data string)
: m_string(Detail::Utf16StringImpl::create(move(string)))
{
}
@@ -77,7 +76,7 @@ Utf16String::Utf16String(Utf16View const& string)
{
}
-Vector<u16, 1> const& Utf16String::string() const
+Utf16Data const& Utf16String::string() const
{
return m_string->string();
}
diff --git a/Userland/Libraries/LibJS/Runtime/Utf16String.h b/Userland/Libraries/LibJS/Runtime/Utf16String.h
index 32ffa733c8..fdcc014252 100644
--- a/Userland/Libraries/LibJS/Runtime/Utf16String.h
+++ b/Userland/Libraries/LibJS/Runtime/Utf16String.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
+ * Copyright (c) 2021-2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -10,6 +10,7 @@
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <AK/Types.h>
+#include <AK/Utf16View.h>
#include <AK/Vector.h>
namespace JS {
@@ -20,18 +21,18 @@ public:
~Utf16StringImpl() = default;
static NonnullRefPtr<Utf16StringImpl> create();
- static NonnullRefPtr<Utf16StringImpl> create(Vector<u16, 1>);
+ static NonnullRefPtr<Utf16StringImpl> create(Utf16Data);
static NonnullRefPtr<Utf16StringImpl> create(StringView);
static NonnullRefPtr<Utf16StringImpl> create(Utf16View const&);
- Vector<u16, 1> const& string() const;
+ Utf16Data const& string() const;
Utf16View view() const;
private:
Utf16StringImpl() = default;
- explicit Utf16StringImpl(Vector<u16, 1> string);
+ explicit Utf16StringImpl(Utf16Data string);
- Vector<u16, 1> m_string;
+ Utf16Data m_string;
};
}
@@ -39,11 +40,11 @@ private:
class Utf16String {
public:
Utf16String();
- explicit Utf16String(Vector<u16, 1>);
+ explicit Utf16String(Utf16Data);
explicit Utf16String(StringView);
explicit Utf16String(Utf16View const&);
- Vector<u16, 1> const& string() 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;