summaryrefslogtreecommitdiffstats
path: root/editeng
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2013-08-21 13:15:29 +0200
committerLászló Németh <nemeth@numbertext.org>2013-08-21 13:15:29 +0200
commit26c4d2f5bde513f05c58718ba1c468be4a6bfc86 (patch)
tree01c04de345c2660712919e33417021eb81a867f3 /editeng
parentString to OUString (diff)
downloadcore-26c4d2f5bde513f05c58718ba1c468be4a6bfc86.tar.gz
core-26c4d2f5bde513f05c58718ba1c468be4a6bfc86.zip
fdo#68373 pattern matching in autocorrection for suffix rich lang.
Change-Id: I4a996c51e6e7115e90bf15254b26025aae1f9a6c
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/misc/svxacorr.cxx37
1 files changed, 29 insertions, 8 deletions
diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx
index 7936933a3117..802297313dea 100644
--- a/editeng/source/misc/svxacorr.cxx
+++ b/editeng/source/misc/svxacorr.cxx
@@ -74,6 +74,7 @@ static const int C_NONE = 0x00;
static const int C_FULL_STOP = 0x01;
static const int C_EXCLAMATION_MARK = 0x02;
static const int C_QUESTION_MARK = 0x04;
+static const int C_ASTERISK = 0x2A;
static const sal_Char pImplAutocorr_ListStr[] = "DocumentList";
static const sal_Char pXMLImplWrdStt_ExcptLstStr[] = "WordExceptList.xml";
@@ -2636,7 +2637,7 @@ void SvxAutocorrWordList::DeleteAndDestroyAll()
}
// returns true if inserted
-bool SvxAutocorrWordList::Insert(SvxAutocorrWord *pWord)
+bool SvxAutocorrWordList::Insert(SvxAutocorrWord *pWord) const
{
if ( maSet.empty() ) // use the hash
{
@@ -2703,7 +2704,7 @@ SvxAutocorrWordList::Content SvxAutocorrWordList::getSortedContent() const
return aContent;
}
-bool SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *pFnd,
+const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *pFnd,
const String &rTxt,
xub_StrLen &rStt,
xub_StrLen nEndPos) const
@@ -2722,11 +2723,31 @@ bool SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *pFnd,
if( rCmp.isEqual( rChk, sWord ))
{
rStt = nCalcStt;
- return true;
+ return pFnd;
+ }
+ }
+ // match "word*" pattern
+ if ( rChk.GetChar( rChk.Len() - 1) == C_ASTERISK )
+ {
+ String sTmp( rChk.Copy( 0, rChk.Len() - 1 ) );
+ // search the first occurance with a left word delimitation
+ xub_StrLen nFndPos = -1;
+ do {
+ nFndPos = rTxt.Search( sTmp, nFndPos + 1);
+ } while ( nFndPos != STRING_NOTFOUND && !(!nFndPos || IsWordDelim( rTxt.GetChar( nFndPos - 1 ))));
+ if ( nFndPos != STRING_NOTFOUND )
+ {
+ // store matching pattern and its replacement as a new list item, eg. "wordi" -> "wordy"
+ SvxAutocorrWord* pNew = new SvxAutocorrWord(OUString(rTxt.GetBuffer() + nFndPos, nEndPos - nFndPos), pFnd->GetLong() + OUString(rTxt.GetBuffer() + nFndPos + sTmp.Len(), nEndPos - nFndPos - sTmp.Len()));
+ if( Insert( pNew ) )
+ {
+ rStt = nFndPos;
+ return pNew;
+ } else delete pNew;
}
}
}
- return false;
+ return NULL;
}
const SvxAutocorrWord* SvxAutocorrWordList::SearchWordsInList(const String& rTxt, xub_StrLen& rStt,
@@ -2734,14 +2755,14 @@ const SvxAutocorrWord* SvxAutocorrWordList::SearchWordsInList(const String& rTxt
{
for( SvxAutocorrWordList_Hash::const_iterator it = maHash.begin(); it != maHash.end(); ++it )
{
- if( WordMatches( it->second, rTxt, rStt, nEndPos ) )
- return it->second;
+ if( const SvxAutocorrWord *aTmp = WordMatches( it->second, rTxt, rStt, nEndPos ) )
+ return aTmp;
}
for( SvxAutocorrWordList_Set::const_iterator it2 = maSet.begin(); it2 != maSet.end(); ++it2 )
{
- if( WordMatches( *it2, rTxt, rStt, nEndPos ) )
- return *it2;
+ if( const SvxAutocorrWord *aTmp = WordMatches( *it2, rTxt, rStt, nEndPos ) )
+ return aTmp;
}
return 0;
}