summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorChristopher Copits <ChrisCDev@live.com>2013-02-23 13:58:18 -0500
committerCaolán McNamara <caolanm@redhat.com>2013-02-28 23:08:36 +0000
commitea7d6d070247f6b676054a8256679ac2d2ae577c (patch)
treeaf610975f6b0446d9511dd4970d6de32dae01519 /editeng
parentb0612be2516bcfeadf99ce46edd0aa724f84d66a (diff)
fdo#55693 Two initial capitalized letters corrected in compound words
What changes I made: 1. In svxacorr.cxx SvxAutoCorrect::IsAutoCorrectChar, I added '-' as a character. 2. In svxacorr.cxx SvxAutoCorrect::FnCptlSttWrd, I added code to iterate through each AutoCorrectChar in a compound word to determine if capitalization needs fixing. Change-Id: I4e7de33fceccdea5edd84e83bacc7ae690135d76 Reviewed-on: https://gerrit.libreoffice.org/2351 Tested-by: LibreOffice gerrit bot <gerrit@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/misc/svxacorr.cxx96
1 files changed, 67 insertions, 29 deletions
diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx
index d56021b4dac7..2880651450a9 100644
--- a/editeng/source/misc/svxacorr.cxx
+++ b/editeng/source/misc/svxacorr.cxx
@@ -235,7 +235,8 @@ sal_Bool SvxAutoCorrect::IsAutoCorrectChar( sal_Unicode cChar )
cChar == ' ' || cChar == '\'' || cChar == '\"' ||
cChar == '*' || cChar == '_' || cChar == '%' ||
cChar == '.' || cChar == ',' || cChar == ';' ||
- cChar == ':' || cChar == '?' || cChar == '!' || cChar == '/';
+ cChar == ':' || cChar == '?' || cChar == '!' ||
+ cChar == '/' || cChar == '-';
}
sal_Bool SvxAutoCorrect::NeedsHardspaceAutocorr( sal_Unicode cChar )
@@ -358,40 +359,77 @@ sal_Bool SvxAutoCorrect::FnCptlSttWrd( SvxAutoCorrDoc& rDoc, const String& rTxt,
if( rCC.isLetterNumeric( rTxt, nEndPos - 1 ))
break;
+ // Is the word a compounded word seperated by delimiters?
+ // If so, keep track of all delimiters so each constituent
+ // word can be checked for two initial capital letters.
+ xub_StrLen n = 0;
+ std::deque<xub_StrLen> aDelimiters;
+
+ // Always check for two capitals at the beginning
+ // of the entire word, so start at nSttPos.
+ aDelimiters.push_back(nSttPos);
+
+ // Find all compound word delimiters
+ for (n = nSttPos; n < nEndPos; n++)
+ {
+ if (IsAutoCorrectChar(rTxt.GetChar( n )))
+ {
+ aDelimiters.push_back( n + 1 ); // Get position of char after delimiter
+ }
+
+ }
+
+ // Decide where to put the terminating delimiter.
+ // If the last AutoCorrect char was a newline, then the AutoCorrect
+ // char will not be included in rTxt.
+ // If the last AutoCorrect char was not a newline, then the AutoCorrect
+ // character will be the last character in rTxt.
+ if (!IsAutoCorrectChar(rTxt.GetChar(nEndPos-1)))
+ aDelimiters.push_back(nEndPos);
+
+ // Iterate through the word and all words that compose it.
+ n = aDelimiters.size();
+
// Two capital letters at the beginning of word?
- if( nSttPos+2 < nEndPos &&
- IsUpperLetter( rCC.getCharacterType( rTxt, nSttPos )) &&
- IsUpperLetter( rCC.getCharacterType( rTxt, ++nSttPos )) &&
- // Is the third character a lower case
- IsLowerLetter( rCC.getCharacterType( rTxt, nSttPos +1 )) &&
- // Do not replace special attributes
- 0x1 != rTxt.GetChar( nSttPos ) && 0x2 != rTxt.GetChar( nSttPos ))
- {
- // test if the word is in an exception list
- String sWord( rTxt.Copy( nSttPos - 1, nEndPos - nSttPos + 1 ));
- if( !FindInWrdSttExceptList(eLang, sWord) )
+ for(n = 0; n < aDelimiters.size() - 1; n++)
+ {
+ nSttPos = aDelimiters.at( n );
+ nEndPos = aDelimiters.at( n + 1 );
+
+ if( nSttPos+2 < nEndPos &&
+ IsUpperLetter( rCC.getCharacterType( rTxt, nSttPos )) &&
+ IsUpperLetter( rCC.getCharacterType( rTxt, ++nSttPos )) &&
+ // Is the third character a lower case
+ IsLowerLetter( rCC.getCharacterType( rTxt, nSttPos +1 )) &&
+ // Do not replace special attributes
+ 0x1 != rTxt.GetChar( nSttPos ) && 0x2 != rTxt.GetChar( nSttPos ))
{
- // Check that word isn't correctly spelled before correcting:
- ::com::sun::star::uno::Reference<
- ::com::sun::star::linguistic2::XSpellChecker1 > xSpeller =
- SvxGetSpellChecker();
- if( xSpeller->hasLanguage(eLang) )
+ // test if the word is in an exception list
+ String sWord( rTxt.Copy( nSttPos - 1, nEndPos - nSttPos + 1 ));
+ if( !FindInWrdSttExceptList(eLang, sWord) )
{
- Sequence< ::com::sun::star::beans::PropertyValue > aEmptySeq;
- if (!xSpeller->spell(sWord, eLang, aEmptySeq).is())
+ // Check that word isn't correctly spelled before correcting:
+ ::com::sun::star::uno::Reference<
+ ::com::sun::star::linguistic2::XSpellChecker1 > xSpeller =
+ SvxGetSpellChecker();
+ if( xSpeller->hasLanguage(eLang) )
+ {
+ Sequence< ::com::sun::star::beans::PropertyValue > aEmptySeq;
+ if (!xSpeller->spell(sWord, eLang, aEmptySeq).is())
+ {
+ return false;
+ }
+ }
+ sal_Unicode cSave = rTxt.GetChar( nSttPos );
+ rtl::OUString sChar( cSave );
+ sChar = rCC.lowercase( sChar );
+ if( sChar[0] != cSave && rDoc.ReplaceRange( nSttPos, 1, sChar ))
{
- return false;
+ if( SaveWordWrdSttLst & nFlags )
+ rDoc.SaveCpltSttWord( CptlSttWrd, nSttPos, sWord, cSave );
+ bRet = sal_True;
}
}
- sal_Unicode cSave = rTxt.GetChar( nSttPos );
- rtl::OUString sChar( cSave );
- sChar = rCC.lowercase( sChar );
- if( sChar[0] != cSave && rDoc.ReplaceRange( nSttPos, 1, sChar ))
- {
- if( SaveWordWrdSttLst & nFlags )
- rDoc.SaveCpltSttWord( CptlSttWrd, nSttPos, sWord, cSave );
- bRet = sal_True;
- }
}
}
return bRet;