2022-01-29 23:47:29 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
#include <AK/DeprecatedString.h>
|
2022-01-29 23:47:29 +02:00
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
|
|
|
|
|
|
namespace JS::Intl {
|
|
|
|
|
|
|
|
|
|
class Segmenter final : public Object {
|
|
|
|
|
JS_OBJECT(Segmenter, Object);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
enum class SegmenterGranularity {
|
|
|
|
|
Grapheme,
|
|
|
|
|
Word,
|
|
|
|
|
Sentence,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
virtual ~Segmenter() override = default;
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString const& locale() const { return m_locale; }
|
|
|
|
|
void set_locale(DeprecatedString locale) { m_locale = move(locale); }
|
2022-01-29 23:47:29 +02:00
|
|
|
|
|
|
|
|
SegmenterGranularity segmenter_granularity() const { return m_segmenter_granularity; }
|
|
|
|
|
void set_segmenter_granularity(StringView);
|
|
|
|
|
StringView segmenter_granularity_string() const;
|
|
|
|
|
|
|
|
|
|
private:
|
2022-08-28 23:51:28 +02:00
|
|
|
explicit Segmenter(Object& prototype);
|
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_locale; // [[Locale]]
|
2022-01-29 23:47:29 +02:00
|
|
|
SegmenterGranularity m_segmenter_granularity { SegmenterGranularity::Grapheme }; // [[SegmenterGranularity]]
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-07 12:24:05 -05:00
|
|
|
ThrowCompletionOr<NonnullGCPtr<Object>> create_segment_data_object(VM&, Segmenter const&, Utf16View const&, double start_index, double end_index);
|
2022-01-30 20:39:26 +02:00
|
|
|
enum class Direction {
|
|
|
|
|
Before,
|
|
|
|
|
After,
|
|
|
|
|
};
|
|
|
|
|
double find_boundary(Segmenter const&, Utf16View const&, double start_index, Direction, Optional<Vector<size_t>>& boundaries_cache);
|
|
|
|
|
|
2022-01-29 23:47:29 +02:00
|
|
|
}
|