Bug 1736938 Part 5 - Convert LineBreaker and WordBreaker into utility classes. r=jfkthame

Differential Revision: https://phabricator.services.mozilla.com/D129363
This commit is contained in:
Ting-Yu Lin 2021-10-25 19:00:23 +00:00
parent f12e90621b
commit 8dddb69ae7
4 changed files with 12 additions and 27 deletions

View File

@ -14,11 +14,6 @@
using namespace mozilla::unicode;
using namespace mozilla::intl;
/*static*/
already_AddRefed<LineBreaker> LineBreaker::Create() {
return RefPtr<LineBreaker>(new LineBreaker()).forget();
}
/*
Simplification of Pair Table in JIS X 4051

View File

@ -6,17 +6,14 @@
#define mozilla_intl_LineBreaker_h__
#include "nscore.h"
#include "nsISupports.h"
#define NS_LINEBREAKER_NEED_MORE_TEXT -1
namespace mozilla {
namespace intl {
class LineBreaker {
class LineBreaker final {
public:
NS_INLINE_DECL_REFCOUNTING(LineBreaker)
enum class WordBreak : uint8_t {
Normal = 0, // default
BreakAll = 1, // break all
@ -31,7 +28,10 @@ class LineBreaker {
Anywhere = 4
};
static already_AddRefed<LineBreaker> Create();
// LineBreaker is a utility class with only static methods. No need to
// instantiate it.
LineBreaker() = delete;
~LineBreaker() = delete;
// Find the next line break opportunity starting from aPos + 1. It can return
// aLen if there's no break opportunity between [aPos + 1, aLen - 1].
@ -54,9 +54,6 @@ class LineBreaker {
WordBreak aWordBreak, Strictness aLevel,
bool aIsChineseOrJapanese,
uint8_t* aBreakBefore);
private:
~LineBreaker() = default;
};
static inline bool NS_IsSpace(char16_t u) {
@ -75,8 +72,8 @@ static inline bool NS_IsSpace(char16_t u) {
static inline bool NS_NeedsPlatformNativeHandling(char16_t aChar) {
return
#if ANDROID || XP_WIN // Bug 1647377/1736393: no "platform native" support for
// Tibetan; better to just use our class-based breaker.
#if ANDROID || XP_WIN // Bug 1647377/1736393: 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

View File

@ -15,11 +15,6 @@ using mozilla::unicode::GetGenCategory;
using mozilla::unicode::GetScriptCode;
using mozilla::unicode::Script;
/*static*/
already_AddRefed<WordBreaker> WordBreaker::Create() {
return RefPtr<WordBreaker>(new WordBreaker()).forget();
}
#define IS_ASCII(c) (0 == (0xFF80 & (c)))
#define ASCII_IS_ALPHA(c) \
((('a' <= (c)) && ((c) <= 'z')) || (('A' <= (c)) && ((c) <= 'Z')))

View File

@ -6,7 +6,6 @@
#define mozilla_intl_WordBreaker_h__
#include "nscore.h"
#include "nsISupports.h"
#define NS_WORDBREAKER_NEED_MORE_TEXT -1
@ -18,11 +17,12 @@ struct WordRange {
uint32_t mEnd;
};
class WordBreaker {
class WordBreaker final {
public:
NS_INLINE_DECL_REFCOUNTING(WordBreaker)
static already_AddRefed<WordBreaker> Create();
// WordBreaker is a utility class with only static methods. No need to
// instantiate it.
WordBreaker() = delete;
~WordBreaker() = delete;
// Find the word boundary by scanning forward and backward from aPos.
//
@ -43,8 +43,6 @@ class WordBreaker {
static int32_t Next(const char16_t* aText, uint32_t aLen, uint32_t aPos);
private:
~WordBreaker() = default;
enum WordBreakClass : uint8_t {
kWbClassSpace = 0,
kWbClassAlphaLetter,