diff options
author | László Németh <nemeth@numbertext.org> | 2014-08-01 18:39:26 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2014-08-01 18:48:10 +0200 |
commit | a07425892205ff8951027ea20459b97370d01de6 (patch) | |
tree | 16af5827c08de240daee1e2e0872471a05cd31c5 /editeng | |
parent | 43b88364b0b05def27899d585a1dab46ba3fb729 (diff) |
fdo#55292 add middle wildcard autocorrection
Syntax: .*text.*, eg. for f-ligature replacements:
.*fi.* -> fi (U-FB01)
.*fl.* -> fl (U-FB02)
For en-dash replacements between numbers ("2014–15"), instead of em-dash:
.*1--.* -> –
.*2--.* -> –
...
Change-Id: I8992a751e2c1fbdd96a36cf555eb4349d5f80276
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/misc/svxacorr.cxx | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index 3595c23044dd..25e7b50f74f0 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -2770,13 +2770,15 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p const OUString& rChk = pFnd->GetShort(); sal_Int32 left_wildcard = rChk.startsWith( ".*" ) ? 2 : 0; // ".*word" pattern? + sal_Int32 right_wildcard = rChk.endsWith( ".*" ) ? 2 : 0; // "word.*" pattern? sal_Int32 nSttWdPos = nEndPos; - if ( nEndPos >= rChk.getLength() - (rChk.endsWith( ".*" ) ? 2 : left_wildcard)) + + if ( nEndPos >= rChk.getLength() - left_wildcard - right_wildcard ) { bool bWasWordDelim = false; sal_Int32 nCalcStt = nEndPos - rChk.getLength() + left_wildcard; - if( ( !nCalcStt || nCalcStt == rStt || left_wildcard || + if( !right_wildcard && ( !nCalcStt || nCalcStt == rStt || left_wildcard || ( nCalcStt < rStt && IsWordDelim( rTxt[ nCalcStt - 1 ] ))) ) { @@ -2796,31 +2798,61 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p SvxAutocorrWord* pNew = new SvxAutocorrWord(rTxt.copy(rStt, nEndPos - rStt), left_pattern); if( Insert( pNew ) ) return pNew; else delete pNew; } - } - // match "word.*" patterns, eg. "i18n.*" - if ( rChk.endsWith( ".*" ) ) + } else + // match "word.*" or ".*word.*" patterns, eg. "i18n.*", ".*---.*", TODO: add transliteration support + if ( right_wildcard ) { - OUString sTmp( rChk.copy( 0, rChk.getLength() - 2 ) ); + + OUString sTmp( rChk.copy( left_wildcard, rChk.getLength() - left_wildcard - right_wildcard ) ); // Get the last word delimiter position bool not_suffix; + while( nSttWdPos && !(bWasWordDelim = IsWordDelim( rTxt[ --nSttWdPos ]))) ; - // search the first occurrence with a left word delimitation + // search the first occurrence (with a left word delimitation, if needed) sal_Int32 nFndPos = -1; do { nFndPos = rTxt.indexOf( sTmp, nFndPos + 1); not_suffix = (bWasWordDelim && (nSttWdPos >= nFndPos + sTmp.getLength())); - } while ( nFndPos != -1 && (!(!nFndPos || IsWordDelim( rTxt[ nFndPos - 1 ])) || not_suffix)); + } while ( nFndPos != -1 && (!(left_wildcard || (!left_wildcard && (!nFndPos || IsWordDelim( rTxt[ nFndPos - 1 ])))) || not_suffix)); + if ( nFndPos != -1 ) { + sal_Int32 extra_repl = nFndPos + sTmp.getLength() > nEndPos ? 1: 0; // for patterns with terminating characters, eg. "a:" + + if ( left_wildcard ) + { + // get the first word delimiter position before the matching ".*word.*" pattern + while( nFndPos && !(bWasWordDelim = IsWordDelim( rTxt[ --nFndPos ]))) + ; + if (bWasWordDelim) nFndPos++; + } // store matching pattern and its replacement as a new list item, eg. "i18ns" -> "internationalizations" - OUString aShort = rTxt.copy(nFndPos, nEndPos - nFndPos + ((rTxt[nEndPos] != 0x20) ? 1: 0)); - OUString aLong = pFnd->GetLong() + rTxt.copy(nFndPos + sTmp.getLength(), nEndPos - nFndPos - sTmp.getLength()); + OUString aShort = rTxt.copy(nFndPos, nEndPos - nFndPos + extra_repl); + + OUString aLong; + rStt = nFndPos; + if ( !left_wildcard ) + { + sal_Int32 siz = nEndPos - nFndPos - sTmp.getLength(); + aLong = pFnd->GetLong() + (siz > 0 ? rTxt.copy(nFndPos + sTmp.getLength(), siz) : ""); + } else { + OUStringBuffer buf; + do { + nSttWdPos = rTxt.indexOf( sTmp, nFndPos); + if (nSttWdPos != -1) + { + buf.append(rTxt.copy(nFndPos, nSttWdPos - nFndPos)).append(pFnd->GetLong()); + nFndPos = nSttWdPos + sTmp.getLength(); + } + } while (nSttWdPos != -1); + if (nEndPos - nFndPos > extra_repl) buf.append(rTxt.copy(nFndPos, nEndPos - nFndPos)); + aLong = buf.makeStringAndClear(); + } SvxAutocorrWord* pNew = new SvxAutocorrWord(aShort, aLong); - if( Insert( pNew ) ) + if ( Insert( pNew ) ) { - rStt = nFndPos; - return pNew; + if ( IsWordDelim(rTxt[nEndPos]) ) return pNew; } else delete pNew; } } |