Bug 1700051: part 24) Refactor `mozInlineSpellWordUtil::SplitDOMWord` to `mozInlineSpellWordUtil::SplitDOMWordAndAppendTo`. r=smaug

More explicit and preparation for further `const`-correctness.

Depends on D110090

Differential Revision: https://phabricator.services.mozilla.com/D110240
This commit is contained in:
Mirko Brodesser 2021-03-31 08:33:09 +00:00
Родитель 2e851222b5
Коммит 7814efb66a
2 изменённых файлов: 11 добавлений и 8 удалений

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

@ -892,13 +892,13 @@ nsresult mozInlineSpellWordUtil::BuildRealWords() {
// This is pretty simple. We just have to walk mSoftText, tokenizing it
// into "real words".
// We do an outer traversal of words delimited by IsDOMWordSeparator, calling
// SplitDOMWord on each of those DOM words
// SplitDOMWordAndAppendTo on each of those DOM words
int32_t wordStart = -1;
mRealWords.Clear();
for (int32_t i = 0; i < int32_t(mSoftText.Length()); ++i) {
if (IsDOMWordSeparator(mSoftText.CharAt(i))) {
if (wordStart >= 0) {
nsresult rv = SplitDOMWord(wordStart, i);
nsresult rv = SplitDOMWordAndAppendTo(wordStart, i, mRealWords);
if (NS_FAILED(rv)) {
return rv;
}
@ -911,7 +911,8 @@ nsresult mozInlineSpellWordUtil::BuildRealWords() {
}
}
if (wordStart >= 0) {
nsresult rv = SplitDOMWord(wordStart, mSoftText.Length());
nsresult rv =
SplitDOMWordAndAppendTo(wordStart, mSoftText.Length(), mRealWords);
if (NS_FAILED(rv)) {
return rv;
}
@ -1086,9 +1087,10 @@ int32_t mozInlineSpellWordUtil::FindRealWordContaining(
return -1;
}
// mozInlineSpellWordUtil::SplitDOMWord
// mozInlineSpellWordUtil::SplitDOMWordAndAppendTo
nsresult mozInlineSpellWordUtil::SplitDOMWord(int32_t aStart, int32_t aEnd) {
nsresult mozInlineSpellWordUtil::SplitDOMWordAndAppendTo(
int32_t aStart, int32_t aEnd, nsTArray<RealWord>& aRealWords) const {
nsDependentSubstring targetText(mSoftText, aStart, aEnd - aStart);
WordSplitState<nsDependentSubstring> state(targetText);
state.mCurCharClass = state.ClassifyCharacter(0, true);
@ -1097,7 +1099,7 @@ nsresult mozInlineSpellWordUtil::SplitDOMWord(int32_t aStart, int32_t aEnd) {
if (state.mCurCharClass != CHAR_CLASS_END_OF_INPUT && state.IsSpecialWord()) {
int32_t specialWordLength =
state.mDOMWordText.Length() - state.mDOMWordOffset;
if (!mRealWords.AppendElement(
if (!aRealWords.AppendElement(
RealWord(aStart + state.mDOMWordOffset, specialWordLength, false),
fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
@ -1116,7 +1118,7 @@ nsresult mozInlineSpellWordUtil::SplitDOMWord(int32_t aStart, int32_t aEnd) {
// find the end of the word
state.AdvanceThroughWord();
int32_t wordLen = state.mDOMWordOffset - wordOffset;
if (!mRealWords.AppendElement(
if (!aRealWords.AppendElement(
RealWord(aStart + wordOffset, wordLen,
!state.ShouldSkipWord(wordOffset, wordLen)),
fallible)) {

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

@ -211,7 +211,8 @@ class MOZ_STACK_CLASS mozInlineSpellWordUtil {
// Build mRealWords array
nsresult BuildRealWords();
nsresult SplitDOMWord(int32_t aStart, int32_t aEnd);
nsresult SplitDOMWordAndAppendTo(int32_t aStart, int32_t aEnd,
nsTArray<RealWord>& aRealWords) const;
nsresult MakeRangeForWord(const RealWord& aWord, nsRange** aRange) const;
void MakeNodeOffsetRangeForWord(const RealWord& aWord,