sc/inc/documentimport.hxx | 4 +- sc/source/core/data/column3.cxx | 12 ++----- sc/source/core/data/documentimport.cxx | 5 +-- sc/source/ui/docshell/impex.cxx | 52 ++++++++++++++++++++------------- test/source/sheet/xspreadsheets2.cxx | 6 +-- 5 files changed, 46 insertions(+), 33 deletions(-)
New commits: commit 4954e2a2f6d99e9c1cfb15435c66bdbbf62f1cd3 Author: Markus Mohrhard <markus.mohrh...@googlemail.com> Date: Mon Oct 28 23:20:20 2013 +0100 simplify code and fix out of bounds read Change-Id: I5be3a28d3d1ae43974f844d143a30bfd989cbe5b diff --git a/test/source/sheet/xspreadsheets2.cxx b/test/source/sheet/xspreadsheets2.cxx index d9d78b6..aa010d3 100644 --- a/test/source/sheet/xspreadsheets2.cxx +++ b/test/source/sheet/xspreadsheets2.cxx @@ -326,10 +326,10 @@ void XSpreadsheets2::importSheetToCopy() bool XSpreadsheets2::isExternalReference(const OUString& aDestContent, const OUString& aSrcContent ) { OUString aStart("'file://"); - const sal_Char* sSrcContent = OUStringToOString( aSrcContent, RTL_TEXTENCODING_UTF8 ).getStr(); - return (aDestContent.endsWithIgnoreAsciiCaseAsciiL(sSrcContent, aSrcContent.getLength()) // same cell address - && aDestContent.indexOf(aStart)==0 // starts with 'file:// + CPPUNIT_ASSERT(aDestContent.startsWith(aStart)); + + return (aDestContent.endsWithIgnoreAsciiCase(aSrcContent, NULL) // same cell address && aDestContent.indexOf(aSrcFileName)>0); // contains source file name } commit 34012133266714259e5b009851924d176199a60d Author: Markus Mohrhard <markus.mohrh...@googlemail.com> Date: Tue Oct 29 02:34:08 2013 +0100 use sal_Int32 instead of xub_StrLen Change-Id: Id868448b5c981d744a066c738b344752bcd0faab diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 1399da2..df74149 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -625,7 +625,7 @@ static bool lcl_appendLineData( OUString& rField, const sal_Unicode* p1, const s OSL_ENSURE( rField.getLength() + (p2 - p1) <= STRING_MAXLEN, "lcl_appendLineData: data overflow"); if (rField.getLength() + (p2 - p1) <= STRING_MAXLEN) { - rField += OUString( p1, sal::static_int_cast<xub_StrLen>( p2 - p1 ) ); + rField += OUString( p1, sal::static_int_cast<sal_Int32>( p2 - p1 ) ); return true; } else @@ -763,7 +763,7 @@ static const sal_Unicode* lcl_ScanSylkString( const sal_Unicode* p, } if (!pEndQuote) pEndQuote = p; // Take all data as string. - rString += OUString(pStartQuote + 1, sal::static_int_cast<xub_StrLen>( pEndQuote - pStartQuote - 1 ) ); + rString += OUString(pStartQuote + 1, sal::static_int_cast<sal_Int32>( pEndQuote - pStartQuote - 1 ) ); lcl_UnescapeSylk( rString, eVersion); return p; } @@ -785,7 +785,7 @@ static const sal_Unicode* lcl_ScanSylkFormula( const sal_Unicode* p, } ++p; } - rString += OUString( pStart, sal::static_int_cast<xub_StrLen>( p - pStart)); + rString += OUString( pStart, sal::static_int_cast<sal_Int32>( p - pStart)); lcl_UnescapeSylk( rString, eVersion); } else @@ -826,7 +826,7 @@ static const sal_Unicode* lcl_ScanSylkFormula( const sal_Unicode* p, { while (*p && *p != ';') ++p; - rString += OUString( pStart, sal::static_int_cast<xub_StrLen>( p - pStart)); + rString += OUString( pStart, sal::static_int_cast<sal_Int32>( p - pStart)); } } return p; @@ -1011,9 +1011,9 @@ static bool lcl_PutString( else if ( nColFormat != SC_COL_STANDARD ) // Datumsformate { const sal_uInt16 nMaxNumberParts = 7; // Y-M-D h:m:s.t - xub_StrLen nLen = rStr.getLength(); - xub_StrLen nStart[nMaxNumberParts]; - xub_StrLen nEnd[nMaxNumberParts]; + sal_Int32 nLen = rStr.getLength(); + sal_Int32 nStart[nMaxNumberParts]; + sal_Int32 nEnd[nMaxNumberParts]; sal_uInt16 nDP, nMP, nYP; switch ( nColFormat ) @@ -1026,7 +1026,7 @@ static bool lcl_PutString( sal_uInt16 nFound = 0; bool bInNum = false; - for ( xub_StrLen nPos=0; nPos<nLen && (bInNum || + for ( sal_Int32 nPos=0; nPos<nLen && (bInNum || nFound<nMaxNumberParts); nPos++ ) { if (bInNum && nFound == 3 && nColFormat == SC_COL_YMD && @@ -1052,8 +1052,8 @@ static bool lcl_PutString( { // try to break one number (without separators) into date fields - xub_StrLen nDateStart = nStart[0]; - xub_StrLen nDateLen = nEnd[0] + 1 - nDateStart; + sal_Int32 nDateStart = nStart[0]; + sal_Int32 nDateLen = nEnd[0] + 1 - nDateStart; if ( nDateLen >= 5 && nDateLen <= 8 && ScGlobal::pCharClass->isNumeric( rStr.copy( nDateStart, nDateLen ) ) ) commit 93959db4d8846cfdfb87ab647c4d457fb09bb869 Author: Markus Mohrhard <markus.mohrh...@googlemail.com> Date: Tue Oct 29 02:31:22 2013 +0100 use DocumentImport for csv import, related fdo#69006 Change-Id: Ib904510b6e897feb787497a4c8ff4204387cf6a4 diff --git a/sc/inc/documentimport.hxx b/sc/inc/documentimport.hxx index 0620301..25d4a03 100644 --- a/sc/inc/documentimport.hxx +++ b/sc/inc/documentimport.hxx @@ -23,6 +23,7 @@ class ScColumn; class ScAddress; class ScTokenArray; class ScFormulaCell; +struct ScSetStringParam; struct ScDocumentImportImpl; /** @@ -59,7 +60,8 @@ public: void setOriginDate(sal_uInt16 nYear, sal_uInt16 nMonth, sal_uInt16 nDay); - void setAutoInput(const ScAddress& rPos, const OUString& rStr); + void setAutoInput(const ScAddress& rPos, const OUString& rStr, + ScSetStringParam* pStringParam = NULL); void setNumericCell(const ScAddress& rPos, double fVal); void setStringCell(const ScAddress& rPos, const OUString& rStr); void setEditCell(const ScAddress& rPos, EditTextObject* pEditText); diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx index 03f5842..99e9b36 100644 --- a/sc/source/core/data/documentimport.cxx +++ b/sc/source/core/data/documentimport.cxx @@ -16,6 +16,7 @@ #include "globalnames.hxx" #include "mtvelements.hxx" #include "tokenarray.hxx" +#include "stringutil.hxx" #include "svl/sharedstringpool.hxx" @@ -81,7 +82,7 @@ void ScDocumentImport::setOriginDate(sal_uInt16 nYear, sal_uInt16 nMonth, sal_uI mpImpl->mrDoc.pDocOptions->SetDate(nDay, nMonth, nYear); } -void ScDocumentImport::setAutoInput(const ScAddress& rPos, const OUString& rStr) +void ScDocumentImport::setAutoInput(const ScAddress& rPos, const OUString& rStr, ScSetStringParam* pStringParam) { ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab()); if (!pTab) @@ -95,7 +96,7 @@ void ScDocumentImport::setAutoInput(const ScAddress& rPos, const OUString& rStr) ScCellValue aCell; pTab->aCol[rPos.Col()].ParseString( - aCell, rPos.Row(), rPos.Tab(), rStr, mpImpl->mrDoc.GetAddressConvention(), NULL); + aCell, rPos.Row(), rPos.Tab(), rStr, mpImpl->mrDoc.GetAddressConvention(), pStringParam); sc::CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells; switch (aCell.meType) diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index fccafbe..1399da2 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -49,6 +49,7 @@ #include "stringutil.hxx" #include "cellvalue.hxx" #include "tokenarray.hxx" +#include "documentimport.hxx" #include "globstr.hrc" #include <vcl/svapp.hxx> @@ -954,11 +955,12 @@ bool ScImportExport::Text2Doc( SvStream& rStrm ) static bool lcl_PutString( - ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString& rStr, sal_uInt8 nColFormat, + ScDocumentImport& rDocImport, SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString& rStr, sal_uInt8 nColFormat, SvNumberFormatter* pFormatter, bool bDetectNumFormat, ::utl::TransliterationWrapper& rTransliteration, CalendarWrapper& rCalendar, ::utl::TransliterationWrapper* pSecondTransliteration, CalendarWrapper* pSecondCalendar ) { + ScDocument* pDoc = &rDocImport.getDoc(); bool bMultiLine = false; if ( nColFormat == SC_COL_SKIP || rStr.isEmpty() || !ValidCol(nCol) || !ValidRow(nRow) ) return bMultiLine; @@ -977,8 +979,18 @@ static bool lcl_PutString( pDoc->ApplyPattern(nCol, nRow, nTab, aNewAttrs); } - pDoc->SetTextCell(ScAddress(nCol,nRow,nTab), rStr); - return bMultiLine; + if(ScStringUtil::isMultiline(rStr)) + { + ScFieldEditEngine& rEngine = pDoc->GetEditEngine(); + rEngine.SetText(rStr); + rDocImport.setEditCell(ScAddress(nCol, nRow, nTab), rEngine.CreateTextObject()); + return true; + } + else + { + rDocImport.setStringCell(ScAddress(nCol, nRow, nTab), rStr); + return false; + } } if ( nColFormat == SC_COL_ENGLISH ) @@ -991,7 +1003,7 @@ static bool lcl_PutString( if ( pDocFormatter->IsNumberFormat( rStr, nEnglish, fVal ) ) { // Zahlformat wird nicht auf englisch gesetzt - pDoc->SetValue( nCol, nRow, nTab, fVal ); + rDocImport.setNumericCell( ScAddress( nCol, nRow, nTab ), fVal ); return bMultiLine; } // sonst weiter mit SetString @@ -1180,7 +1192,7 @@ static bool lcl_PutString( nFormat = pDocFormatter->GetStandardFormat( fDays, nFormat, nType, eDocLang); ScAddress aPos(nCol,nRow,nTab); - pDoc->SetValue(aPos, fDays); + rDocImport.setNumericCell(aPos, fDays); pDoc->SetNumberFormat(aPos, nFormat); return bMultiLine; // success @@ -1197,14 +1209,14 @@ static bool lcl_PutString( aParam.mbDetectNumberFormat = bDetectNumFormat; aParam.meSetTextNumFormat = ScSetStringParam::SpecialNumberOnly; aParam.mbHandleApostrophe = false; - pDoc->SetString( nCol, nRow, nTab, rStr, &aParam ); + rDocImport.setAutoInput(ScAddress(nCol, nRow, nTab), rStr, &aParam); } else { bMultiLine = true; ScFieldEditEngine& rEngine = pDoc->GetEditEngine(); rEngine.SetText(rStr); - pDoc->SetEditText(ScAddress(nCol,nRow,nTab), rEngine.CreateTextObject()); + rDocImport.setEditCell(ScAddress(nCol, nRow, nTab), rEngine.CreateTextObject()); } return bMultiLine; } @@ -1327,6 +1339,7 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) sal_uLong nOriginalStreamPos = rStrm.Tell(); + ScDocumentImport aDocImport(*pDoc); do { for( ;; ) @@ -1363,7 +1376,7 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) nFmt = SC_COL_TEXT; bMultiLine |= lcl_PutString( - pDoc, nCol, nRow, nTab, aCell, nFmt, + aDocImport, nCol, nRow, nTab, aCell, nFmt, &aNumFormatter, bDetectNumFormat, aTransliteration, aCalendar, pEnglishTransliteration.get(), pEnglishCalendar.get()); } @@ -1406,7 +1419,7 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) nFmt = SC_COL_TEXT; bMultiLine |= lcl_PutString( - pDoc, nCol, nRow, nTab, aCell, nFmt, + aDocImport, nCol, nRow, nTab, aCell, nFmt, &aNumFormatter, bDetectNumFormat, aTransliteration, aCalendar, pEnglishTransliteration.get(), pEnglishCalendar.get()); } @@ -1464,6 +1477,7 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) bDetermineRange = !bDetermineRange; // toggle } while (!bDetermineRange); + aDocImport.finalize(); xProgress.reset(); // make room for AdjustRowHeight progress if (bRangeIsDetermined) commit 3757128f488bf47c51c2064daea90155601242b2 Author: Markus Mohrhard <markus.mohrh...@googlemail.com> Date: Tue Oct 29 02:00:44 2013 +0100 variable can never be NULL in this place Change-Id: I806a5ce53f1f290d6e37fe4afdd574b52b98fcce diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index da5cdbb..e1cb2a1 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -1542,13 +1542,10 @@ bool ScColumn::ParseString( if (!aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal)) break; - if ( aParam.mpNumFormatter ) - { - // convert back to the original language if a built-in format was detected - const SvNumberformat* pOldFormat = aParam.mpNumFormatter->GetEntry( nOldIndex ); - if ( pOldFormat ) - nIndex = aParam.mpNumFormatter->GetFormatForLanguageIfBuiltIn( nIndex, pOldFormat->GetLanguage() ); - } + // convert back to the original language if a built-in format was detected + const SvNumberformat* pOldFormat = aParam.mpNumFormatter->GetEntry( nOldIndex ); + if ( pOldFormat ) + nIndex = aParam.mpNumFormatter->GetFormatForLanguageIfBuiltIn( nIndex, pOldFormat->GetLanguage() ); rCell.set(nVal); if ( nIndex != nOldIndex) @@ -1558,7 +1555,6 @@ bool ScColumn::ParseString( // Exception: If the new format is boolean, always apply it. bool bOverwrite = false; - const SvNumberformat* pOldFormat = aParam.mpNumFormatter->GetEntry( nOldIndex ); if ( pOldFormat ) { short nOldType = pOldFormat->GetType() & ~NUMBERFORMAT_DEFINED; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits