[Libreoffice-commits] core.git: sc/inc sc/source
László Németh
laszlo.nemeth at collabora.com
Thu Jan 29 13:11:40 PST 2015
sc/inc/address.hxx | 5
sc/source/core/tool/address.cxx | 192 +++++++++++++++---------------------
sc/source/filter/excel/xeroot.cxx | 2
sc/source/filter/excel/xestream.cxx | 14 --
sc/source/filter/excel/xetable.cxx | 6 -
sc/source/filter/excel/xeview.cxx | 6 -
sc/source/filter/inc/xestream.hxx | 2
7 files changed, 94 insertions(+), 133 deletions(-)
New commits:
commit f0152b737d9a196e83752a546154735efee5c2be
Author: László Németh <laszlo.nemeth at collabora.com>
Date: Thu Jan 29 21:12:12 2015 +0100
tdf#88810 XLSX export: more cleanup
Change-Id: I2a4ddb2e3a3ff629243dba46880b8c986dfde2dc
diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx
index a745c73..6bf55340 100644
--- a/sc/inc/address.hxx
+++ b/sc/inc/address.hxx
@@ -326,9 +326,10 @@ public:
ExternalInfo* pExtInfo = NULL,
const css::uno::Sequence<css::sheet::ExternalLinkInfo>* pExternalLinks = NULL );
- SC_DLLPUBLIC bool TryFormat( OStringBuffer& s, sal_uInt16 nFlags = 0,
+ SC_DLLPUBLIC void Format( OStringBuffer& r, sal_uInt16 nFlags = 0,
const ScDocument* pDocument = NULL,
const Details& rDetails = detailsOOOa1) const;
+
SC_DLLPUBLIC OUString Format( sal_uInt16 nFlags = 0,
const ScDocument* pDocument = NULL,
const Details& rDetails = detailsOOOa1) const;
@@ -892,8 +893,6 @@ bool ConvertDoubleRef( ScDocument* pDocument, const OUString& rRefString,
/// append alpha representation of column to buffer
SC_DLLPUBLIC void ScColToAlpha( OUStringBuffer& rBuffer, SCCOL nCol);
-SC_DLLPUBLIC void ScColToAlpha( OStringBuffer& rBuffer, SCCOL nCol);
-
inline void ScColToAlpha( OUString& rStr, SCCOL nCol)
{
OUStringBuffer aBuf(2);
diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx
index 36cdb92..8fd08fa 100644
--- a/sc/source/core/tool/address.cxx
+++ b/sc/source/core/tool/address.cxx
@@ -1672,50 +1672,93 @@ sal_uInt16 ScRange::ParseRows( const OUString& rStr, ScDocument* pDoc,
return (p != NULL && *p == '\0') ? nRes : 0;
}
-static inline void lcl_a1_append_c ( OUStringBuffer &rString, int nCol, bool bIsAbs )
+template<typename T > static inline void lcl_ScColToAlpha( T& rBuf, SCCOL nCol )
+{
+ if (nCol < 26*26)
+ {
+ if (nCol < 26)
+ rBuf.append( static_cast<char>( 'A' + nCol ));
+ else
+ {
+ rBuf.append( static_cast<char>( 'A' + nCol / 26 - 1 ));
+ rBuf.append( static_cast<char>( 'A' + nCol % 26 ));
+ }
+ }
+ else
+ {
+ sal_Int32 nInsert = rBuf.getLength();
+ while (nCol >= 26)
+ {
+ SCCOL nC = nCol % 26;
+ rBuf.insert(nInsert, static_cast<char> ( 'A' + nC ));
+ nCol = sal::static_int_cast<SCCOL>( nCol - nC );
+ nCol = nCol / 26 - 1;
+ }
+ rBuf.insert(nInsert, static_cast<char> ( 'A' + nCol ));
+ }
+}
+
+void ScColToAlpha( OUStringBuffer& rBuf, SCCOL nCol)
+{
+ lcl_ScColToAlpha(rBuf, nCol);
+}
+
+template <typename T > static inline void lcl_a1_append_c ( T &rString, int nCol, bool bIsAbs )
{
if( bIsAbs )
rString.append("$");
- ScColToAlpha( rString, sal::static_int_cast<SCCOL>(nCol) );
+ lcl_ScColToAlpha( rString, sal::static_int_cast<SCCOL>(nCol) );
}
-static inline void lcl_a1_append_r ( OUStringBuffer &rString, int nRow, bool bIsAbs )
+static inline void lcl_string_append_number(OUStringBuffer &rString, int nNumber)
+{
+ rString.append(OUString::number( nNumber ));
+}
+
+static inline void lcl_string_append_number(OStringBuffer &rString, int nNumber)
+{
+ rString.append(OString::number( nNumber ));
+}
+
+template <typename T > static inline void lcl_a1_append_r ( T &rString, int nRow, bool bIsAbs )
{
if ( bIsAbs )
rString.append("$");
- rString.append(OUString::number( nRow+1 ));
+ lcl_string_append_number(rString, nRow+1 );
}
-static inline void lcl_r1c1_append_c ( OUStringBuffer &rString, int nCol, bool bIsAbs,
+template <typename T > static inline void lcl_r1c1_append_c ( T &rString, int nCol, bool bIsAbs,
const ScAddress::Details& rDetails )
{
rString.append("C");
if (bIsAbs)
{
- rString.append(OUString::number( nCol + 1 ));
+ lcl_string_append_number(rString, nCol + 1 );
}
else
{
nCol -= rDetails.nCol;
if (nCol != 0) {
- rString.append("[").append(OUString::number( nCol )).append("]");
+ lcl_string_append_number(rString.append("["), nCol );
+ rString.append("]");
}
}
}
-static inline void lcl_r1c1_append_r ( OUStringBuffer &rString, int nRow, bool bIsAbs,
+template <typename T > static inline void lcl_r1c1_append_r ( T &rString, int nRow, bool bIsAbs,
const ScAddress::Details& rDetails )
{
rString.append("R");
if (bIsAbs)
{
- rString.append(OUString::number( nRow + 1 ));
+ lcl_string_append_number(rString, nRow + 1 );
}
else
{
nRow -= rDetails.nRow;
if (nRow != 0) {
- rString.append("[").append(OUString::number( nRow )).append("]");
+ lcl_string_append_number(rString.append("["), nRow);
+ rString.append("]");
}
}
}
@@ -1745,51 +1788,29 @@ static OUString getFileNameFromDoc( const ScDocument* pDoc )
return sFileName;
}
-/** Tries to obtain a simple address without OUString/OString allocation
- *
- * @returns TRUE at success (it is enough to call OUString Format() at FALSE)
- *
- */
-bool ScAddress::TryFormat(OStringBuffer& s, sal_uInt16 nFlags, const ScDocument* pDoc,
- const Details& rDetails) const
+static inline void lcl_string_append(OUStringBuffer &rString, const OUString &sString)
{
- if( nFlags & SCA_VALID )
- nFlags |= ( SCA_VALID_ROW | SCA_VALID_COL | SCA_VALID_TAB );
- if(( pDoc && (nFlags & SCA_VALID_TAB ) && ( nTab >= pDoc->GetTableCount() || ( nFlags & SCA_TAB_3D ))) ||
- ! (nFlags & SCA_VALID_COL) || ! (nFlags & SCA_VALID_ROW) ||
- (nFlags & SCA_COL_ABSOLUTE) != 0 || (nFlags & SCA_ROW_ABSOLUTE) != 0 )
- {
- return false;
- }
+ rString.append(sString);
+}
- switch( rDetails.eConv )
- {
- default :
- case formula::FormulaGrammar::CONV_OOO:
- case formula::FormulaGrammar::CONV_XL_A1:
- case formula::FormulaGrammar::CONV_XL_OOX:
- ScColToAlpha( s, nCol );
- s.append( OString::number(nRow+1) );
- break;
- case formula::FormulaGrammar::CONV_XL_R1C1:
- // not used in XLSX export
- return false;
- }
- return true;
+static inline void lcl_string_append(OStringBuffer &rString, const OUString &sString)
+{
+ rString.append(OUStringToOString( sString, RTL_TEXTENCODING_UTF8 ));
}
-OUString ScAddress::Format(sal_uInt16 nFlags, const ScDocument* pDoc,
- const Details& rDetails) const
+template<typename T > inline void lcl_Format( T& r, SCTAB nTab, SCROW nRow, SCCOL nCol, sal_uInt16 nFlags,
+ const ScDocument* pDoc,
+ const ScAddress::Details& rDetails)
{
- OUStringBuffer r;
if( nFlags & SCA_VALID )
nFlags |= ( SCA_VALID_ROW | SCA_VALID_COL | SCA_VALID_TAB );
if( pDoc && (nFlags & SCA_VALID_TAB ) )
{
if ( nTab >= pDoc->GetTableCount() )
{
- return ScGlobal::GetRscString( STR_NOREF_STR );
+ lcl_string_append(r, ScGlobal::GetRscString( STR_NOREF_STR ));
+ return;
}
if( nFlags & SCA_TAB_3D )
{
@@ -1820,10 +1841,10 @@ OUString ScAddress::Format(sal_uInt16 nFlags, const ScDocument* pDoc,
{
default :
case formula::FormulaGrammar::CONV_OOO:
- r.append(aDocName);
+ lcl_string_append(r, aDocName);
if( nFlags & SCA_TAB_ABSOLUTE )
r.append("$");
- r.append(aTabName);
+ lcl_string_append(r, aTabName);
r.append(".");
break;
@@ -1832,9 +1853,10 @@ OUString ScAddress::Format(sal_uInt16 nFlags, const ScDocument* pDoc,
case formula::FormulaGrammar::CONV_XL_OOX:
if (!aDocName.isEmpty())
{
- r.append("[").append(aDocName).append("]");
+ lcl_string_append(r.append("["), aDocName);
+ r.append("]");
}
- r.append(aTabName);
+ lcl_string_append(r, aTabName);
r.append("!");
break;
}
@@ -1859,6 +1881,20 @@ OUString ScAddress::Format(sal_uInt16 nFlags, const ScDocument* pDoc,
lcl_r1c1_append_c ( r, nCol, (nFlags & SCA_COL_ABSOLUTE) != 0, rDetails );
break;
}
+}
+
+void ScAddress::Format( OStringBuffer& r, sal_uInt16 nFlags,
+ const ScDocument* pDoc,
+ const Details& rDetails) const
+{
+ lcl_Format(r, nTab, nRow, nCol, nFlags, pDoc, rDetails);
+}
+
+OUString ScAddress::Format(sal_uInt16 nFlags, const ScDocument* pDoc,
+ const Details& rDetails) const
+{
+ OUStringBuffer r;
+ lcl_Format(r, nTab, nRow, nCol, nFlags, pDoc, rDetails);
return r.makeStringAndClear();
}
@@ -2064,7 +2100,7 @@ OUString ScAddress::GetColRowString( bool bAbsolute,
if (bAbsolute)
aString.append("$");
- ScColToAlpha( aString, nCol);
+ lcl_ScColToAlpha( aString, nCol);
if ( bAbsolute )
aString.append("$");
@@ -2104,66 +2140,6 @@ OUString ScRefAddress::GetRefString( ScDocument* pDoc, SCTAB nActTab,
return aAdr.Format(nFlags, pDoc, rDetails);
}
-void ScColToAlpha( OUStringBuffer& rBuf, SCCOL nCol )
-{
- if (nCol < 26*26)
- {
- if (nCol < 26)
- rBuf.append( static_cast<sal_Unicode>( 'A' +
- static_cast<sal_uInt16>(nCol)));
- else
- {
- rBuf.append( static_cast<sal_Unicode>( 'A' +
- (static_cast<sal_uInt16>(nCol) / 26) - 1));
- rBuf.append( static_cast<sal_Unicode>( 'A' +
- (static_cast<sal_uInt16>(nCol) % 26)));
- }
- }
- else
- {
- OUString aStr;
- while (nCol >= 26)
- {
- SCCOL nC = nCol % 26;
- aStr += OUString( static_cast<sal_Unicode>( 'A' +
- static_cast<sal_uInt16>(nC)));
- nCol = sal::static_int_cast<SCCOL>( nCol - nC );
- nCol = nCol / 26 - 1;
- }
- aStr += OUString(static_cast<sal_Unicode>( 'A' +
- static_cast<sal_uInt16>(nCol)));
- rBuf.append(comphelper::string::reverseString(aStr));
- }
-}
-
-void ScColToAlpha( OStringBuffer& rBuf, SCCOL nCol )
-{
- if (nCol < 26*26)
- {
- if (nCol < 26)
- rBuf.append( static_cast<char>( 'A' + nCol ));
- else
- {
- rBuf.append( static_cast<char>( 'A' + nCol / 26 - 1 ));
- rBuf.append( static_cast<char>( 'A' + nCol % 26 ));
- }
- }
- else
- {
- OString aStr;
- while (nCol >= 26)
- {
- SCCOL nC = nCol % 26;
- aStr += OString( static_cast<char> ( 'A' + nC ));
- nCol = sal::static_int_cast<SCCOL>( nCol - nC );
- nCol = nCol / 26 - 1;
- }
- aStr += OString( static_cast<char> ( 'A' + nCol ));
- rBuf.append(comphelper::string::reverseString(aStr));
- }
-}
-
-
bool AlphaToCol( SCCOL& rCol, const OUString& rStr)
{
SCCOL nResult = 0;
diff --git a/sc/source/filter/excel/xeroot.cxx b/sc/source/filter/excel/xeroot.cxx
index 29f6551..96f5085 100644
--- a/sc/source/filter/excel/xeroot.cxx
+++ b/sc/source/filter/excel/xeroot.cxx
@@ -57,7 +57,7 @@ XclExpRootData::XclExpRootData( XclBiff eBiff, SfxMedium& rMedium,
{
SvtSaveOptions aSaveOpt;
mbRelUrl = mrMedium.IsRemote() ? aSaveOpt.IsSaveRelINet() : aSaveOpt.IsSaveRelFSys();
- maStringBuf = OStringBuffer(10); // for simple addresses, like ABC1000000
+ maStringBuf = OStringBuffer();
}
XclExpRootData::~XclExpRootData()
diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx
index 57792ea..48153eb 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -720,17 +720,10 @@ OString XclXmlUtils::ToOString( const OUString& s )
OStringBuffer& XclXmlUtils::ToOString( OStringBuffer& s, const ScAddress& rAddress )
{
- if (!rAddress.TryFormat(s, SCA_VALID, NULL, ScAddress::Details( FormulaGrammar::CONV_XL_A1)))
- s.append(ToOString(rAddress));
+ rAddress.Format(s, SCA_VALID, NULL, ScAddress::Details( FormulaGrammar::CONV_XL_A1));
return s;
}
-OString XclXmlUtils::ToOString( const ScAddress& rAddress )
-{
- OUString sAddress(rAddress.Format(SCA_VALID, NULL, ScAddress::Details( FormulaGrammar::CONV_XL_A1)));
- return ToOString( sAddress );
-}
-
OString XclXmlUtils::ToOString( const ScfUInt16Vec& rBuffer )
{
if(rBuffer.empty())
@@ -772,11 +765,6 @@ OStringBuffer& XclXmlUtils::ToOString( OStringBuffer& s, const XclAddress& rAddr
return ToOString( s, lcl_ToAddress( rAddress ));
}
-OString XclXmlUtils::ToOString( const XclAddress& rAddress )
-{
- return ToOString( lcl_ToAddress( rAddress ) );
-}
-
OString XclXmlUtils::ToOString( const XclExpString& s )
{
OSL_ENSURE( !s.IsRich(), "XclXmlUtils::ToOString(XclExpString): rich text string found!" );
diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx
index 6f01de7..25130af 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -663,7 +663,7 @@ void XclExpBooleanCell::SaveXml( XclExpXmlStream& rStrm )
{
sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
rWorksheet->startElement( XML_c,
- XML_r, XclXmlUtils::ToOString( GetXclPos() ).getStr(),
+ XML_r, XclXmlUtils::ToOString( rStrm.GetRoot().GetStringBuf(), GetXclPos() ).getStr(),
XML_s, lcl_GetStyleId( rStrm, *this ).getStr(),
XML_t, "b",
// OOXTODO: XML_cm, XML_vm, XML_ph
@@ -766,7 +766,7 @@ void XclExpLabelCell::SaveXml( XclExpXmlStream& rStrm )
{
sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
rWorksheet->startElement( XML_c,
- XML_r, XclXmlUtils::ToOString( GetXclPos() ).getStr(),
+ XML_r, XclXmlUtils::ToOString( rStrm.GetRoot().GetStringBuf(), GetXclPos() ).getStr(),
XML_s, lcl_GetStyleId( rStrm, *this ).getStr(),
XML_t, "s",
// OOXTODO: XML_cm, XML_vm, XML_ph
@@ -1276,7 +1276,7 @@ void XclExpBlankCell::WriteXmlContents( XclExpXmlStream& rStrm, const XclAddress
{
sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
rWorksheet->singleElement( XML_c,
- XML_r, XclXmlUtils::ToOString( rAddress ).getStr(),
+ XML_r, XclXmlUtils::ToOString( rStrm.GetRoot().GetStringBuf(), rAddress ).getStr(),
XML_s, lcl_GetStyleId( rStrm, nXFId ).getStr(),
FSEND );
}
diff --git a/sc/source/filter/excel/xeview.cxx b/sc/source/filter/excel/xeview.cxx
index faa3bb0..e3104ff 100644
--- a/sc/source/filter/excel/xeview.cxx
+++ b/sc/source/filter/excel/xeview.cxx
@@ -182,7 +182,7 @@ void XclExpPane::SaveXml( XclExpXmlStream& rStrm )
rStrm.GetCurrentStream()->singleElement( XML_pane,
XML_xSplit, OString::number( mnSplitX ).getStr(),
XML_ySplit, OString::number( mnSplitY ).getStr(),
- XML_topLeftCell, XclXmlUtils::ToOString( maSecondXclPos ).getStr(),
+ XML_topLeftCell, XclXmlUtils::ToOString( rStrm.GetRoot().GetStringBuf(), maSecondXclPos ).getStr(),
XML_activePane, lcl_GetActivePane( mnActivePane ),
XML_state, mbFrozenPanes ? "frozen" : "split",
FSEND );
@@ -225,7 +225,7 @@ void XclExpSelection::SaveXml( XclExpXmlStream& rStrm )
{
rStrm.GetCurrentStream()->singleElement( XML_selection,
XML_pane, lcl_GetActivePane( mnPane ),
- XML_activeCell, XclXmlUtils::ToOString( maSelData.maXclCursor ).getStr(),
+ XML_activeCell, XclXmlUtils::ToOString( rStrm.GetRoot().GetStringBuf(), maSelData.maXclCursor ).getStr(),
XML_activeCellId, OString::number( maSelData.mnCursorIdx ).getStr(),
XML_sqref, XclXmlUtils::ToOString( maSelData.maXclSelection ).getStr(),
FSEND );
@@ -426,7 +426,7 @@ void XclExpTabViewSettings::SaveXml( XclExpXmlStream& rStrm )
XML_defaultGridColor, mnGridColorId == XclExpPalette::GetColorIdFromIndex( EXC_COLOR_WINDOWTEXT ) ? "true" : "false",
// OOXTODO: XML_showWhiteSpace,
XML_view, maData.mbPageMode ? "pageBreakPreview" : "normal", // OOXTODO: pageLayout
- XML_topLeftCell, XclXmlUtils::ToOString( maData.maFirstXclPos ).getStr(),
+ XML_topLeftCell, XclXmlUtils::ToOString( rStrm.GetRoot().GetStringBuf(), maData.maFirstXclPos ).getStr(),
XML_colorId, OString::number( rStrm.GetRoot().GetPalette().GetColorIndex( mnGridColorId ) ).getStr(),
XML_zoomScale, lcl_GetZoom( maData.mnCurrentZoom ).getStr(),
XML_zoomScaleNormal, lcl_GetZoom( maData.mnNormalZoom ).getStr(),
diff --git a/sc/source/filter/inc/xestream.hxx b/sc/source/filter/inc/xestream.hxx
index 71aea1d..5bb2b20 100644
--- a/sc/source/filter/inc/xestream.hxx
+++ b/sc/source/filter/inc/xestream.hxx
@@ -268,11 +268,9 @@ public:
static OString ToOString( const OUString& s );
static OString ToOString( const ScfUInt16Vec& rBuffer );
static OStringBuffer& ToOString( OStringBuffer& s, const ScAddress& rRange );
- static OString ToOString( const ScAddress& rRange );
static OString ToOString( const ScRange& rRange );
static OString ToOString( const ScRangeList& rRangeList );
static OStringBuffer& ToOString( OStringBuffer& s, const XclAddress& rAddress );
- static OString ToOString( const XclAddress& rAddress );
static OString ToOString( const XclExpString& s );
static OString ToOString( const XclRange& rRange );
static OString ToOString( const XclRangeList& rRangeList );
More information about the Libreoffice-commits
mailing list