editeng/qa/unit/core-test.cxx | 9 +---- editeng/source/editeng/edtspell.cxx | 4 +- editeng/source/editeng/edtspell.hxx | 2 - editeng/source/misc/svxacorr.cxx | 61 +++++++++++++++++++----------------- include/editeng/svxacorr.hxx | 12 +++---- sw/source/core/edit/acorrect.cxx | 2 - sw/source/core/edit/autofmt.cxx | 2 - sw/source/core/edit/edws.cxx | 2 - sw/source/core/inc/acorrect.hxx | 2 - 9 files changed, 49 insertions(+), 47 deletions(-)
New commits: commit 163975fd413be1751b8624f8724af441433039d4 Author: Caolán McNamara <[email protected]> Date: Wed Sep 18 13:51:35 2013 +0100 convert SvxAutoCorrect::DoAutoCorrect to OUString which makes autocorrect in the editengine work again Change-Id: I97d56448e4abd6e563479ffee706b86cb04199ec diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx index e8958e1..57c62c3 100644 --- a/editeng/qa/unit/core-test.cxx +++ b/editeng/qa/unit/core-test.cxx @@ -272,8 +272,8 @@ private: //fprintf(stderr, "TestAutoCorrDoc::GetPrevPara\n"); return OUString(); } - virtual sal_Bool ChgAutoCorrWord( sal_uInt16& rSttPos, - sal_uInt16 nEndPos, SvxAutoCorrect& rACorrect, + virtual bool ChgAutoCorrWord( sal_Int32& rSttPos, + sal_Int32 nEndPos, SvxAutoCorrect& rACorrect, OUString* pPara ) { //fprintf(stderr, "TestAutoCorrDoc::ChgAutoCorrWord\n"); @@ -333,10 +333,7 @@ void Test::testAutocorrect() OUString sExpected("foo"); TestAutoCorrDoc aFoo(sInput, LANGUAGE_ENGLISH_US); - String const& rInput2(reinterpret_cast<String const&>(aFoo.getResult())); - aAutoCorrect.DoAutoCorrect(aFoo, - rInput2, - sInput.getLength(), cNextChar, true); + aAutoCorrect.DoAutoCorrect(aFoo, sInput, sInput.getLength(), cNextChar, true); CPPUNIT_ASSERT_EQUAL(sExpected, aFoo.getResult()); } diff --git a/editeng/source/editeng/edtspell.cxx b/editeng/source/editeng/edtspell.cxx index 4ac3157..6787981 100644 --- a/editeng/source/editeng/edtspell.cxx +++ b/editeng/source/editeng/edtspell.cxx @@ -727,8 +727,8 @@ OUString EdtAutoCorrDoc::GetPrevPara( sal_Bool ) } -sal_Bool EdtAutoCorrDoc::ChgAutoCorrWord( sal_uInt16& rSttPos, - sal_uInt16 nEndPos, SvxAutoCorrect& rACorrect, +bool EdtAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, + sal_Int32 nEndPos, SvxAutoCorrect& rACorrect, OUString* pPara ) { // Paragraph-start or a blank found, search for the word diff --git a/editeng/source/editeng/edtspell.hxx b/editeng/source/editeng/edtspell.hxx index 76d0c0d..04a3397 100644 --- a/editeng/source/editeng/edtspell.hxx +++ b/editeng/source/editeng/edtspell.hxx @@ -149,7 +149,7 @@ public: virtual OUString GetPrevPara( sal_Bool bAtNormalPos ); - virtual sal_Bool ChgAutoCorrWord( sal_uInt16& rSttPos, sal_uInt16 nEndPos, + virtual bool ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos, SvxAutoCorrect& rACorrect, OUString* pPara ); virtual LanguageType GetLanguage( sal_uInt16 nPos, sal_Bool bPrevPara = sal_False ) const; diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index ab82308..14d3de7 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -1229,7 +1229,7 @@ OUString SvxAutoCorrect::GetQuote( SvxAutoCorrDoc& rDoc, xub_StrLen nInsPos, } sal_uLong -SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, +SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const OUString& rTxt, xub_StrLen nInsPos, sal_Unicode cChar, sal_Bool bInsert, Window* pFrameWin ) { @@ -1243,7 +1243,7 @@ SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, // Prevent double space if( nInsPos && ' ' == cChar && IsAutoCorrFlag( IgnoreDoubleSpace ) && - ' ' == rTxt.GetChar( nInsPos - 1 ) ) + ' ' == rTxt[ nInsPos - 1 ]) { nRet = IgnoreDoubleSpace; break; @@ -1257,7 +1257,7 @@ SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, { sal_Unicode cPrev; sal_Bool bSttQuote = !nInsPos || - IsWordDelim( ( cPrev = rTxt.GetChar( nInsPos-1 ))) || + IsWordDelim( ( cPrev = rTxt[ nInsPos-1 ])) || lcl_IsInAsciiArr( "([{", cPrev ) || ( cEmDash && cEmDash == cPrev ) || ( cEnDash && cEnDash == cPrev ); @@ -1283,15 +1283,15 @@ SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, else if ( bIsNextRun && !IsAutoCorrectChar( cChar ) ) { // Remove the NBSP if it wasn't an autocorrection - if ( nInsPos != 0 && NeedsHardspaceAutocorr( rTxt.GetChar( nInsPos - 1 ) ) && + if ( nInsPos != 0 && NeedsHardspaceAutocorr( rTxt[ nInsPos - 1 ] ) && cChar != ' ' && cChar != '\t' && cChar != CHAR_HARDBLANK ) { // Look for the last HARD_SPACE - xub_StrLen nPos = nInsPos - 1; + sal_Int32 nPos = nInsPos - 1; bool bContinue = true; while ( bContinue ) { - const sal_Unicode cTmpChar = rTxt.GetChar( nPos ); + const sal_Unicode cTmpChar = rTxt[ nPos ]; if ( cTmpChar == CHAR_HARDBLANK ) { rDoc.Delete( nPos, nPos + 1 ); @@ -1310,13 +1310,13 @@ SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, if( !nInsPos ) break; - xub_StrLen nPos = nInsPos - 1; + sal_Int32 nPos = nInsPos - 1; - if( IsWordDelim( rTxt.GetChar( nPos ))) + if( IsWordDelim( rTxt[ nPos ])) break; // Set bold or underline automatically? - if( '*' == cChar || '_' == cChar ) + if (('*' == cChar || '_' == cChar) && (nPos+1 < rTxt.getLength())) { if( IsAutoCorrFlag( ChgWeightUnderl ) && FnChgWeightUnderl( rDoc, rTxt, 0, nPos+1 ) ) @@ -1324,13 +1324,13 @@ SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, break; } - while( nPos && !IsWordDelim( rTxt.GetChar( --nPos ))) + while( nPos && !IsWordDelim( rTxt[ --nPos ])) ; // Found a Paragraph-start or a Blank, search for the word shortcut in // auto. - xub_StrLen nCapLttrPos = nPos+1; // on the 1st Character - if( !nPos && !IsWordDelim( rTxt.GetChar( 0 ))) + sal_Int32 nCapLttrPos = nPos+1; // on the 1st Character + if( !nPos && !IsWordDelim( rTxt[ 0 ])) --nCapLttrPos; // Absatz Anfang und kein Blank ! LanguageType eLang = rDoc.GetLanguage( nCapLttrPos, sal_False ); @@ -1347,17 +1347,17 @@ SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, OUString aPara; OUString* pPara = IsAutoCorrFlag(CptlSttSntnc) ? &aPara : 0; - sal_Bool bChgWord = rDoc.ChgAutoCorrWord( nCapLttrPos, nInsPos, + bool bChgWord = rDoc.ChgAutoCorrWord( nCapLttrPos, nInsPos, *this, pPara ); if( !bChgWord ) { - xub_StrLen nCapLttrPos1 = nCapLttrPos, nInsPos1 = nInsPos; + sal_Int32 nCapLttrPos1 = nCapLttrPos, nInsPos1 = nInsPos; while( nCapLttrPos1 < nInsPos && - lcl_IsInAsciiArr( sImplSttSkipChars, rTxt.GetChar( nCapLttrPos1 ) ) + lcl_IsInAsciiArr( sImplSttSkipChars, rTxt[ nCapLttrPos1 ] ) ) ++nCapLttrPos1; while( nCapLttrPos1 < nInsPos1 && nInsPos1 && - lcl_IsInAsciiArr( sImplEndSkipChars, rTxt.GetChar( nInsPos1-1 ) ) + lcl_IsInAsciiArr( sImplEndSkipChars, rTxt[ nInsPos1-1 ] ) ) --nInsPos1; @@ -1365,7 +1365,7 @@ SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, nCapLttrPos1 < nInsPos1 && rDoc.ChgAutoCorrWord( nCapLttrPos1, nInsPos1, *this, pPara )) { - bChgWord = sal_True; + bChgWord = true; nCapLttrPos = nCapLttrPos1; } } @@ -1685,7 +1685,7 @@ static void GeneratePackageName ( const OUString& rShort, OUString& rPackageName static const SvxAutocorrWord* lcl_SearchWordsInList( SvxAutoCorrectLanguageListsPtr pList, const String& rTxt, - xub_StrLen& rStt, xub_StrLen nEndPos) + sal_Int32& rStt, sal_Int32 nEndPos) { const SvxAutocorrWordList* pAutoCorrWordList = pList->GetAutocorrWordList(); return pAutoCorrWordList->SearchWordsInList( rTxt, rStt, nEndPos ); @@ -1693,7 +1693,7 @@ static const SvxAutocorrWord* lcl_SearchWordsInList( // the search for the words in the substitution table const SvxAutocorrWord* SvxAutoCorrect::SearchWordsInList( - const OUString& rTxt, xub_StrLen& rStt, xub_StrLen nEndPos, + const OUString& rTxt, sal_Int32& rStt, sal_Int32 nEndPos, SvxAutoCorrDoc&, LanguageType& rLang ) { LanguageType eLang = rLang; @@ -2734,8 +2734,8 @@ SvxAutocorrWordList::Content SvxAutocorrWordList::getSortedContent() const const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *pFnd, const OUString &rTxt, - xub_StrLen &rStt, - xub_StrLen nEndPos) const + sal_Int32 &rStt, + sal_Int32 nEndPos) const { const String& rChk = pFnd->GetShort(); xub_StrLen left_wildcard = ( rChk.GetChar( 0 ) == C_ASTERISK ) ? 1 : 0; // "*word" pattern? @@ -2794,8 +2794,8 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p return NULL; } -const SvxAutocorrWord* SvxAutocorrWordList::SearchWordsInList(const OUString& rTxt, xub_StrLen& rStt, - xub_StrLen nEndPos) const +const SvxAutocorrWord* SvxAutocorrWordList::SearchWordsInList(const OUString& rTxt, sal_Int32& rStt, + sal_Int32 nEndPos) const { for( SvxAutocorrWordList_Hash::const_iterator it = maHash.begin(); it != maHash.end(); ++it ) { diff --git a/include/editeng/svxacorr.hxx b/include/editeng/svxacorr.hxx index b687dc4..cc08b5f3 100644 --- a/include/editeng/svxacorr.hxx +++ b/include/editeng/svxacorr.hxx @@ -104,7 +104,7 @@ public: // (Does not to have to be the same paragraph !!!!) virtual OUString GetPrevPara( sal_Bool bAtNormalPos ) = 0; - virtual sal_Bool ChgAutoCorrWord( xub_StrLen& rSttPos, xub_StrLen nEndPos, + virtual bool ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos, SvxAutoCorrect& rACorrect, OUString* pPara ) = 0; // Is called after the change of the signs by the functions @@ -151,8 +151,8 @@ class EDITENG_DLLPUBLIC SvxAutocorrWordList const SvxAutocorrWord* WordMatches(const SvxAutocorrWord *pFnd, const OUString &rTxt, - xub_StrLen &rStt, - xub_StrLen nEndPos) const; + sal_Int32 &rStt, + sal_Int32 nEndPos) const; public: // free any objects still in the set ~SvxAutocorrWordList(); @@ -165,7 +165,7 @@ public: typedef std::vector<SvxAutocorrWord *> Content; Content getSortedContent() const; - const SvxAutocorrWord* SearchWordsInList(const OUString& rTxt, xub_StrLen& rStt, xub_StrLen nEndPos) const; + const SvxAutocorrWord* SearchWordsInList(const OUString& rTxt, sal_Int32& rStt, sal_Int32 nEndPos) const; }; class EDITENG_DLLPUBLIC SvxAutoCorrectLanguageLists @@ -292,7 +292,7 @@ public: // FIXME: this has the horrible flaw that the rTxt must be a reference // to the actual SwTxtNode/EditNode string because it inserts the character // in rDoc and expects that to side-effect rTxt - sal_uLong DoAutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, + sal_uLong DoAutoCorrect( SvxAutoCorrDoc& rDoc, const OUString& rTxt, xub_StrLen nPos, sal_Unicode cInsChar, sal_Bool bInsert, Window* pFrameWin = NULL ); // Return for the autotext expansion the previous word, @@ -307,7 +307,7 @@ public: // rLang - Input: in which language is searched // Output: in which "language list" was it found const SvxAutocorrWord* SearchWordsInList( const OUString& rTxt, - xub_StrLen& rStt, xub_StrLen nEndPos, + sal_Int32& rStt, sal_Int32 nEndPos, SvxAutoCorrDoc& rDoc, LanguageType& rLang ); diff --git a/sw/source/core/edit/acorrect.cxx b/sw/source/core/edit/acorrect.cxx index 4eb19c7..4599e75 100644 --- a/sw/source/core/edit/acorrect.cxx +++ b/sw/source/core/edit/acorrect.cxx @@ -293,7 +293,7 @@ OUString SwAutoCorrDoc::GetPrevPara( sal_Bool bAtNormalPos ) return aStr; } -sal_Bool SwAutoCorrDoc::ChgAutoCorrWord( xub_StrLen & rSttPos, xub_StrLen nEndPos, +bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos, SvxAutoCorrect& rACorrect, OUString* pPara ) { diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx index 9b4dae9..8d4571a 100644 --- a/sw/source/core/edit/autofmt.cxx +++ b/sw/source/core/edit/autofmt.cxx @@ -1827,7 +1827,7 @@ void SwAutoFormat::AutoCorrect( xub_StrLen nPos ) SwTxtFrmInfo aFInfo( 0 ); - xub_StrLen nSttPos, nLastBlank = nPos; + sal_Int32 nSttPos, nLastBlank = nPos; sal_Bool bFirst = aFlags.bCptlSttSntnc, bFirstSent = bFirst; sal_Unicode cChar = 0; diff --git a/sw/source/core/edit/edws.cxx b/sw/source/core/edit/edws.cxx index e006f56..437189b 100644 --- a/sw/source/core/edit/edws.cxx +++ b/sw/source/core/edit/edws.cxx @@ -254,7 +254,7 @@ void SwEditShell::AutoCorrect( SvxAutoCorrect& rACorr, sal_Bool bInsert, SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCrsr, cChar ); // FIXME: this _must_ be called with reference to the actual node text! - String const& rNodeText(reinterpret_cast<String const&>(pTNd->GetTxt())); + OUString const& rNodeText(pTNd->GetTxt()); rACorr.DoAutoCorrect( aSwAutoCorrDoc, rNodeText, pCrsr->GetPoint()->nContent.GetIndex(), cChar, bInsert, GetWin() ); diff --git a/sw/source/core/inc/acorrect.hxx b/sw/source/core/inc/acorrect.hxx index a7a5e6b..6b6d5a0 100644 --- a/sw/source/core/inc/acorrect.hxx +++ b/sw/source/core/inc/acorrect.hxx @@ -74,7 +74,7 @@ public: // (does not need to be the same paragraph) virtual OUString GetPrevPara( sal_Bool bAtNormalPos ); - virtual sal_Bool ChgAutoCorrWord( xub_StrLen& rSttPos, xub_StrLen nEndPos, + virtual bool ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos, SvxAutoCorrect& rACorrect, OUString* pPara ); commit 5b6dcac8dca72583e25213331bbadc5ec1973646 Author: Caolán McNamara <[email protected]> Date: Wed Sep 18 13:44:24 2013 +0100 comparision of STRING_NOTFOUND to OUString::indexOf Change-Id: I5ad12b594143a3e9ab2399836d30e48deb656639 diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index 2e932e7..ab82308 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -653,8 +653,8 @@ sal_Bool SvxAutoCorrect::FnAddNonBrkSpace( } // Check the presence of "://" in the word - xub_StrLen nStrPos = rTxt.indexOf( "://", nSttWdPos + 1 ); - if ( STRING_NOTFOUND == nStrPos && nEndPos > 0 ) + sal_Int32 nStrPos = rTxt.indexOf( "://", nSttWdPos + 1 ); + if ( nStrPos == -1 && nEndPos > 0 ) { // Check the previous char sal_Unicode cPrevChar = rTxt[ nEndPos - 1 ]; commit 9bb1b4c5a1529a4cca09d0ed3e5325bf9310e814 Author: Caolán McNamara <[email protected]> Date: Wed Sep 18 13:34:35 2013 +0100 don't access string out of bounds Change-Id: I1cee53bc864efaa4ae3b4462111cad4dc80e82be diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx index bb24fe0..2e932e7 100644 --- a/editeng/source/misc/svxacorr.cxx +++ b/editeng/source/misc/svxacorr.cxx @@ -642,11 +642,16 @@ sal_Bool SvxAutoCorrect::FnAddNonBrkSpace( while( nSttWdPos && !(bWasWordDelim = IsWordDelim( rTxt[ --nSttWdPos ]))) ; - if(INetURLObject::CompareProtocolScheme(rTxt.copy(nSttWdPos + (bWasWordDelim ? 1 : 0), nEndPos - nSttWdPos + 1)) != INET_PROT_NOT_VALID) { - return sal_False; + //See if the text is the start of a protocol string, e.g. have text of + //"http" see if it is the start of "http:" and if so leave it alone + sal_Int32 nIndex = nSttWdPos + (bWasWordDelim ? 1 : 0); + sal_Int32 nProtocolLen = nEndPos - nSttWdPos + 1; + if (nIndex + nProtocolLen <= rTxt.getLength()) + { + if (INetURLObject::CompareProtocolScheme(rTxt.copy(nIndex, nProtocolLen)) != INET_PROT_NOT_VALID) + return sal_False; } - // Check the presence of "://" in the word xub_StrLen nStrPos = rTxt.indexOf( "://", nSttWdPos + 1 ); if ( STRING_NOTFOUND == nStrPos && nEndPos > 0 )
_______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
