Bug 1700051: part 25) Change `mozInlineSpellWordUtil::BuildRealWords` to return the built words. r=smaug

Depends on D110240

Differential Revision: https://phabricator.services.mozilla.com/D110241
This commit is contained in:
Mirko Brodesser 2021-03-31 09:04:45 +00:00
Родитель 4fe3769af8
Коммит c4cd5efacd
2 изменённых файлов: 20 добавлений и 14 удалений

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

@ -265,11 +265,14 @@ nsresult mozInlineSpellWordUtil::SetPositionAndEnd(nsINode* aPositionNode,
nsresult mozInlineSpellWordUtil::EnsureWords() {
if (mSoftTextValid) return NS_OK;
BuildSoftText();
nsresult rv = BuildRealWords();
if (NS_FAILED(rv)) {
mRealWords.Clear();
return rv;
mRealWords.Clear();
Result<RealWords, nsresult> realWords = BuildRealWords();
if (realWords.isErr()) {
return realWords.unwrapErr();
}
mRealWords = realWords.unwrap();
mSoftTextValid = true;
return NS_OK;
}
@ -888,19 +891,20 @@ void mozInlineSpellWordUtil::BuildSoftText() {
NS_ConvertUTF16toUTF8(mSoftText).get()));
}
nsresult mozInlineSpellWordUtil::BuildRealWords() {
auto mozInlineSpellWordUtil::BuildRealWords() const
-> Result<RealWords, nsresult> {
// 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
// SplitDOMWordAndAppendTo on each of those DOM words
int32_t wordStart = -1;
mRealWords.Clear();
RealWords realWords;
for (int32_t i = 0; i < int32_t(mSoftText.Length()); ++i) {
if (IsDOMWordSeparator(mSoftText.CharAt(i))) {
if (wordStart >= 0) {
nsresult rv = SplitDOMWordAndAppendTo(wordStart, i, mRealWords);
nsresult rv = SplitDOMWordAndAppendTo(wordStart, i, realWords);
if (NS_FAILED(rv)) {
return rv;
return Err(rv);
}
wordStart = -1;
}
@ -912,13 +916,13 @@ nsresult mozInlineSpellWordUtil::BuildRealWords() {
}
if (wordStart >= 0) {
nsresult rv =
SplitDOMWordAndAppendTo(wordStart, mSoftText.Length(), mRealWords);
SplitDOMWordAndAppendTo(wordStart, mSoftText.Length(), realWords);
if (NS_FAILED(rv)) {
return rv;
return Err(rv);
}
}
return NS_OK;
return realWords;
}
/*********** DOM/realwords<->mSoftText mapping functions ************/

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

@ -8,6 +8,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/Maybe.h"
#include "mozilla/Result.h"
#include "mozilla/dom/Document.h"
#include "nsCOMPtr.h"
#include "nsString.h"
@ -175,7 +176,8 @@ class MOZ_STACK_CLASS mozInlineSpellWordUtil {
int32_t EndOffset() const { return mSoftTextOffset + mLength; }
};
nsTArray<RealWord> mRealWords;
using RealWords = nsTArray<RealWord>;
RealWords mRealWords;
int32_t mNextWordIndex;
bool mSoftTextValid;
@ -208,8 +210,8 @@ class MOZ_STACK_CLASS mozInlineSpellWordUtil {
// build mSoftText and mSoftTextDOMMapping
void BuildSoftText();
// Build mRealWords array
nsresult BuildRealWords();
mozilla::Result<RealWords, nsresult> BuildRealWords() const;
nsresult SplitDOMWordAndAppendTo(int32_t aStart, int32_t aEnd,
nsTArray<RealWord>& aRealWords) const;