6#error Internationalization is expected to be enabled.
15#include "unicode/brkiter.h"
23 Factory* factory = isolate->factory();
29 std::vector<std::string> requested_locales =
33 if (IsUndefined(*options_obj, isolate)) {
48 requested_locales, matcher, {});
55 enum class Type { CHARACTER, WORD, SENTENCE, LINE };
57 isolate, options,
"type", service,
58 {
"word",
"character",
"sentence",
"line"},
59 {Type::WORD, Type::CHARACTER, Type::SENTENCE, Type::LINE}, Type::WORD);
63 icu::Locale icu_locale =
r.icu_locale;
64 DCHECK(!icu_locale.isBogus());
67 UErrorCode status = U_ZERO_ERROR;
68 std::unique_ptr<icu::BreakIterator> break_iterator =
nullptr;
72 icu::BreakIterator::createCharacterInstance(icu_locale, status));
76 icu::BreakIterator::createSentenceInstance(icu_locale, status));
82 icu::BreakIterator::createLineInstance(icu_locale, status));
88 icu::BreakIterator::createWordInstance(icu_locale, status));
93 if (U_FAILURE(status) || break_iterator ==
nullptr) {
105 isolate->factory()->NewStringFromAsciiChecked(
r.locale.c_str());
110 isolate->factory()->NewFastOrSlowJSObjectFromMap(map));
112 break_iterator_holder->set_locale(*locale_str);
113 break_iterator_holder->set_break_iterator(*managed_break_iterator);
114 break_iterator_holder->set_unicode_string(*managed_unicode_string);
117 return break_iterator_holder;
122 Factory* factory = isolate->factory();
123 const auto as_string = [
isolate](icu::BreakIterator* break_iterator) {
132 std::unique_ptr<icu::BreakIterator> cloned_break_iterator(
133 break_iterator->clone());
139 icu::UnicodeString
data(
"He is.");
140 cloned_break_iterator->setText(data);
141 switch (cloned_break_iterator->next()) {
143 return isolate->factory()->character_string();
145 return isolate->factory()->word_string();
147 return isolate->factory()->line_string();
149 return isolate->factory()->sentence_string();
162 as_string(break_iterator->break_iterator()->raw()),
170 icu::BreakIterator* break_iterator =
171 break_iterator_holder->break_iterator()->raw();
180 return isolate->factory()->NewNumberFromInt(
181 break_iterator->break_iterator()->raw()->current());
186 return isolate->factory()->NewNumberFromInt(
187 break_iterator->break_iterator()->raw()->first());
192 return isolate->factory()->NewNumberFromInt(
193 break_iterator->break_iterator()->raw()->next());
198 int32_t status = break_iterator->break_iterator()->raw()->getRuleStatus();
200 if (status >= UBRK_WORD_NONE && status < UBRK_WORD_NONE_LIMIT) {
203 if (status >= UBRK_WORD_NUMBER && status < UBRK_WORD_NUMBER_LIMIT) {
206 if (status >= UBRK_WORD_LETTER && status < UBRK_WORD_LETTER_LIMIT) {
209 if (status >= UBRK_WORD_KANA && status < UBRK_WORD_KANA_LIMIT) {
212 if (status >= UBRK_WORD_IDEO && status < UBRK_WORD_IDEO_LIMIT) {
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
V8_INLINE T FromJust() const &
V8_INLINE bool IsNothing() const
Handle< JSObject > NewJSObjectWithNullProto()
Handle< JSObject > NewJSObject(DirectHandle< JSFunction > constructor, AllocationType allocation=AllocationType::kYoung, NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
static const std::set< std::string > & GetAvailableLocales()
static Maybe< std::vector< std::string > > CanonicalizeLocaleList(Isolate *isolate, DirectHandle< Object > locales, bool only_return_one_result=false)
static Maybe< ResolvedLocale > ResolveLocale(Isolate *isolate, const std::set< std::string > &available_locales, const std::vector< std::string > &requested_locales, MatcherOption options, const std::set< std::string > &relevant_extension_keys)
static V8_WARN_UNUSED_RESULT Maybe< MatcherOption > GetLocaleMatcher(Isolate *isolate, DirectHandle< JSReceiver > options, const char *method_name)
static DirectHandle< Managed< icu::UnicodeString > > SetTextToBreakIterator(Isolate *isolate, DirectHandle< String > text, icu::BreakIterator *break_iterator)
static V8_EXPORT_PRIVATE void AddProperty(Isolate *isolate, DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > value, PropertyAttributes attributes)
static Tagged< String > BreakType(Isolate *isolate, DirectHandle< JSV8BreakIterator > break_iterator)
static DirectHandle< JSObject > ResolvedOptions(Isolate *isolate, DirectHandle< JSV8BreakIterator > break_iterator)
static DirectHandle< Object > Current(Isolate *isolate, DirectHandle< JSV8BreakIterator > break_iterator)
static V8_EXPORT_PRIVATE const std::set< std::string > & GetAvailableLocales()
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSV8BreakIterator > New(Isolate *isolate, DirectHandle< Map > map, DirectHandle< Object > input_locales, DirectHandle< Object > input_options, const char *service)
static DirectHandle< Object > Next(Isolate *isolate, DirectHandle< JSV8BreakIterator > break_iterator)
static DirectHandle< Object > First(Isolate *isolate, DirectHandle< JSV8BreakIterator > break_iterator)
static void AdoptText(Isolate *isolate, DirectHandle< JSV8BreakIterator > break_iterator, DirectHandle< String > text)
static DirectHandle< Managed< CppType > > From(Isolate *isolate, size_t estimated_size, std::shared_ptr< CppType > shared_ptr, AllocationType allocation_type=AllocationType::kYoung)
static V8_WARN_UNUSED_RESULT HandleType< JSReceiver >::MaybeType ToObject(Isolate *isolate, HandleType< T > object, const char *method_name=nullptr)
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call)
#define THROW_NEW_ERROR(isolate, call)
#define MAYBE_RETURN(call, value)
DirectHandle< JSReceiver > options
ZoneVector< RpoNumber > & result
Maybe< bool > GetStringOption(Isolate *isolate, DirectHandle< JSReceiver > options, const char *property, const std::vector< const char * > &values, const char *method_name, std::unique_ptr< char[]> *result)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
#define DCHECK_NOT_NULL(val)
#define DCHECK(condition)