11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci#ifndef V8_OBJECTS_JS_SEGMENTER_H_
51cb0ef41Sopenharmony_ci#define V8_OBJECTS_JS_SEGMENTER_H_
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#ifndef V8_INTL_SUPPORT
81cb0ef41Sopenharmony_ci#error Internationalization is expected to be enabled.
91cb0ef41Sopenharmony_ci#endif  // V8_INTL_SUPPORT
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci#include <set>
121cb0ef41Sopenharmony_ci#include <string>
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci#include "src/base/bit-field.h"
151cb0ef41Sopenharmony_ci#include "src/execution/isolate.h"
161cb0ef41Sopenharmony_ci#include "src/heap/factory.h"
171cb0ef41Sopenharmony_ci#include "src/objects/managed.h"
181cb0ef41Sopenharmony_ci#include "src/objects/objects.h"
191cb0ef41Sopenharmony_ci#include "unicode/uversion.h"
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards):
221cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h"
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_cinamespace U_ICU_NAMESPACE {
251cb0ef41Sopenharmony_ciclass BreakIterator;
261cb0ef41Sopenharmony_ci}  // namespace U_ICU_NAMESPACE
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_cinamespace v8 {
291cb0ef41Sopenharmony_cinamespace internal {
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/js-segmenter-tq.inc"
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ciclass JSSegmenter : public TorqueGeneratedJSSegmenter<JSSegmenter, JSObject> {
341cb0ef41Sopenharmony_ci public:
351cb0ef41Sopenharmony_ci  // Creates segmenter object with properties derived from input locales and
361cb0ef41Sopenharmony_ci  // options.
371cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<JSSegmenter> New(
381cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<Map> map, Handle<Object> locales,
391cb0ef41Sopenharmony_ci      Handle<Object> options);
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static Handle<JSObject> ResolvedOptions(
421cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSSegmenter> segmenter_holder);
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci  Handle<String> GranularityAsString(Isolate* isolate) const;
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci  // Segmenter accessors.
491cb0ef41Sopenharmony_ci  DECL_ACCESSORS(icu_break_iterator, Managed<icu::BreakIterator>)
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  // Granularity: identifying the segmenter used.
521cb0ef41Sopenharmony_ci  //
531cb0ef41Sopenharmony_ci  // ecma402 #sec-segmenter-internal-slots
541cb0ef41Sopenharmony_ci  enum class Granularity {
551cb0ef41Sopenharmony_ci    GRAPHEME,  // for character-breaks
561cb0ef41Sopenharmony_ci    WORD,      // for word-breaks
571cb0ef41Sopenharmony_ci    SENTENCE   // for sentence-breaks
581cb0ef41Sopenharmony_ci  };
591cb0ef41Sopenharmony_ci  inline void set_granularity(Granularity granularity);
601cb0ef41Sopenharmony_ci  inline Granularity granularity() const;
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci  Handle<String> static GetGranularityString(Isolate* isolate,
631cb0ef41Sopenharmony_ci                                             Granularity granularity);
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci  // Bit positions in |flags|.
661cb0ef41Sopenharmony_ci  DEFINE_TORQUE_GENERATED_JS_SEGMENTER_FLAGS()
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ci  STATIC_ASSERT(Granularity::GRAPHEME <= GranularityBits::kMax);
691cb0ef41Sopenharmony_ci  STATIC_ASSERT(Granularity::WORD <= GranularityBits::kMax);
701cb0ef41Sopenharmony_ci  STATIC_ASSERT(Granularity::SENTENCE <= GranularityBits::kMax);
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci  DECL_PRINTER(JSSegmenter)
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(JSSegmenter)
751cb0ef41Sopenharmony_ci};
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci}  // namespace internal
781cb0ef41Sopenharmony_ci}  // namespace v8
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h"
811cb0ef41Sopenharmony_ci
821cb0ef41Sopenharmony_ci#endif  // V8_OBJECTS_JS_SEGMENTER_H_
83