1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-21 23:35:07 +00:00
serenity/Userland/Libraries/LibJS/Runtime/Intl/Segmenter.h
Timothy Flynn 115baa7e32 LibJS+Everywhere: Make PrimitiveString and Utf16String fallible
This makes construction of Utf16String fallible in OOM conditions. The
immediate impact is that PrimitiveString must then be fallible as well,
as it may either transcode UTF-8 to UTF-16, or create a UTF-16 string
from ropes.

There are a couple of places where it is very non-trivial to propagate
the error further. A FIXME has been added to those locations.
2023-01-08 12:13:15 +01:00

47 lines
1.3 KiB
C++

/*
* Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/DeprecatedString.h>
#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;
DeprecatedString const& locale() const { return m_locale; }
void set_locale(DeprecatedString locale) { m_locale = move(locale); }
SegmenterGranularity segmenter_granularity() const { return m_segmenter_granularity; }
void set_segmenter_granularity(StringView);
StringView segmenter_granularity_string() const;
private:
explicit Segmenter(Object& prototype);
DeprecatedString m_locale; // [[Locale]]
SegmenterGranularity m_segmenter_granularity { SegmenterGranularity::Grapheme }; // [[SegmenterGranularity]]
};
ThrowCompletionOr<NonnullGCPtr<Object>> create_segment_data_object(VM&, Segmenter const&, Utf16View const&, double start_index, double end_index);
enum class Direction {
Before,
After,
};
double find_boundary(Segmenter const&, Utf16View const&, double start_index, Direction, Optional<Vector<size_t>>& boundaries_cache);
}