From f276ca939deb3ee19d171b8541cd18baa4eec3d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Fri, 1 Jul 2016 14:38:54 +0100 Subject: [PATCH] don't autocapitalize words that follow a field mark Change-Id: Ia8efa88aaf47edba9a590c858d0ea30d7bfe2977 --- editeng/qa/unit/core-test.cxx | 22 ++++++++++++++++++++++ editeng/source/misc/svxacorr.cxx | 18 ++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx index d303805..14f06fe 100644 --- a/editeng/qa/unit/core-test.cxx +++ b/editeng/qa/unit/core-test.cxx @@ -340,6 +340,28 @@ void Test::testAutocorrect() CPPUNIT_ASSERT_EQUAL(sExpected, aFoo.getResult()); } + + { + OUString sInput("Test. test"); + sal_Unicode cNextChar(' '); + OUString sExpected("Test. Test "); + + TestAutoCorrDoc aFoo(sInput, LANGUAGE_ENGLISH_US); + aAutoCorrect.DoAutoCorrect(aFoo, sInput, sInput.getLength(), cNextChar, true); + + CPPUNIT_ASSERT_MESSAGE("autocorrect", aFoo.getResult() == sExpected); + } + + { + OUString sInput("Test. \x01 test"); + sal_Unicode cNextChar(' '); + OUString sExpected("Test. \x01 test "); + + TestAutoCorrDoc aFoo(sInput, LANGUAGE_ENGLISH_US); + aAutoCorrect.DoAutoCorrect(aFoo, sInput, sInput.getLength(), cNextChar, true); + + CPPUNIT_ASSERT_MESSAGE("autocorrect", aFoo.getResult() == sExpected); + } } namespace { diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index d736d94..11e56ef 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -102,6 +102,12 @@ static inline bool IsWordDelim( const sal_Unicode c ) cNonBreakingSpace == c || 0x2011 == c || 0x1 == c; } +static inline bool IsAutoCapitalizeWordDelim( const sal_Unicode c ) +{ + return ' ' == c || '\t' == c || 0x0a == c || + cNonBreakingSpace == c || 0x2011 == c; +} + static inline bool IsLowerLetter( sal_Int32 nCharType ) { return CharClass::isLetterType( nCharType ) && @@ -855,9 +861,9 @@ bool SvxAutoCorrect::FnCapitalStartSentence( SvxAutoCorrDoc& rDoc, if( !bAtStart ) // Still no beginning of a paragraph? { - if ( IsWordDelim( *pStr ) ) + if (IsAutoCapitalizeWordDelim(*pStr)) { - while( ! ( bAtStart = (pStart == pStr--) ) && IsWordDelim( *pStr ) ) + while (!(bAtStart = (pStart == pStr--)) && IsAutoCapitalizeWordDelim(*pStr)) ; } // Asian full stop, full width full stop, full width exclamation mark @@ -888,7 +894,7 @@ bool SvxAutoCorrect::FnCapitalStartSentence( SvxAutoCorrDoc& rDoc, do { // overwrite all blanks --pStr; - if( !IsWordDelim( *pStr )) + if (!IsAutoCapitalizeWordDelim(*pStr)) break; } while( ! ( bAtStart = (pStart == pStr) ) ); @@ -983,7 +989,7 @@ bool SvxAutoCorrect::FnCapitalStartSentence( SvxAutoCorrDoc& rDoc, else bAlphaFnd = true; } - else if( bAlphaFnd || IsWordDelim( *pTmpStr ) ) + else if (bAlphaFnd || IsAutoCapitalizeWordDelim(*pTmpStr)) break; if( pTmpStr == pStart ) @@ -999,7 +1005,7 @@ bool SvxAutoCorrect::FnCapitalStartSentence( SvxAutoCorrDoc& rDoc, bool bNumericOnly = '0' <= *(pStr+1) && *(pStr+1) <= '9'; // Search for the beginning of the word - while( !IsWordDelim( *pStr )) + while (!IsAutoCapitalizeWordDelim(*pStr)) { if( bNumericOnly && rCC.isLetter( aText, pStr - pStart ) ) bNumericOnly = false; @@ -1013,7 +1019,7 @@ bool SvxAutoCorrect::FnCapitalStartSentence( SvxAutoCorrDoc& rDoc, if( bNumericOnly ) // consists of only numbers, then not return false; - if( IsWordDelim( *pStr )) + if (IsAutoCapitalizeWordDelim(*pStr)) ++pStr; OUString sWord; -- 2.7.4