From e90e8b6d4fbec2af89f387c38299b7e21514b99e Mon Sep 17 00:00:00 2001 From: Oliver Bolte Date: Wed, 5 Aug 2009 12:39:09 +0000 Subject: CWS-TOOLING: integrate CWS gciteratorfix 2009-08-04 10:23:19 +0200 od r274608 : add missing patch flags for libaries swui, msword and xo 2009-08-03 16:42:48 +0200 mav r274586 : #i101899# workaround the wrong error code on MAC 2009-08-03 13:24:44 +0200 tl r274575 : #i103936# fix for grammar checking loop 2009-08-03 12:37:37 +0200 tl r274573 : #i103936# fix for grammar checking loop 2009-08-03 12:10:01 +0200 tl r274572 : #i103936# fix for grammar checking loop 2009-08-03 09:06:49 +0200 tl r274565 : #i103936# fix for grammar checking loop 2009-08-03 09:04:50 +0200 tl r274564 : #i103936# fix for grammar checking loop 2009-07-31 17:52:45 +0200 tl r274545 : #i103936# fix for grammar checking loop --- linguistic/source/gciterator.cxx | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx index 4f555aeef8..94caf22eec 100644 --- a/linguistic/source/gciterator.cxx +++ b/linguistic/source/gciterator.cxx @@ -191,7 +191,7 @@ static sal_Int32 lcl_SkipWhiteSpaces( const OUString &rText, sal_Int32 nStartPos static sal_Int32 lcl_BacktraceWhiteSpaces( const OUString &rText, sal_Int32 nStartPos ) { - // note having nStartPos point right behind the string is OK since that one + // note: having nStartPos point right behind the string is OK since that one // is a correct end-of-sentence position to be returned from a grammar checker... const sal_Int32 nLen = rText.getLength(); @@ -215,14 +215,16 @@ static sal_Int32 lcl_BacktraceWhiteSpaces( const OUString &rText, sal_Int32 nSta sal_Int32 nPosBefore = nStartPos - 1; const sal_Unicode *pStart = rText.getStr(); if (0 <= nPosBefore && nPosBefore < nLen && lcl_IsWhiteSpace( pStart[ nPosBefore ] )) - nStartPos = nPosBefore; - if (0 <= nStartPos && nStartPos < nLen) { - const sal_Unicode *pText = rText.getStr() + nStartPos; - while (pText > pStart && lcl_IsWhiteSpace( *pText )) - --pText; - // now add 1 since we wnat to point to the first char after the last char in the sentence... - nRes = pText - pStart + 1; + nStartPos = nPosBefore; + if (0 <= nStartPos && nStartPos < nLen) + { + const sal_Unicode *pText = rText.getStr() + nStartPos; + while (pText > pStart && lcl_IsWhiteSpace( *pText )) + --pText; + // now add 1 since we want to point to the first char after the last char in the sentence... + nRes = pText - pStart + 1; + } } DBG_ASSERT( 0 <= nRes && nRes <= nLen, "lcl_BacktraceWhiteSpaces return value out of range" ); @@ -577,6 +579,7 @@ void GrammarCheckingIterator::DequeueAndCheck() sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex; sal_Int32 nSuggestedEnd = GetSuggestedEndOfSentence( aCurTxt, nStartPos, aCurLocale ); + DBG_ASSERT( nSuggestedEnd > nStartPos, "nSuggestedEndOfSentencePos calculation failed?" ); linguistic2::ProofreadingResult aRes; @@ -586,6 +589,15 @@ void GrammarCheckingIterator::DequeueAndCheck() aGuard.clear(); uno::Sequence< beans::PropertyValue > aEmptyProps; aRes = xGC->doProofreading( aCurDocId, aCurTxt, aCurLocale, nStartPos, nSuggestedEnd, aEmptyProps ); + + //!! work-around to prevent looping if the grammar checker + //!! failed to properly identify the sentence end + if (aRes.nBehindEndOfSentencePosition <= nStartPos) + { + DBG_ASSERT( 0, "!! Grammarchecker failed to provide end of sentence !!" ); + aRes.nBehindEndOfSentencePosition = nSuggestedEnd; + } + aRes.xFlatParagraph = xFlatPara; aRes.nStartOfSentencePosition = nStartPos; } @@ -718,6 +730,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException) ::osl::ClearableGuard< ::osl::Mutex > aGuard( MyMutex::get() ); aDocId = GetOrCreateDocId( xComponent ); nSuggestedEndOfSentencePos = GetSuggestedEndOfSentence( rText, nStartPos, aCurLocale ); + DBG_ASSERT( nSuggestedEndOfSentencePos > nStartPos, "nSuggestedEndOfSentencePos calculation failed?" ); xGC = GetGrammarChecker( aCurLocale ); } @@ -727,6 +740,15 @@ throw (lang::IllegalArgumentException, uno::RuntimeException) { uno::Sequence< beans::PropertyValue > aEmptyProps; aTmpRes = xGC->doProofreading( aDocId, rText, aCurLocale, nStartPos, nSuggestedEndOfSentencePos, aEmptyProps ); + + //!! work-around to prevent looping if the grammar checker + //!! failed to properly identify the sentence end + if (aTmpRes.nBehindEndOfSentencePosition <= nStartPos) + { + DBG_ASSERT( 0, "!! Grammarchecker failed to provide end of sentence !!" ); + aTmpRes.nBehindEndOfSentencePosition = nSuggestedEndOfSentencePos; + } + aTmpRes.xFlatParagraph = xFlatPara; aTmpRes.nStartOfSentencePosition = nStartPos; nEndPos = aTmpRes.nBehindEndOfSentencePosition; -- cgit v1.2.3