sc/inc/filter.hxx | 17 -- sc/source/filter/dif/difimp.cxx | 304 +++------------------------------------- sc/source/filter/inc/dif.hxx | 29 --- sc/source/filter/inc/ftools.hxx | 2 sc/source/ui/docshell/impex.cxx | 2 5 files changed, 29 insertions(+), 325 deletions(-)
New commits: commit a7b5be118191a4e8a6cd422b5b2438a1ac22f36f Author: Jochen Nitschke <j.nitschke+loger...@ok.de> Date: Mon Jul 18 09:45:30 2016 +0200 sc dif import: plain number formatter is unused commit 2cb7d3c13cc55d8ee680fe19d99819529d8b9ba5 revealed DifOptions is always set to DifOptions::Excel, so DifParser.bPlain is never true. remove import with plain number formatter and DifOptions enum Change-Id: I8e214f3fff8ecfc7e03622dd1fe3fb53c2fb1e25 Reviewed-on: https://gerrit.libreoffice.org/27277 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noelgran...@gmail.com> diff --git a/sc/inc/filter.hxx b/sc/inc/filter.hxx index aaeb9f3..e51ee3a 100644 --- a/sc/inc/filter.hxx +++ b/sc/inc/filter.hxx @@ -20,7 +20,6 @@ #ifndef INCLUDED_SC_INC_FILTER_HXX #define INCLUDED_SC_INC_FILTER_HXX -#include <o3tl/typed_flags_set.hxx> #include <rtl/textenc.h> #include <rtl/ustring.hxx> #include <tools/solar.h> @@ -60,20 +59,6 @@ enum EXCIMPFORMAT { EIF_AUTO, EIF_BIFF5, EIF_BIFF8, EIF_BIFF_LE4 }; enum ExportFormatLotus { ExpWK1, ExpWK3, ExpWK4 }; enum ExportFormatExcel { ExpBiff2, ExpBiff3, ExpBiff4, ExpBiff4W, ExpBiff5, ExpBiff8, Exp2007Xml }; -// options for DIF im-/export (combine with '|') -enum class DifOptions -{ - Plain = 0x00000000, - Date = 0x00000001, - Time = 0x00000002, - Currency = 0x00000004, - - Excel = (Date|Time|Currency) -}; -namespace o3tl { - template<> struct typed_flags<DifOptions> : is_typed_flags<DifOptions, 0x00000007> {}; -} - // These are implemented inside the scfilt library and lazy loaded class ScEEAbsImport { @@ -98,7 +83,7 @@ class SAL_DLLPUBLIC_RTTI ScFormatFilterPlugin { // eFormat == EIF_BIFF_LE4 -> only non storage files _might_ be read successfully virtual FltError ScImportStarCalc10( SvStream&, ScDocument* ) = 0; virtual FltError ScImportDif( SvStream&, ScDocument*, const ScAddress& rInsPos, - const rtl_TextEncoding eSrc = RTL_TEXTENCODING_DONTKNOW, DifOptions nDifOption = DifOptions::Excel ) = 0; + const rtl_TextEncoding eSrc = RTL_TEXTENCODING_DONTKNOW ) = 0; virtual FltError ScImportRTF( SvStream&, const OUString& rBaseURL, ScDocument*, ScRange& rRange ) = 0; virtual FltError ScImportHTML( SvStream&, const OUString& rBaseURL, ScDocument*, ScRange& rRange, double nOutputFactor = 1.0, bool bCalcWidthHeight = true, SvNumberFormatter* pFormatter = nullptr, bool bConvertDate = true ) = 0; diff --git a/sc/source/filter/dif/difimp.cxx b/sc/source/filter/dif/difimp.cxx index 704bf66..5b5b936 100644 --- a/sc/source/filter/dif/difimp.cxx +++ b/sc/source/filter/dif/difimp.cxx @@ -48,11 +48,9 @@ const sal_Unicode pKeyV[] = { 'V', 0 }; const sal_Unicode pKey1_0[] = { '1', ',', '0', 0 }; FltError ScFormatFilterPluginImpl::ScImportDif(SvStream& rIn, ScDocument* pDoc, const ScAddress& rInsPos, - const rtl_TextEncoding eVon, DifOptions nDifOption ) + const rtl_TextEncoding eVon ) { - DifParser aDifParser( rIn, nDifOption, *pDoc, eVon ); - - const bool bPlain = aDifParser.IsPlain(); + DifParser aDifParser( rIn, *pDoc, eVon ); SCTAB nBaseTab = rInsPos.Tab(); @@ -126,7 +124,7 @@ FltError ScFormatFilterPluginImpl::ScImportDif(SvStream& rIn, ScDocument* pDoc, SCCOL nColCnt = SCCOL_MAX; SCROW nRowCnt = rInsPos.Row(); - DifAttrCache aAttrCache( bPlain ); + DifAttrCache aAttrCache; DATASET eAkt = D_UNKNOWN; @@ -160,18 +158,14 @@ FltError ScFormatFilterPluginImpl::ScImportDif(SvStream& rIn, ScDocument* pDoc, if( DifParser::IsV( aData.getStr() ) ) { pDoc->SetValue(aPos, aDifParser.fVal); - if( !bPlain ) - aAttrCache.SetNumFormat( nColCnt, nRowCnt, + aAttrCache.SetNumFormat( nColCnt, nRowCnt, aDifParser.nNumFormat ); } else if( aData == pKeyTRUE || aData == pKeyFALSE ) { pDoc->SetValue(aPos, aDifParser.fVal); - if( bPlain ) - aAttrCache.SetLogical( nColCnt, nRowCnt ); - else - aAttrCache.SetNumFormat( nColCnt, nRowCnt, - aDifParser.nNumFormat ); + aAttrCache.SetNumFormat( nColCnt, nRowCnt, + aDifParser.nNumFormat ); } else if( aData == pKeyNA || aData == pKeyERROR ) { @@ -230,12 +224,13 @@ FltError ScFormatFilterPluginImpl::ScImportDif(SvStream& rIn, ScDocument* pDoc, return eERR_OK; } -DifParser::DifParser(SvStream& rNewIn, DifOptions nOption, ScDocument& rDoc, rtl_TextEncoding e ) +DifParser::DifParser( SvStream& rNewIn, ScDocument& rDoc, rtl_TextEncoding e ) : fVal(0.0) , nVector(0) , nVal(0) , nNumFormat(0) , eCharSet(e) + , pNumFormatter(rDoc.GetFormatTable()) , rIn(rNewIn) { if ( rIn.GetStreamCharSet() != eCharSet ) @@ -244,13 +239,6 @@ DifParser::DifParser(SvStream& rNewIn, DifOptions nOption, ScDocument& rDoc, rtl rIn.SetStreamCharSet( eCharSet ); } rIn.StartReadingUnicodeText( eCharSet ); - - bPlain = ( nOption == DifOptions::Plain ); - - if( bPlain ) - pNumFormatter = nullptr; - else - pNumFormatter = rDoc.GetFormatTable(); } TOPIC DifParser::GetNextTopic() @@ -410,28 +398,20 @@ static void lcl_DeEscapeQuotesDif( OUString& rString ) DATASET DifParser::GetNumberDataset( const sal_Unicode* pPossibleNumericData ) { DATASET eRet = D_SYNT_ERROR; - if( bPlain ) + + OSL_ENSURE( pNumFormatter, "-DifParser::GetNumberDataset(): No Formatter, more fun!" ); + OUString aTestVal( pPossibleNumericData ); + sal_uInt32 nFormat = 0; + double fTmpVal; + if( pNumFormatter->IsNumberFormat( aTestVal, nFormat, fTmpVal ) ) { - if( ScanFloatVal( pPossibleNumericData ) ) - eRet = D_NUMERIC; - else - eRet = D_SYNT_ERROR; + fVal = fTmpVal; + nNumFormat = nFormat; + eRet = D_NUMERIC; } else - { // ...and for punishment, with number formatting... - OSL_ENSURE( pNumFormatter, "-DifParser::GetNextDataset(): No Formatter, more fun!" ); - OUString aTestVal( pPossibleNumericData ); - sal_uInt32 nFormat = 0; - double fTmpVal; - if( pNumFormatter->IsNumberFormat( aTestVal, nFormat, fTmpVal ) ) - { - fVal = fTmpVal; - nNumFormat = nFormat; - eRet = D_NUMERIC; - } - else - eRet = D_SYNT_ERROR; - } + eRet = D_SYNT_ERROR; + return eRet; } @@ -629,214 +609,11 @@ const sal_Unicode* DifParser::ScanIntVal( const sal_Unicode* pStart, sal_uInt32& return pStart; } -bool DifParser::ScanFloatVal( const sal_Unicode* pStart ) -{ - bool bNeg = false; - double fFracPos = 1.0; - sal_Int32 nExp = 0; - bool bExpNeg = false; - bool bExpOverflow = false; - static const sal_uInt16 nExpLimit = 4096; // FIXME: has to be set more accurately! - - sal_Unicode cAkt; - bool bRet = false; - - enum STATE { S_FIRST, S_PRE, S_POST, S_EXP_FIRST, S_EXP, S_END, S_FINDEND }; - - STATE eS = S_FIRST; - - double fNewVal = 0.0; - - while( eS != S_END ) - { - cAkt = *pStart; - switch( eS ) - { - case S_FIRST: - if( IsNumber( cAkt ) ) - { - fNewVal *= 10; - fNewVal += cAkt - '0'; - eS = S_PRE; - } - else - { - switch( cAkt ) - { - case ' ': - case '\t': - case '+': - break; - case '-': - bNeg = !bNeg; - break; - case '.': - case ',': - eS = S_POST; - fFracPos = 0.1; - break; - default: - eS = S_END; - } - } - break; - case S_PRE: - if( IsNumber( cAkt ) ) - { - fNewVal *= 10; - fNewVal += cAkt - '0'; - } - else - { - switch( cAkt ) - { - case '.': - case ',': - eS = S_POST; - fFracPos = 0.1; - break; - case 'e': - case 'E': - eS = S_EXP; - break; - case 0x00: // IsNumberEnding( cAkt ) - bRet = true; - SAL_FALLTHROUGH; - default: - eS = S_END; - } - } - break; - case S_POST: - if( IsNumber( cAkt ) ) - { - fNewVal += fFracPos * ( cAkt - '0' ); - fFracPos /= 10.0; - } - else - { - switch( cAkt ) - { - case 'e': - case 'E': - eS = S_EXP_FIRST; - break; - case 0x00: // IsNumberEnding( cAkt ) - bRet = true; - SAL_FALLTHROUGH; - default: - eS = S_END; - } - } - break; - case S_EXP_FIRST: - if( IsNumber( cAkt ) ) - { - if( nExp < nExpLimit ) - { - nExp *= 10; - nExp += ( sal_uInt16 ) ( cAkt - '0' ); - } - eS = S_EXP; - } - else - { - switch( cAkt ) - { - case '+': - break; - case '-': - bExpNeg = !bExpNeg; - break; - default: - eS = S_END; - } - } - break; - case S_EXP: - if( IsNumber( cAkt ) ) - { - if( nExp < ( 0xFFFF / 10 ) ) - { - nExp *= 10; - nExp += ( sal_uInt16 ) ( cAkt - '0' ); - } - else - { - bExpOverflow = true; - eS = S_FINDEND; - } - } - else - { - bRet = IsNumberEnding( cAkt ); - eS = S_END; - } - break; - case S_FINDEND: - if( IsNumberEnding( cAkt ) ) - { - bRet = true; // to continue parsing - eS = S_END; - } - break; - // coverity[dead_error_begin] - following conditions exist to avoid compiler warning - case S_END: - OSL_FAIL( "DifParser::ScanFloatVal - unexpected state" ); - break; - default: - OSL_FAIL( "DifParser::ScanFloatVal - missing enum" ); - } - pStart++; - } - - if( bRet ) - { - if( bExpOverflow ) - return false; // FIXME: add special cases here - - if( bNeg ) - fNewVal *= 1.0; - - if( bExpNeg ) - nExp *= -1; - - if( nExp != 0 ) - fNewVal *= pow( 10.0, ( double ) nExp ); - fVal = fNewVal; - } - - return bRet; -} - DifColumn::DifColumn () : mpAkt(nullptr) { } -void DifColumn::SetLogical( SCROW nRow ) -{ - OSL_ENSURE( ValidRow(nRow), "*DifColumn::SetLogical(): Row too big!" ); - - if( mpAkt ) - { - OSL_ENSURE( nRow > 0, "*DifColumn::SetLogical(): more cannot be zero!" ); - - nRow--; - - if( mpAkt->nEnd == nRow ) - mpAkt->nEnd++; - else - mpAkt = nullptr; - } - else - { - maEntries.push_back(ENTRY()); - mpAkt = &maEntries.back(); - mpAkt->nStart = mpAkt->nEnd = nRow; - } -} - void DifColumn::SetNumFormat( SCROW nRow, const sal_uInt32 nNumFormat ) { OSL_ENSURE( ValidRow(nRow), "*DifColumn::SetNumFormat(): Row too big!" ); @@ -895,9 +672,8 @@ void DifColumn::Apply( ScDocument& rDoc, const SCCOL nCol, const SCTAB nTab ) } } -DifAttrCache::DifAttrCache( const bool bNewPlain ) +DifAttrCache::DifAttrCache() { - bPlain = bNewPlain; ppCols = new DifColumn *[ MAXCOL + 1 ]; for( SCCOL nCnt = 0 ; nCnt <= MAXCOL ; nCnt++ ) ppCols[ nCnt ] = nullptr; @@ -914,21 +690,9 @@ DifAttrCache::~DifAttrCache() delete[] ppCols; } -void DifAttrCache::SetLogical( const SCCOL nCol, const SCROW nRow ) -{ - OSL_ENSURE( ValidCol(nCol), "-DifAttrCache::SetLogical(): Col too big!" ); - OSL_ENSURE( bPlain, "*DifAttrCache::SetLogical(): has to be Plain!" ); - - if( !ppCols[ nCol ] ) - ppCols[ nCol ] = new DifColumn; - - ppCols[ nCol ]->SetLogical( nRow ); -} - void DifAttrCache::SetNumFormat( const SCCOL nCol, const SCROW nRow, const sal_uInt32 nNumFormat ) { OSL_ENSURE( ValidCol(nCol), "-DifAttrCache::SetNumFormat(): Col too big!" ); - OSL_ENSURE( !bPlain, "*DifAttrCache::SetNumFormat(): should not be Plain!" ); if( !ppCols[ nCol ] ) ppCols[ nCol ] = new DifColumn; @@ -938,32 +702,10 @@ void DifAttrCache::SetNumFormat( const SCCOL nCol, const SCROW nRow, const sal_u void DifAttrCache::Apply( ScDocument& rDoc, SCTAB nTab ) { - if( bPlain ) - { - std::unique_ptr<ScPatternAttr> pPatt; - - for( SCCOL nCol = 0 ; nCol <= MAXCOL ; nCol++ ) - { - if( ppCols[ nCol ] ) - { - if( !pPatt ) - { - pPatt.reset(new ScPatternAttr( rDoc.GetPool() )); - pPatt->GetItemSet().Put( SfxUInt32Item( ATTR_VALUE_FORMAT, - rDoc.GetFormatTable()->GetStandardFormat( css::util::NumberFormat::LOGICAL ) ) ); - } - - ppCols[ nCol ]->Apply( rDoc, nCol, nTab, *pPatt ); - } - } - } - else + for( SCCOL nCol = 0 ; nCol <= MAXCOL ; nCol++ ) { - for( SCCOL nCol = 0 ; nCol <= MAXCOL ; nCol++ ) - { - if( ppCols[ nCol ] ) - ppCols[ nCol ]->Apply( rDoc, nCol, nTab ); - } + if( ppCols[ nCol ] ) + ppCols[ nCol ]->Apply( rDoc, nCol, nTab ); } } diff --git a/sc/source/filter/inc/dif.hxx b/sc/source/filter/inc/dif.hxx index 9892408..56d2e7d 100644 --- a/sc/source/filter/inc/dif.hxx +++ b/sc/source/filter/inc/dif.hxx @@ -55,10 +55,6 @@ enum TOPIC enum DATASET { D_BOT, D_EOD, D_NUMERIC, D_STRING, D_UNKNOWN, D_SYNT_ERROR }; -class DifAttrCache; -class ScPatternAttr; -enum class DifOptions; - class DifParser { public: @@ -71,7 +67,6 @@ public: private: SvNumberFormatter* pNumFormatter; SvStream& rIn; - bool bPlain; OUString aLookAheadLine; bool ReadNextLine( OUString& rStr ); @@ -81,21 +76,17 @@ private: static inline bool IsEOD( const sal_Unicode* pRef ); static inline bool Is1_0( const sal_Unicode* pRef ); public: - DifParser( SvStream&, DifOptions nOption, ScDocument&, rtl_TextEncoding ); + DifParser( SvStream&, ScDocument&, rtl_TextEncoding ); TOPIC GetNextTopic(); DATASET GetNextDataset(); static const sal_Unicode* ScanIntVal( const sal_Unicode* pStart, sal_uInt32& rRet ); - bool ScanFloatVal( const sal_Unicode* pStart ); static inline bool IsNumber( const sal_Unicode cChar ); - static inline bool IsNumberEnding( const sal_Unicode cChar ); static inline bool IsV( const sal_Unicode* pRef ); - - inline bool IsPlain() const; }; inline bool DifParser::IsBOT( const sal_Unicode* pRef ) @@ -133,16 +124,7 @@ inline bool DifParser::IsNumber( const sal_Unicode cChar ) return ( cChar >= '0' && cChar <= '9' ); } -inline bool DifParser::IsNumberEnding( const sal_Unicode cChar ) -{ - return ( cChar == 0x00 ); -} - -inline bool DifParser::IsPlain() const -{ - return bPlain; -} - +class DifAttrCache; class DifColumn { friend class DifAttrCache; @@ -159,8 +141,6 @@ class DifColumn DifColumn(); - void SetLogical( SCROW nRow ); - void SetNumFormat( SCROW nRow, const sal_uInt32 nNumFormat ); void NewEntry( const SCROW nPos, const sal_uInt32 nNumFormat ); @@ -174,12 +154,10 @@ class DifAttrCache { public: - DifAttrCache( const bool bPlain ); + DifAttrCache(); ~DifAttrCache(); - void SetLogical( const SCCOL nCol, const SCROW nRow ); - void SetNumFormat( const SCCOL nCol, const SCROW nRow, const sal_uInt32 nNumFormat ); void Apply( ScDocument&, SCTAB nTab ); @@ -187,7 +165,6 @@ public: private: DifColumn** ppCols; - bool bPlain; }; #endif diff --git a/sc/source/filter/inc/ftools.hxx b/sc/source/filter/inc/ftools.hxx index 2f3d3d8..85ed6b1 100644 --- a/sc/source/filter/inc/ftools.hxx +++ b/sc/source/filter/inc/ftools.hxx @@ -276,7 +276,7 @@ public: // eFormat == EIF_BIFF_LE4 -> nur Nicht-Storage-Dateien _koennen_ zum Erfolg fuehren virtual FltError ScImportStarCalc10( SvStream&, ScDocument* ) override; virtual FltError ScImportDif( SvStream&, ScDocument*, const ScAddress& rInsPos, - const rtl_TextEncoding eSrc = RTL_TEXTENCODING_DONTKNOW, DifOptions nDifOption = DifOptions::Excel ) override; + const rtl_TextEncoding eSrc = RTL_TEXTENCODING_DONTKNOW ) override; virtual FltError ScImportRTF( SvStream&, const OUString& rBaseURL, ScDocument*, ScRange& rRange ) override; virtual FltError ScImportHTML( SvStream&, const OUString& rBaseURL, ScDocument*, ScRange& rRange, double nOutputFactor = 1.0, bool bCalcWidthHeight = true, diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index a98ad1f..5abc8a8 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -2221,7 +2221,7 @@ class ScFormatFilterMissing : public ScFormatFilterPlugin { virtual FltError ScImportExcel( SfxMedium&, ScDocument*, const EXCIMPFORMAT ) override { return eERR_INTERN; } virtual FltError ScImportStarCalc10( SvStream&, ScDocument* ) override { return eERR_INTERN; } virtual FltError ScImportDif( SvStream&, ScDocument*, const ScAddress&, - const rtl_TextEncoding, DifOptions ) override { return eERR_INTERN; } + const rtl_TextEncoding ) override { return eERR_INTERN; } virtual FltError ScImportRTF( SvStream&, const OUString&, ScDocument*, ScRange& ) override { return eERR_INTERN; } virtual FltError ScImportHTML( SvStream&, const OUString&, ScDocument*, ScRange&, double, bool, SvNumberFormatter*, bool ) override { return eERR_INTERN; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits