cid#1557346 COPY_INSTEAD_OF_MOVE

Change-Id: Ifcd2f402bdf0295aee13d02ad713262ab51f9743
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170194
Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
This commit is contained in:
Caolán McNamara 2024-07-09 08:48:06 +01:00
parent 0ce14edb62
commit 7b75fc87f0

View file

@ -795,81 +795,80 @@ linguistic2::ProofreadingResult SAL_CALL GrammarCheckingIterator::checkSentenceA
{ {
// for the context menu... // for the context menu...
linguistic2::ProofreadingResult aRes;
uno::Reference< lang::XComponent > xComponent( xDoc, uno::UNO_QUERY ); uno::Reference< lang::XComponent > xComponent( xDoc, uno::UNO_QUERY );
if (xFlatPara.is() && xComponent.is() && const bool bDoCheck = (xFlatPara.is() && xComponent.is() &&
( nErrorPosInPara < 0 || nErrorPosInPara < rText.getLength())) ( nErrorPosInPara < 0 || nErrorPosInPara < rText.getLength()));
if (!bDoCheck)
return linguistic2::ProofreadingResult();
// iterate through paragraph until we find the sentence we are interested in
linguistic2::ProofreadingResult aTmpRes;
sal_Int32 nStartPos = nStartOfSentencePos >= 0 ? nStartOfSentencePos : 0;
bool bFound = false;
do
{ {
// iterate through paragraph until we find the sentence we are interested in lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, nStartPos );
linguistic2::ProofreadingResult aTmpRes; sal_Int32 nOldStartOfSentencePos = nStartPos;
sal_Int32 nStartPos = nStartOfSentencePos >= 0 ? nStartOfSentencePos : 0; uno::Reference< linguistic2::XProofreader > xGC;
OUString aDocId;
bool bFound = false; // ---- THREAD SAFE START ----
do
{ {
lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, nStartPos ); ::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
sal_Int32 nOldStartOfSentencePos = nStartPos; aDocId = GetOrCreateDocId( xComponent );
uno::Reference< linguistic2::XProofreader > xGC; nSuggestedEndOfSentencePos = GetSuggestedEndOfSentence( rText, nStartPos, aCurLocale );
OUString aDocId; DBG_ASSERT( nSuggestedEndOfSentencePos > nStartPos, "nSuggestedEndOfSentencePos calculation failed?" );
// ---- THREAD SAFE START ---- xGC = GetGrammarChecker( aCurLocale );
{
::osl::Guard< ::osl::Mutex > aGuard( MyMutex() );
aDocId = GetOrCreateDocId( xComponent );
nSuggestedEndOfSentencePos = GetSuggestedEndOfSentence( rText, nStartPos, aCurLocale );
DBG_ASSERT( nSuggestedEndOfSentencePos > nStartPos, "nSuggestedEndOfSentencePos calculation failed?" );
xGC = GetGrammarChecker( aCurLocale );
}
// ---- THREAD SAFE START ----
sal_Int32 nEndPos = -1;
if (xGC.is())
{
uno::Sequence<beans::PropertyValue> const aProps(
lcl_makeProperties(xFlatPara, PROOFINFO_GET_PROOFRESULT));
aTmpRes = xGC->doProofreading( aDocId, rText,
aCurLocale, nStartPos, nSuggestedEndOfSentencePos, aProps );
//!! work-around to prevent looping if the grammar checker
//!! failed to properly identify the sentence end
if (aTmpRes.nBehindEndOfSentencePosition <= nStartPos)
{
SAL_WARN( "linguistic", "!! Grammarchecker failed to provide end of sentence !!" );
aTmpRes.nBehindEndOfSentencePosition = nSuggestedEndOfSentencePos;
}
aTmpRes.xFlatParagraph = xFlatPara;
aTmpRes.nStartOfSentencePosition = nStartPos;
nEndPos = aTmpRes.nBehindEndOfSentencePosition;
if ((nErrorPosInPara< 0 || nStartPos <= nErrorPosInPara) && nErrorPosInPara < nEndPos)
bFound = true;
}
if (nEndPos == -1) // no result from grammar checker
nEndPos = nSuggestedEndOfSentencePos;
nStartPos = lcl_SkipWhiteSpaces( rText, nEndPos );
aTmpRes.nBehindEndOfSentencePosition = nEndPos;
aTmpRes.nStartOfNextSentencePosition = nStartPos;
aTmpRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces( rText, aTmpRes.nStartOfNextSentencePosition );
// prevent endless loop by forcefully advancing if needs be...
if (nStartPos <= nOldStartOfSentencePos)
{
SAL_WARN( "linguistic", "end-of-sentence detection failed?" );
nStartPos = nOldStartOfSentencePos + 1;
}
} }
while (!bFound && nStartPos < rText.getLength()); // ---- THREAD SAFE START ----
sal_Int32 nEndPos = -1;
if (xGC.is())
{
uno::Sequence<beans::PropertyValue> const aProps(
lcl_makeProperties(xFlatPara, PROOFINFO_GET_PROOFRESULT));
aTmpRes = xGC->doProofreading( aDocId, rText,
aCurLocale, nStartPos, nSuggestedEndOfSentencePos, aProps );
if (bFound && !xFlatPara->isModified()) //!! work-around to prevent looping if the grammar checker
aRes = aTmpRes; //!! failed to properly identify the sentence end
if (aTmpRes.nBehindEndOfSentencePosition <= nStartPos)
{
SAL_WARN( "linguistic", "!! Grammarchecker failed to provide end of sentence !!" );
aTmpRes.nBehindEndOfSentencePosition = nSuggestedEndOfSentencePos;
}
aTmpRes.xFlatParagraph = xFlatPara;
aTmpRes.nStartOfSentencePosition = nStartPos;
nEndPos = aTmpRes.nBehindEndOfSentencePosition;
if ((nErrorPosInPara< 0 || nStartPos <= nErrorPosInPara) && nErrorPosInPara < nEndPos)
bFound = true;
}
if (nEndPos == -1) // no result from grammar checker
nEndPos = nSuggestedEndOfSentencePos;
nStartPos = lcl_SkipWhiteSpaces( rText, nEndPos );
aTmpRes.nBehindEndOfSentencePosition = nEndPos;
aTmpRes.nStartOfNextSentencePosition = nStartPos;
aTmpRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces( rText, aTmpRes.nStartOfNextSentencePosition );
// prevent endless loop by forcefully advancing if needs be...
if (nStartPos <= nOldStartOfSentencePos)
{
SAL_WARN( "linguistic", "end-of-sentence detection failed?" );
nStartPos = nOldStartOfSentencePos + 1;
}
} }
while (!bFound && nStartPos < rText.getLength());
return aRes; if (bFound && !xFlatPara->isModified())
return aTmpRes;
return linguistic2::ProofreadingResult();
} }
sal_Int32 GrammarCheckingIterator::GetSuggestedEndOfSentence( sal_Int32 GrammarCheckingIterator::GetSuggestedEndOfSentence(
const OUString &rText, const OUString &rText,
sal_Int32 nSentenceStartPos, sal_Int32 nSentenceStartPos,