summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-01-31 18:41:44 +0200
committerIdan Horowitz <idan.horowitz@gmail.com>2022-01-31 21:05:04 +0200
commitb1d19b5917e42022669403b6983215e2680b4067 (patch)
tree17bb9ed74afda02138d109db64d3922b5cec45f4
parent4967bcd4ce32f35144ee2b9b5bfe6980981e553a (diff)
downloadserenity-b1d19b5917e42022669403b6983215e2680b4067.zip
LibJS: Convert Intl.Segmenter, Segments and SegmentIterator to Utf16
This is a precursor to implementing the FindBoundary AO, which operates on Utf16 code unit indexes.
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp6
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.h9
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/Segments.h10
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp2
6 files changed, 17 insertions, 16 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp
index 4c3be7e6de..2d848e8adb 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.cpp
@@ -10,7 +10,7 @@
namespace JS::Intl {
// 18.6.1 CreateSegmentIterator ( segmenter, string ), https://tc39.es/ecma402/#sec-createsegmentsobject
-SegmentIterator* SegmentIterator::create(GlobalObject& global_object, Segmenter& segmenter, String string)
+SegmentIterator* SegmentIterator::create(GlobalObject& global_object, Segmenter& segmenter, Utf16View const& string)
{
// 1. Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]], [[IteratedStringNextSegmentCodeUnitIndex]] ».
// 2. Let iterator be ! OrdinaryObjectCreate(%SegmentIteratorPrototype%, internalSlotsList).
@@ -22,10 +22,10 @@ SegmentIterator* SegmentIterator::create(GlobalObject& global_object, Segmenter&
}
// 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects
-SegmentIterator::SegmentIterator(GlobalObject& global_object, Segmenter& segmenter, String string)
+SegmentIterator::SegmentIterator(GlobalObject& global_object, Segmenter& segmenter, Utf16View const& string)
: Object(*global_object.intl_segment_iterator_prototype())
, m_iterating_segmenter(segmenter)
- , m_iterated_string(move(string))
+ , m_iterated_string(string)
{
}
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.h b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.h
index 30cd05488b..953141b352 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmentIterator.h
@@ -6,6 +6,7 @@
#pragma once
+#include <AK/Utf16View.h>
#include <LibJS/Runtime/Intl/Segmenter.h>
#include <LibJS/Runtime/Object.h>
@@ -15,20 +16,20 @@ class SegmentIterator final : public Object {
JS_OBJECT(SegmentIterator, Object);
public:
- static SegmentIterator* create(GlobalObject&, Segmenter&, String);
+ static SegmentIterator* create(GlobalObject&, Segmenter&, Utf16View const&);
- SegmentIterator(GlobalObject&, Segmenter&, String);
+ SegmentIterator(GlobalObject&, Segmenter&, Utf16View const&);
virtual ~SegmentIterator() override = default;
Segmenter const& iterating_segmenter() const { return m_iterating_segmenter; }
- String const& iterated_string() const { return m_iterated_string; }
+ Utf16View const& iterated_string() const { return m_iterated_string; }
size_t iterated_string_next_segment_code_unit_index() const { return m_iterated_string_next_segment_code_unit_index; }
private:
virtual void visit_edges(Cell::Visitor&) override;
Segmenter& m_iterating_segmenter; // [[IteratingSegmenter]]
- String m_iterated_string; // [[IteratedString]]
+ Utf16View m_iterated_string; // [[IteratedString]]
size_t m_iterated_string_next_segment_code_unit_index { 0 }; // [[IteratedStringNextSegmentCodeUnitIndex]]
};
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp
index 6b1d3ffcae..2dd67d0cb7 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmenterPrototype.cpp
@@ -61,7 +61,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::segment)
auto* segmenter = TRY(typed_this_object(global_object));
// 3. Let string be ? ToString(string).
- auto string = TRY(vm.argument(0).to_string(global_object));
+ auto string = TRY(vm.argument(0).to_utf16_string(global_object));
// 4. Return ! CreateSegmentsObject(segmenter, string).
return Segments::create(global_object, *segmenter, move(string));
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp b/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp
index 31907e1edb..dd53cc3d27 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Segments.cpp
@@ -11,7 +11,7 @@
namespace JS::Intl {
// 18.5.1 CreateSegmentsObject ( segmenter, string ), https://tc39.es/ecma402/#sec-createsegmentsobject
-Segments* Segments::create(GlobalObject& global_object, Segmenter& segmenter, String string)
+Segments* Segments::create(GlobalObject& global_object, Segmenter& segmenter, Utf16String string)
{
// 1. Let internalSlotsList be « [[SegmentsSegmenter]], [[SegmentsString]] ».
// 2. Let segments be ! OrdinaryObjectCreate(%SegmentsPrototype%, internalSlotsList).
@@ -22,7 +22,7 @@ Segments* Segments::create(GlobalObject& global_object, Segmenter& segmenter, St
}
// 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects
-Segments::Segments(GlobalObject& global_object, Segmenter& segmenter, String string)
+Segments::Segments(GlobalObject& global_object, Segmenter& segmenter, Utf16String string)
: Object(*global_object.intl_segments_prototype())
, m_segments_segmenter(segmenter)
, m_segments_string(move(string))
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/Segments.h b/Userland/Libraries/LibJS/Runtime/Intl/Segments.h
index 26e1424495..970bcdaba0 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/Segments.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/Segments.h
@@ -6,7 +6,7 @@
#pragma once
-#include <AK/String.h>
+#include <AK/Utf16View.h>
#include <LibJS/Runtime/Intl/Segmenter.h>
#include <LibJS/Runtime/Object.h>
@@ -16,20 +16,20 @@ class Segments final : public Object {
JS_OBJECT(Segments, Object);
public:
- static Segments* create(GlobalObject&, Segmenter&, String);
+ static Segments* create(GlobalObject&, Segmenter&, Utf16String);
- Segments(GlobalObject&, Segmenter&, String);
+ Segments(GlobalObject&, Segmenter&, Utf16String);
virtual ~Segments() override = default;
Segmenter& segments_segmenter() const { return m_segments_segmenter; }
- String const& segments_string() const { return m_segments_string; }
+ Utf16View segments_string() const { return m_segments_string.view(); }
private:
virtual void visit_edges(Cell::Visitor&) override;
Segmenter& m_segments_segmenter; // [[SegmentsSegmenter]]
- String m_segments_string; // [[SegmentsString]]
+ Utf16String m_segments_string; // [[SegmentsString]]
};
}
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp
index 3141b65ea1..6d5870ff7f 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/SegmentsPrototype.cpp
@@ -38,7 +38,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::symbol_iterator)
auto& segmenter = segments->segments_segmenter();
// 4. Let string be segments.[[SegmentsString]].
- auto& string = segments->segments_string();
+ auto string = segments->segments_string();
// 5. Return ! CreateSegmentIterator(segmenter, string).
return SegmentIterator::create(global_object, segmenter, string);