1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_intl_LineBreaker_h__
6 #define mozilla_intl_LineBreaker_h__
9 #include "nsISupports.h"
11 #define NS_LINEBREAKER_NEED_MORE_TEXT -1
18 NS_INLINE_DECL_REFCOUNTING(LineBreaker
)
20 enum class WordBreak
: uint8_t {
21 Normal
= 0, // default
22 BreakAll
= 1, // break all
23 KeepAll
= 2 // always keep
26 enum class Strictness
: uint8_t {
34 static already_AddRefed
<LineBreaker
> Create();
36 int32_t Next(const char16_t
* aText
, uint32_t aLen
, uint32_t aPos
);
38 int32_t Prev(const char16_t
* aText
, uint32_t aLen
, uint32_t aPos
);
40 // Call this on a word with whitespace at either end. We will apply JISx4051
41 // rules to find breaks inside the word. aBreakBefore is set to the break-
42 // before status of each character; aBreakBefore[0] will always be false
43 // because we never return a break before the first character.
44 // aLength is the length of the aText array and also the length of the
45 // aBreakBefore output array.
46 void GetJISx4051Breaks(const char16_t
* aText
, uint32_t aLength
,
47 WordBreak aWordBreak
, Strictness aLevel
,
48 bool aIsChineseOrJapanese
, uint8_t* aBreakBefore
);
49 void GetJISx4051Breaks(const uint8_t* aText
, uint32_t aLength
,
50 WordBreak aWordBreak
, Strictness aLevel
,
51 bool aIsChineseOrJapanese
, uint8_t* aBreakBefore
);
54 ~LineBreaker() = default;
56 int32_t WordMove(const char16_t
* aText
, uint32_t aLen
, uint32_t aPos
,
60 static inline bool NS_IsSpace(char16_t u
) {
61 return u
== 0x0020 || // SPACE
62 u
== 0x0009 || // CHARACTER TABULATION
63 u
== 0x000D || // CARRIAGE RETURN
64 (0x2000 <= u
&& u
<= 0x2006) || // EN QUAD, EM QUAD, EN SPACE,
65 // EM SPACE, THREE-PER-EM SPACE,
66 // FOUR-PER-SPACE, SIX-PER-EM SPACE,
67 (0x2008 <= u
&& u
<= 0x200B) || // PUNCTUATION SPACE, THIN SPACE,
68 // HAIR SPACE, ZERO WIDTH SPACE
69 u
== 0x1361 || // ETHIOPIC WORDSPACE
70 u
== 0x1680 || // OGHAM SPACE MARK
71 u
== 0x205F; // MEDIUM MATHEMATICAL SPACE
74 static inline bool NS_NeedsPlatformNativeHandling(char16_t aChar
) {
76 #if ANDROID // Bug 1647377: no "platform native" support for Tibetan;
77 // better to just use our class-based breaker.
78 (0x0e01 <= aChar
&& aChar
<= 0x0eff) || // Thai, Lao
80 (0x0e01 <= aChar
&& aChar
<= 0x0fff) || // Thai, Lao, Tibetan
82 (0x1780 <= aChar
&& aChar
<= 0x17ff); // Khmer
86 } // namespace mozilla
88 #endif /* mozilla_intl_LineBreaker_h__ */