2020-07-29 15:06:31 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
2018-10-05 01:57:05 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2020-07-29 15:06:31 +00:00
|
|
|
#ifndef V8_OBJECTS_JS_SEGMENTER_H_
|
|
|
|
#define V8_OBJECTS_JS_SEGMENTER_H_
|
2018-10-05 01:57:05 +00:00
|
|
|
|
|
|
|
#ifndef V8_INTL_SUPPORT
|
|
|
|
#error Internationalization is expected to be enabled.
|
|
|
|
#endif // V8_INTL_SUPPORT
|
|
|
|
|
2018-10-24 00:56:40 +00:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
|
2019-11-15 11:58:57 +00:00
|
|
|
#include "src/base/bit-field.h"
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/isolate.h"
|
2018-10-05 01:57:05 +00:00
|
|
|
#include "src/heap/factory.h"
|
|
|
|
#include "src/objects/managed.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects.h"
|
2018-10-05 01:57:05 +00:00
|
|
|
#include "unicode/uversion.h"
|
|
|
|
|
|
|
|
// Has to be the last include (doesn't have include guards):
|
|
|
|
#include "src/objects/object-macros.h"
|
|
|
|
|
|
|
|
namespace U_ICU_NAMESPACE {
|
|
|
|
class BreakIterator;
|
2020-08-13 15:50:17 +00:00
|
|
|
} // namespace U_ICU_NAMESPACE
|
2018-10-05 01:57:05 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2020-10-28 16:09:52 +00:00
|
|
|
#include "torque-generated/src/objects/js-segmenter-tq.inc"
|
|
|
|
|
2020-05-08 16:35:16 +00:00
|
|
|
class JSSegmenter : public TorqueGeneratedJSSegmenter<JSSegmenter, JSObject> {
|
2018-10-05 01:57:05 +00:00
|
|
|
public:
|
2019-06-12 15:37:29 +00:00
|
|
|
// Creates segmenter object with properties derived from input locales and
|
|
|
|
// options.
|
|
|
|
V8_WARN_UNUSED_RESULT static MaybeHandle<JSSegmenter> New(
|
|
|
|
Isolate* isolate, Handle<Map> map, Handle<Object> locales,
|
|
|
|
Handle<Object> options);
|
2018-10-05 01:57:05 +00:00
|
|
|
|
|
|
|
V8_WARN_UNUSED_RESULT static Handle<JSObject> ResolvedOptions(
|
|
|
|
Isolate* isolate, Handle<JSSegmenter> segmenter_holder);
|
|
|
|
|
2019-04-04 08:51:47 +00:00
|
|
|
V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
|
2018-10-24 00:56:40 +00:00
|
|
|
|
2020-07-29 15:06:31 +00:00
|
|
|
Handle<String> GranularityAsString(Isolate* isolate) const;
|
2018-10-05 01:57:05 +00:00
|
|
|
|
|
|
|
// Segmenter accessors.
|
2019-01-08 12:58:31 +00:00
|
|
|
DECL_ACCESSORS(icu_break_iterator, Managed<icu::BreakIterator>)
|
2018-10-05 01:57:05 +00:00
|
|
|
|
|
|
|
// Granularity: identifying the segmenter used.
|
|
|
|
//
|
|
|
|
// ecma402 #sec-segmenter-internal-slots
|
|
|
|
enum class Granularity {
|
|
|
|
GRAPHEME, // for character-breaks
|
|
|
|
WORD, // for word-breaks
|
2019-07-19 21:29:44 +00:00
|
|
|
SENTENCE // for sentence-breaks
|
2018-10-05 01:57:05 +00:00
|
|
|
};
|
|
|
|
inline void set_granularity(Granularity granularity);
|
|
|
|
inline Granularity granularity() const;
|
|
|
|
|
2020-07-29 15:06:31 +00:00
|
|
|
Handle<String> static GetGranularityString(Isolate* isolate,
|
|
|
|
Granularity granularity);
|
|
|
|
|
2020-02-26 20:12:38 +00:00
|
|
|
// Bit positions in |flags|.
|
|
|
|
DEFINE_TORQUE_GENERATED_JS_SEGMENTER_FLAGS()
|
2018-10-05 01:57:05 +00:00
|
|
|
|
|
|
|
STATIC_ASSERT(Granularity::GRAPHEME <= GranularityBits::kMax);
|
|
|
|
STATIC_ASSERT(Granularity::WORD <= GranularityBits::kMax);
|
|
|
|
STATIC_ASSERT(Granularity::SENTENCE <= GranularityBits::kMax);
|
|
|
|
|
|
|
|
DECL_PRINTER(JSSegmenter)
|
|
|
|
|
2020-05-08 16:35:16 +00:00
|
|
|
TQ_OBJECT_CONSTRUCTORS(JSSegmenter)
|
2018-10-05 01:57:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#include "src/objects/object-macros-undef.h"
|
|
|
|
|
|
|
|
#endif // V8_OBJECTS_JS_SEGMENTER_H_
|