2001-09-26 04:40:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2017-12-14 07:17:32 +03:00
|
|
|
#ifndef mozilla_intl_LineBreaker_h__
|
|
|
|
#define mozilla_intl_LineBreaker_h__
|
1999-02-09 19:01:48 +03:00
|
|
|
|
|
|
|
#include "nscore.h"
|
2017-12-14 07:17:32 +03:00
|
|
|
#include "nsISupports.h"
|
1999-02-09 19:01:48 +03:00
|
|
|
|
2005-08-22 07:00:06 +04:00
|
|
|
#define NS_LINEBREAKER_NEED_MORE_TEXT -1
|
|
|
|
|
2017-12-14 07:17:32 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace intl {
|
1999-02-09 19:01:48 +03:00
|
|
|
|
2017-12-14 07:17:32 +03:00
|
|
|
class LineBreaker {
|
1999-02-16 21:11:14 +03:00
|
|
|
public:
|
2017-12-14 07:17:32 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(LineBreaker)
|
2012-05-07 23:18:23 +04:00
|
|
|
|
2019-05-20 23:46:35 +03:00
|
|
|
enum class WordBreak : uint8_t {
|
|
|
|
Normal = 0, // default
|
|
|
|
BreakAll = 1, // break all
|
|
|
|
KeepAll = 2 // always keep
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Strictness : uint8_t {
|
|
|
|
Auto = 0,
|
|
|
|
Loose = 1,
|
|
|
|
Normal = 2,
|
|
|
|
Strict = 3,
|
|
|
|
Anywhere = 4
|
2012-05-07 23:18:23 +04:00
|
|
|
};
|
|
|
|
|
2017-12-14 07:17:32 +03:00
|
|
|
static already_AddRefed<LineBreaker> Create();
|
|
|
|
|
|
|
|
int32_t Next(const char16_t* aText, uint32_t aLen, uint32_t aPos);
|
1999-02-23 19:20:39 +03:00
|
|
|
|
2017-12-14 07:17:32 +03:00
|
|
|
int32_t Prev(const char16_t* aText, uint32_t aLen, uint32_t aPos);
|
1999-02-16 21:11:14 +03:00
|
|
|
|
2013-02-27 11:04:38 +04:00
|
|
|
// Call this on a word with whitespace at either end. We will apply JISx4051
|
2007-01-17 05:14:10 +03:00
|
|
|
// rules to find breaks inside the word. aBreakBefore is set to the break-
|
|
|
|
// before status of each character; aBreakBefore[0] will always be false
|
|
|
|
// because we never return a break before the first character.
|
|
|
|
// aLength is the length of the aText array and also the length of the
|
|
|
|
// aBreakBefore output array.
|
2017-12-14 07:17:32 +03:00
|
|
|
void GetJISx4051Breaks(const char16_t* aText, uint32_t aLength,
|
2019-05-20 23:46:35 +03:00
|
|
|
WordBreak aWordBreak, Strictness aLevel,
|
2019-05-20 23:47:09 +03:00
|
|
|
bool aIsChineseOrJapanese, uint8_t* aBreakBefore);
|
2017-12-14 07:17:32 +03:00
|
|
|
void GetJISx4051Breaks(const uint8_t* aText, uint32_t aLength,
|
2019-05-20 23:46:35 +03:00
|
|
|
WordBreak aWordBreak, Strictness aLevel,
|
2019-05-20 23:47:09 +03:00
|
|
|
bool aIsChineseOrJapanese, uint8_t* aBreakBefore);
|
2017-12-14 07:17:32 +03:00
|
|
|
|
|
|
|
private:
|
2020-03-04 12:11:10 +03:00
|
|
|
~LineBreaker() = default;
|
1999-02-09 19:01:48 +03:00
|
|
|
|
2017-12-14 07:17:32 +03:00
|
|
|
int32_t WordMove(const char16_t* aText, uint32_t aLen, uint32_t aPos,
|
|
|
|
int8_t aDirection);
|
|
|
|
};
|
1999-02-09 19:01:48 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
static inline bool NS_IsSpace(char16_t u) {
|
2007-09-19 10:34:24 +04:00
|
|
|
return u == 0x0020 || // SPACE
|
|
|
|
u == 0x0009 || // CHARACTER TABULATION
|
|
|
|
u == 0x000D || // CARRIAGE RETURN
|
|
|
|
(0x2000 <= u && u <= 0x2006) || // EN QUAD, EM QUAD, EN SPACE,
|
|
|
|
// EM SPACE, THREE-PER-EM SPACE,
|
|
|
|
// FOUR-PER-SPACE, SIX-PER-EM SPACE,
|
2012-12-12 11:00:23 +04:00
|
|
|
(0x2008 <= u && u <= 0x200B) || // PUNCTUATION SPACE, THIN SPACE,
|
2007-09-19 10:34:24 +04:00
|
|
|
// HAIR SPACE, ZERO WIDTH SPACE
|
2017-08-31 20:08:20 +03:00
|
|
|
u == 0x1361 || // ETHIOPIC WORDSPACE
|
|
|
|
u == 0x1680 || // OGHAM SPACE MARK
|
2012-12-12 11:00:23 +04:00
|
|
|
u == 0x205F; // MEDIUM MATHEMATICAL SPACE
|
2007-09-19 10:34:24 +04:00
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
static inline bool NS_NeedsPlatformNativeHandling(char16_t aChar) {
|
2020-06-30 10:27:00 +03:00
|
|
|
return
|
|
|
|
#if ANDROID // Bug 1647377: no "platform native" support for Tibetan;
|
|
|
|
// better to just use our class-based breaker.
|
|
|
|
(0x0e01 <= aChar && aChar <= 0x0eff) || // Thai, Lao
|
|
|
|
#else
|
|
|
|
(0x0e01 <= aChar && aChar <= 0x0fff) || // Thai, Lao, Tibetan
|
|
|
|
#endif
|
|
|
|
(0x1780 <= aChar && aChar <= 0x17ff); // Khmer
|
2007-10-01 00:30:31 +04:00
|
|
|
}
|
|
|
|
|
2017-12-14 07:17:32 +03:00
|
|
|
} // namespace intl
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_intl_LineBreaker_h__ */
|