Bug 1733872 Part 2 - Add a new LineBreaker::Next(), and deprecate the old Next(). r=m_kato

This patch is similar to Bug 1728708 Part 4, but for line breaker. This
should make the future integration of ICU4X line segmenter easier. A
UAX14 compatible line breaker always breaks at the end of text
(rule LB3 [1]), and ICU4X line segmenter has this behavior, too.

Current LineBreaker::Next() doesn't treat the end of text as a line
break opportunity, so this patch deprecates it by renaming it, and add a
new Next() method.

TestASCIILB() has adopted the new Next(). All the other callers of the
DeprecatedNext (nsPlainTextSerializer, nsXMLContentSerializer,
InternetCiter) should be audited later, possibly with the removal of
Prev() because the all the usages are very close to Prev().

[1] https://www.unicode.org/reports/tr14/#LB3

Differential Revision: https://phabricator.services.mozilla.com/D127379
This commit is contained in:
Ting-Yu Lin 2021-10-07 07:39:13 +00:00
Родитель da1f64cd71
Коммит e558c2cbd9
6 изменённых файлов: 33 добавлений и 10 удалений

Просмотреть файл

@ -169,8 +169,8 @@ int32_t nsPlainTextSerializer::CurrentLine::FindWrapIndexForContent(
(prefixwidth > aWrapColumn + 1) ? 1 : aWrapColumn - prefixwidth + 1;
if (aLineBreaker) {
if ((uint32_t)goodSpace < mContent.Length())
goodSpace =
aLineBreaker->Next(mContent.get(), mContent.Length(), goodSpace);
goodSpace = aLineBreaker->DeprecatedNext(mContent.get(),
mContent.Length(), goodSpace);
if (goodSpace == NS_LINEBREAKER_NEED_MORE_TEXT)
goodSpace = mContent.Length();
} else {

Просмотреть файл

@ -1545,9 +1545,9 @@ bool nsXMLContentSerializer::AppendWrapped_NonWhitespaceSequence(
if (wrapPosition != NS_LINEBREAKER_NEED_MORE_TEXT) {
foundWrapPosition = true;
} else {
wrapPosition =
lineBreaker->Next(aSequenceStart, (aEnd - aSequenceStart),
(aPos - aSequenceStart));
wrapPosition = lineBreaker->DeprecatedNext(aSequenceStart,
(aEnd - aSequenceStart),
(aPos - aSequenceStart));
if (wrapPosition != NS_LINEBREAKER_NEED_MORE_TEXT) {
foundWrapPosition = true;
}

Просмотреть файл

@ -249,8 +249,9 @@ nsresult InternetCiter::Rewrap(const nsAString& aInString, uint32_t aWrapCol,
}
// Else try looking forwards:
breakPt = lineBreaker->Next(tString.get() + posInString,
length - posInString, eol - posInString);
breakPt = lineBreaker->DeprecatedNext(tString.get() + posInString,
length - posInString,
eol - posInString);
rv = breakPt == NS_LINEBREAKER_NEED_MORE_TEXT ? NS_ERROR_BASE : NS_OK;
} else {

Просмотреть файл

@ -956,6 +956,16 @@ int32_t LineBreaker::WordMove(const char16_t* aText, uint32_t aLen,
}
int32_t LineBreaker::Next(const char16_t* aText, uint32_t aLen, uint32_t aPos) {
MOZ_ASSERT(aText);
if (aPos >= aLen) {
return NS_LINEBREAKER_NEED_MORE_TEXT;
}
return WordMove(aText, aLen, aPos, 1);
}
int32_t LineBreaker::DeprecatedNext(const char16_t* aText, uint32_t aLen,
uint32_t aPos) {
NS_ASSERTION(aText, "aText shouldn't be null");
NS_ASSERTION(aLen > aPos,
"Bad position passed to nsJISx4051LineBreaker::Next");

Просмотреть файл

@ -33,8 +33,23 @@ class LineBreaker {
static already_AddRefed<LineBreaker> Create();
// 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].
//
// If aPos is already at the end of aText or beyond, i.e. aPos >= aLen, return
// NS_LINEBREAKER_NEED_MORE_TEXT.
int32_t Next(const char16_t* aText, uint32_t aLen, uint32_t aPos);
// Similar to Next(), but doesn't treat the end of text a line break
// opportunity. It returns NS_LINEBREAKER_NEED_MORE_TEXT when reaching the end
// of text.
///
// XXX: Please do not add new callers to DeprecatedNext(). This method will be
// removed.
int32_t DeprecatedNext(const char16_t* aText, uint32_t aLen, uint32_t aPos);
// Bug 1733009: Please do not add new callers to Prev(). This method will be
// removed.
int32_t Prev(const char16_t* aText, uint32_t aLen, uint32_t aPos);
// Call this on a word with whitespace at either end. We will apply JISx4051

Просмотреть файл

@ -125,9 +125,6 @@ bool TestASCIILB(mozilla::intl::LineBreaker* lb, const char* in,
while (true) {
curr = lb->Next(input.get(), input.Length(), curr);
if (curr == NS_LINEBREAKER_NEED_MORE_TEXT) {
// XXX: We should remove the following line once LineBreaker recognizes
// text end as a line break point.
result.AppendElement(input.Length());
break;
}
result.AppendElement(curr);