2022-01-30 02:18:47 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-01-31 18:41:44 +02:00
|
|
|
#include <AK/Utf16View.h>
|
2022-01-30 02:18:47 +02:00
|
|
|
#include <LibJS/Runtime/Intl/Segmenter.h>
|
|
|
|
#include <LibJS/Runtime/Object.h>
|
2024-06-23 09:14:27 -04:00
|
|
|
#include <LibUnicode/Segmenter.h>
|
2022-01-30 02:18:47 +02:00
|
|
|
|
|
|
|
namespace JS::Intl {
|
|
|
|
|
|
|
|
class SegmentIterator final : public Object {
|
|
|
|
JS_OBJECT(SegmentIterator, Object);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(SegmentIterator);
|
2022-01-30 02:18:47 +02:00
|
|
|
|
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
static GC::Ref<SegmentIterator> create(Realm&, Unicode::Segmenter const&, Utf16View const&, Segments const&);
|
2022-01-30 02:18:47 +02:00
|
|
|
|
|
|
|
virtual ~SegmentIterator() override = default;
|
|
|
|
|
2024-06-23 09:14:27 -04:00
|
|
|
Unicode::Segmenter& iterating_segmenter() { return *m_iterating_segmenter; }
|
2022-01-31 18:41:44 +02:00
|
|
|
Utf16View const& iterated_string() const { return m_iterated_string; }
|
2024-06-18 18:51:06 -04:00
|
|
|
size_t iterated_string_next_segment_code_unit_index() const { return m_iterating_segmenter->current_boundary(); }
|
2022-01-30 21:34:41 +02:00
|
|
|
|
|
|
|
Segments const& segments() { return m_segments; }
|
2022-01-30 02:18:47 +02:00
|
|
|
|
|
|
|
private:
|
2024-06-23 09:14:27 -04:00
|
|
|
SegmentIterator(Realm&, Unicode::Segmenter const&, Utf16View const&, Segments const&);
|
2022-08-28 23:51:28 +02:00
|
|
|
|
2022-01-30 02:18:47 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2024-06-23 09:14:27 -04:00
|
|
|
NonnullOwnPtr<Unicode::Segmenter> m_iterating_segmenter; // [[IteratingSegmenter]]
|
|
|
|
Utf16View m_iterated_string; // [[IteratedString]]
|
2022-01-30 21:34:41 +02:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Segments const> m_segments;
|
2022-01-30 02:18:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|