summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTheppitak Karoonboonyanan <theppitak@gmail.com>2023-11-30 22:34:29 +0700
committerJonathan Clark <jonathan@libreoffice.org>2024-06-21 20:34:22 +0200
commit76c96ca7c9a6e0d847ec5dc186c6e47ab6061f5f (patch)
treeeca01564978b35d6b3a911f43b752d78bd678a86 /include
parenta820696263e62ffc7ebe0a9f6d51bec2e1354926 (diff)
tdf#158454 Add Thai Autocorrect Support, coding part
SvxAutoCorrDoc::ChgAutoCorrWord() implementations: correct multiple patterns * include/editeng/svxacorr.hxx, editeng/source/misc/svxacorr.cxx: - Add classes SvxAutocorrWordList::{Iterator,WordSearchStatus}. - Make SvxAutocorrWordList::SearchWordsInList() return WordSearchStatus so the search can be continued with the added SvxAutocorrWordList::SearchWordsNext() method. - Make SvxAutoCorrect::SearchWordsInList(), and its lcl_SearchWordsInList() companion, return WordSearchStatus propagated from SvxAutocorrWordList::SearchWordsInList(). - SvxAutocorrWordList::WordMatches(): The existing mechanism of preventing collision of patterns like in tdf#83037 (→ and ← and ↔ autocorrect collisions) was by storing the matched string of wildcard pattern back to the list without overwriting existing one. If the matched string was found in the list, it would just be treated as no matching. While this worked well for collision prevention, it caused failure on the new exhaustive wildcard pattern visiting method when autocorrecting the second text chunk with the same content. In such situation, all intermediate stages of corrections of the first text chunk would be recorded into the list. And, in the second chunk, the first stage would just be applied from the recorded pattern, but all the next stages would be refused due to the "collision" with the recorded patterns. Moreover, the new method would cause the list to grow more quickly as the autocorrections are done. To solve the problem, just "peek" for the collision instead of actually storing it. And SvxAutocorrWordList::ContainsPattern() is added for this purpose. * editeng/qa/unit/core-test.cxx: - Modify TestAutoCorrDoc::ChgAutoCorrWord() to iterate through all patterns, instead of finishing at the first one. * editeng/source/editeng/edtspell.cxx: - Ditto for EdtAutoCorrDoc::ChgAutoCorrWord(). * sw/source/core/edit/acorrect.cxx: - Ditto for SwAutoCorrDoc::ChgAutoCorrWord(). - SwAutoCorrDoc::ChgAutoCorrWord(): Remove old dead code for autocorrection on text with redlines. * sw/qa/extras/uiwriter/uiwriter6.cxx, +sw/qa/extras/uiwriter/data/tdf158454.odt: - Add unit test "testTdf158454". Change-Id: I8fb4a628a977b79b0ed2f239fd3749f15823b5df Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160160 Tested-by: Jenkins Reviewed-by: Jonathan Clark <jonathan@libreoffice.org>
Diffstat (limited to 'include')
-rw-r--r--include/editeng/svxacorr.hxx72
1 files changed, 63 insertions, 9 deletions
diff --git a/include/editeng/svxacorr.hxx b/include/editeng/svxacorr.hxx
index d85a3d242783..d30a9795a743 100644
--- a/include/editeng/svxacorr.hxx
+++ b/include/editeng/svxacorr.hxx
@@ -163,15 +163,62 @@ class EDITENG_DLLPUBLIC SvxAutocorrWordList
SvxAutocorrWordList( const SvxAutocorrWordList& ) = delete;
const SvxAutocorrWordList& operator= ( const SvxAutocorrWordList& ) = delete;
- const SvxAutocorrWord* WordMatches(const SvxAutocorrWord *pFnd,
- std::u16string_view rTxt,
- sal_Int32 &rStt,
- sal_Int32 nEndPos) const;
+ std::optional<SvxAutocorrWord> WordMatches(const SvxAutocorrWord *pFnd,
+ std::u16string_view rTxt,
+ sal_Int32 &rStt,
+ sal_Int32 nEndPos) const;
public:
+ class EDITENG_DLLPUBLIC Iterator {
+ struct Impl;
+ std::unique_ptr<Impl> mpImpl;
+
+ // For construction from containers in *SvxAutocorrWordList::mpImpl
+ friend class SvxAutocorrWordList;
+ Iterator(std::unique_ptr<Impl> pImpl);
+
+ public:
+ Iterator(const Iterator& it);
+ ~Iterator();
+ bool Step();
+ const SvxAutocorrWord& operator*() const;
+ const SvxAutocorrWord* operator->() const;
+ };
+
+ class EDITENG_DLLPUBLIC WordSearchStatus {
+ SvxAutocorrWord mFnd;
+
+ // For iteration
+ friend class SvxAutocorrWordList;
+ const SvxAutocorrWordList* mpAutocorrWordList;
+ SvxAutocorrWordList::Iterator mAutocorrWordListIter;
+
+ public:
+ WordSearchStatus(
+ const SvxAutocorrWord& aFnd,
+ const SvxAutocorrWordList* pAutocorrWordList,
+ const SvxAutocorrWordList::Iterator& autocorrWordListIter
+ ) : mFnd(aFnd), mpAutocorrWordList(pAutocorrWordList),
+ mAutocorrWordListIter(autocorrWordListIter)
+ {}
+ const SvxAutocorrWord* GetAutocorrWord() const {
+ return &mFnd;
+ }
+ const SvxAutocorrWordList* GetAutocorrWordList() const {
+ return mpAutocorrWordList;
+ }
+ const SvxAutocorrWord* GetWordAtIter() const {
+ return &*mAutocorrWordListIter;
+ }
+ bool StepIter() {
+ return mAutocorrWordListIter.Step();
+ }
+ };
+
SvxAutocorrWordList();
// free any objects still in the set
~SvxAutocorrWordList();
void DeleteAndDestroyAll();
+ bool ContainsPattern(const OUString& sShort) const;
const SvxAutocorrWord* Insert(SvxAutocorrWord aWord) const;
std::optional<SvxAutocorrWord> FindAndRemove(const SvxAutocorrWord *pWord);
void LoadEntry(const OUString& sWrong, const OUString& sRight, bool bOnlyTxt);
@@ -181,7 +228,10 @@ public:
typedef std::vector<SvxAutocorrWord> AutocorrWordSetType;
const AutocorrWordSetType & getSortedContent() const;
- const SvxAutocorrWord* SearchWordsInList(std::u16string_view rTxt, sal_Int32& rStt, sal_Int32 nEndPos) const;
+ std::optional<WordSearchStatus>
+ SearchWordsInList(std::u16string_view rTxt, sal_Int32& rStt, sal_Int32 nEndPos) const;
+ bool
+ SearchWordsNext(std::u16string_view rTxt, sal_Int32& rStt, sal_Int32 nEndPos, WordSearchStatus& rStatus) const;
};
class EDITENG_DLLPUBLIC SvxAutoCorrectLanguageLists
@@ -323,10 +373,14 @@ public:
// nEnd - to check position - as of this item forward
// rLang - Input: in which language is searched
// Output: in which "language list" was it found
- const SvxAutocorrWord* SearchWordsInList( std::u16string_view rTxt,
- sal_Int32& rStt, sal_Int32 nEndPos,
- SvxAutoCorrDoc& rDoc,
- LanguageTag& rLang );
+ std::optional<SvxAutocorrWordList::WordSearchStatus>
+ SearchWordsInList( std::u16string_view rTxt,
+ sal_Int32& rStt, sal_Int32 nEndPos,
+ SvxAutoCorrDoc& rDoc,
+ LanguageTag& rLang );
+ static bool SearchWordsNext( std::u16string_view rTxt,
+ sal_Int32& rStt, sal_Int32 nEndPos,
+ SvxAutocorrWordList::WordSearchStatus& rStatus );
// Query/Set the Character for the Quote substitution
sal_Unicode GetStartSingleQuote() const { return cStartSQuote; }