Bug 1808234 - Clean up xpcshell variant scheduling. r=jmaher
[gecko.git] / intl / lwbrk / LineBreaker.h
bloba2d7377474f3db08c976ba566dd67683e1ac425e
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__
8 #include <cstdint>
10 #define NS_LINEBREAKER_NEED_MORE_TEXT -1
12 namespace mozilla {
13 namespace intl {
14 enum class LineBreakRule : uint8_t;
15 enum class WordBreakRule : uint8_t;
17 class LineBreaker final {
18 public:
19 // LineBreaker is a utility class with only static methods. No need to
20 // instantiate it.
21 LineBreaker() = delete;
22 ~LineBreaker() = delete;
24 // Find the next line break opportunity starting from aPos + 1. It can return
25 // aLen if there's no break opportunity between [aPos + 1, aLen - 1].
27 // If aPos is already at the end of aText or beyond, i.e. aPos >= aLen, return
28 // NS_LINEBREAKER_NEED_MORE_TEXT.
30 // DEPRECATED: Use LineBreakIteratorUtf16 instead.
31 static int32_t Next(const char16_t* aText, uint32_t aLen, uint32_t aPos);
33 // Call this on a word with whitespace at either end. We will apply JISx4051
34 // rules to find breaks inside the word. aBreakBefore is set to the break-
35 // before status of each character; aBreakBefore[0] will always be false
36 // because we never return a break before the first character.
37 // aLength is the length of the aText array and also the length of the
38 // aBreakBefore output array.
39 static void ComputeBreakPositions(const char16_t* aText, uint32_t aLength,
40 WordBreakRule aWordBreak,
41 LineBreakRule aLevel,
42 bool aIsChineseOrJapanese,
43 uint8_t* aBreakBefore);
44 static void ComputeBreakPositions(const uint8_t* aText, uint32_t aLength,
45 WordBreakRule aWordBreak,
46 LineBreakRule aLevel,
47 bool aIsChineseOrJapanese,
48 uint8_t* aBreakBefore);
51 static inline bool NS_IsSpace(char16_t u) {
52 return u == 0x0020 || // SPACE
53 u == 0x0009 || // CHARACTER TABULATION
54 u == 0x000D || // CARRIAGE RETURN
55 (0x2000 <= u && u <= 0x2006) || // EN QUAD, EM QUAD, EN SPACE,
56 // EM SPACE, THREE-PER-EM SPACE,
57 // FOUR-PER-SPACE, SIX-PER-EM SPACE,
58 (0x2008 <= u && u <= 0x200B) || // PUNCTUATION SPACE, THIN SPACE,
59 // HAIR SPACE, ZERO WIDTH SPACE
60 u == 0x1361 || // ETHIOPIC WORDSPACE
61 u == 0x1680 || // OGHAM SPACE MARK
62 u == 0x205F; // MEDIUM MATHEMATICAL SPACE
65 static inline bool NS_NeedsPlatformNativeHandling(char16_t aChar) {
66 return
67 #if ANDROID || XP_WIN // Bug 1647377/1736393: no "platform native" support for
68 // Tibetan; better to just use our class-based breaker.
69 (0x0e01 <= aChar && aChar <= 0x0eff) || // Thai, Lao
70 #else
71 // Routing Tibetan to the platform-native breaker currently results in
72 // WPT failures in a few css3-text-line-break-opclns-* testcases that mix
73 // a Tibetan character with other-script context.
74 (0x0e01 <= aChar && aChar <= 0x0fff) || // Thai, Lao, Tibetan
75 #endif
76 (0x1780 <= aChar && aChar <= 0x17ff); // Khmer
79 } // namespace intl
80 } // namespace mozilla
82 #endif /* mozilla_intl_LineBreaker_h__ */