[Libreoffice-commits] .: 3 commits - comphelper/inc comphelper/source sc/inc sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Mon Nov 14 23:02:54 PST 2011


 comphelper/inc/comphelper/string.hxx |    3 ++
 comphelper/source/misc/string.cxx    |   12 ++++++++++
 sc/inc/dptabres.hxx                  |   36 +++++++++++++++---------------
 sc/source/core/data/dptabres.cxx     |   42 ++++++++++++++++-------------------
 sc/source/core/data/dptabsrc.cxx     |   12 +++++-----
 5 files changed, 59 insertions(+), 46 deletions(-)

New commits:
commit e786e2d25ab0105e88d7ca260c7ef4a88c9b821c
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Tue Nov 15 02:02:14 2011 -0500

    String to rtl::OUString.

diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx
index 4545302..620db1b 100644
--- a/comphelper/inc/comphelper/string.hxx
+++ b/comphelper/inc/comphelper/string.hxx
@@ -352,6 +352,9 @@ COMPHELPER_DLLPUBLIC inline rtl::OUStringBuffer& padToLength(
     return detail::padToLength(rBuffer, nLength, cFill);
 }
 
+COMPHELPER_DLLPUBLIC rtl::OUString removeTrailingChars(
+    const rtl::OUString& rStr, sal_Unicode cChar);
+
 /** Convert a sequence of strings to a single comma separated string.
 
     Note that no escaping of commas or anything fancy is done.
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx
index 873a1ff..6f59564 100644
--- a/comphelper/source/misc/string.cxx
+++ b/comphelper/source/misc/string.cxx
@@ -235,6 +235,18 @@ sal_uInt32 decimalStringToNumber(
     return result;
 }
 
+rtl::OUString removeTrailingChars(const rtl::OUString& rStr, sal_Unicode cChar)
+{
+    sal_Int32 n = rStr.getLength();
+    const sal_Unicode* p = &rStr.getStr()[n-1]; // last char
+    while (n > 0 && *p == cChar)
+    {
+        --p;
+        --n;
+    }
+    return rStr.copy(0, n);
+}
+
 using namespace ::com::sun::star;
 
 // convert between sequence of string and comma separated string
diff --git a/sc/inc/dptabres.hxx b/sc/inc/dptabres.hxx
index b8a2414..2c92f22 100644
--- a/sc/inc/dptabres.hxx
+++ b/sc/inc/dptabres.hxx
@@ -299,7 +299,7 @@ private:
     ScSubTotalFunc*         pMeasFuncs;
     ::com::sun::star::sheet::DataPilotFieldReference* pMeasRefs;
     sal_uInt16*                 pMeasRefOrient;
-    std::vector<String>     maMeasureNames;
+    std::vector<rtl::OUString> maMeasureNames;
     bool                    bLateInit:1;
     bool                    bDataAtCol:1;
     bool                    bDataAtRow:1;
@@ -312,7 +312,7 @@ public:
 
     void                SetMeasureData( long nCount, const ScSubTotalFunc* pFunctions,
                                         const ::com::sun::star::sheet::DataPilotFieldReference* pRefs,
-                                        const sal_uInt16* pRefOrient, std::vector<String>& rNames );
+                                        const sal_uInt16* pRefOrient, std::vector<rtl::OUString>& rNames );
     void                SetDataLayoutOrientation( sal_uInt16 nOrient );
     void                SetLateInit( bool bSet );
 
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx
index b7c5e0a..62feb0b 100644
--- a/sc/source/core/data/dptabres.cxx
+++ b/sc/source/core/data/dptabres.cxx
@@ -786,7 +786,7 @@ ScDPResultData::~ScDPResultData()
 
 void ScDPResultData::SetMeasureData( long nCount, const ScSubTotalFunc* pFunctions,
                                     const sheet::DataPilotFieldReference* pRefs, const sal_uInt16* pRefOrient,
-                                    std::vector<String>& rNames )
+                                    std::vector<rtl::OUString>& rNames )
 {
     delete[] pMeasFuncs;
     delete[] pMeasRefs;
@@ -815,7 +815,7 @@ void ScDPResultData::SetMeasureData( long nCount, const ScSubTotalFunc* pFunctio
         pMeasRefs  = new sheet::DataPilotFieldReference[1]; // default ctor is ok
         pMeasRefOrient = new sal_uInt16[1];
         pMeasRefOrient[0] = sheet::DataPilotFieldOrientation_HIDDEN;
-        std::vector<String> aMeasureName;
+        std::vector<rtl::OUString> aMeasureName;
         aMeasureName.push_back(ScGlobal::GetRscString(STR_EMPTYDATA));
         maMeasureNames.swap(aMeasureName);
     }
@@ -887,18 +887,18 @@ String ScDPResultData::GetMeasureString(long nMeasure, bool bForce, ScSubTotalFu
             if (pLayoutName)
                 return *pLayoutName;
         }
-        String aRet;
+        rtl::OUStringBuffer aRet;
         ScSubTotalFunc eFunc = ( eForceFunc == SUBTOTAL_FUNC_NONE ) ?
                                     GetMeasureFunction(nMeasure) : eForceFunc;
         sal_uInt16 nId = nFuncStrIds[eFunc];
         if (nId)
         {
-            aRet += ScGlobal::GetRscString(nId);        // function name
-            aRet.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " - " ));
+            aRet.append(ScGlobal::GetRscString(nId));        // function name
+            aRet.appendAscii(RTL_CONSTASCII_STRINGPARAM(" - "));
         }
-        aRet += maMeasureNames[nMeasure];                   // field name
+        aRet.append(maMeasureNames[nMeasure]);                   // field name
 
-        return aRet;
+        return aRet.makeStringAndClear();
     }
 }
 
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index 008ea39..b0ac477 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -69,6 +69,7 @@
 #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
 #include <com/sun/star/table/CellAddress.hpp>
 
+#include "comphelper/string.hxx"
 #include <unotools/collatorwrapper.hxx>
 #include <unotools/calendarwrapper.hxx>
 #include <com/sun/star/i18n/CalendarDisplayIndex.hpp>
@@ -792,7 +793,7 @@ void ScDPSource::CreateRes_Impl()
         // TODO: Aggreate pDataNames, pDataRefValues, nDataRefOrient, and
         // eDataFunctions into a structure and use vector instead of static
         // or pointer arrays.
-        vector<String> aDataNames;
+        vector<rtl::OUString> aDataNames;
         sheet::DataPilotFieldReference* pDataRefValues = NULL;
         ScSubTotalFunc eDataFunctions[SC_DAPI_MAXFIELDS];
         sal_uInt16 nDataRefOrient[SC_DAPI_MAXFIELDS];
@@ -854,7 +855,7 @@ void ScDPSource::CreateRes_Impl()
             //  asterisk is added to duplicated dimension names by ScDPSaveData::WriteToSource
             //! modify user visible strings as in ScDPResultData::GetMeasureString instead!
 
-            aDataNames[i].EraseTrailingChars('*');
+            aDataNames[i] = comphelper::string::removeTrailingChars(aDataNames[i], '*');
 
             //! if the name is overridden by user, a flag must be set
             //! so the user defined name replaces the function string and field name.
commit 35054d3f6213c11546200820c706c8a1527ec605
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Tue Nov 15 01:31:34 2011 -0500

    Replaced heap array with std::vector.

diff --git a/sc/inc/dptabres.hxx b/sc/inc/dptabres.hxx
index aedb6f7..b8a2414 100644
--- a/sc/inc/dptabres.hxx
+++ b/sc/inc/dptabres.hxx
@@ -299,7 +299,7 @@ private:
     ScSubTotalFunc*         pMeasFuncs;
     ::com::sun::star::sheet::DataPilotFieldReference* pMeasRefs;
     sal_uInt16*                 pMeasRefOrient;
-    String*                 pMeasNames;
+    std::vector<String>     maMeasureNames;
     bool                    bLateInit:1;
     bool                    bDataAtCol:1;
     bool                    bDataAtRow:1;
@@ -312,7 +312,7 @@ public:
 
     void                SetMeasureData( long nCount, const ScSubTotalFunc* pFunctions,
                                         const ::com::sun::star::sheet::DataPilotFieldReference* pRefs,
-                                        const sal_uInt16* pRefOrient, const String* pNames );
+                                        const sal_uInt16* pRefOrient, std::vector<String>& rNames );
     void                SetDataLayoutOrientation( sal_uInt16 nOrient );
     void                SetLateInit( bool bSet );
 
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx
index 3f18da1..b7c5e0a 100644
--- a/sc/source/core/data/dptabres.cxx
+++ b/sc/source/core/data/dptabres.cxx
@@ -767,7 +767,6 @@ ScDPResultData::ScDPResultData( ScDPSource* pSrc ) :        //! Ref
     pMeasFuncs( NULL ),
     pMeasRefs( NULL ),
     pMeasRefOrient( NULL ),
-    pMeasNames( NULL ),
     bLateInit( false ),
     bDataAtCol( false ),
     bDataAtRow( false )
@@ -781,32 +780,30 @@ ScDPResultData::~ScDPResultData()
     delete[] pMeasFuncs;
     delete[] pMeasRefs;
     delete[] pMeasRefOrient;
-    delete[] pMeasNames;
 
       lcl_ResizePointVector( mpDimMembers , 0 );
 }
 
 void ScDPResultData::SetMeasureData( long nCount, const ScSubTotalFunc* pFunctions,
                                     const sheet::DataPilotFieldReference* pRefs, const sal_uInt16* pRefOrient,
-                                    const String* pNames )
+                                    std::vector<String>& rNames )
 {
     delete[] pMeasFuncs;
     delete[] pMeasRefs;
     delete[] pMeasRefOrient;
-    delete[] pMeasNames;
     if ( nCount )
     {
+        OSL_ASSERT(nCount == static_cast<long>(rNames.size()));
         nMeasCount = nCount;
         pMeasFuncs = new ScSubTotalFunc[nCount];
         pMeasRefs  = new sheet::DataPilotFieldReference[nCount];
         pMeasRefOrient = new sal_uInt16[nCount];
-        pMeasNames = new String[nCount];
+        maMeasureNames.swap(rNames);
         for (long i=0; i<nCount; i++)
         {
             pMeasFuncs[i] = pFunctions[i];
             pMeasRefs[i]  = pRefs[i];
             pMeasRefOrient[i] = pRefOrient[i];
-            pMeasNames[i] = pNames[i];
         }
     }
     else
@@ -818,8 +815,9 @@ void ScDPResultData::SetMeasureData( long nCount, const ScSubTotalFunc* pFunctio
         pMeasRefs  = new sheet::DataPilotFieldReference[1]; // default ctor is ok
         pMeasRefOrient = new sal_uInt16[1];
         pMeasRefOrient[0] = sheet::DataPilotFieldOrientation_HIDDEN;
-        pMeasNames = new String[1];
-        pMeasNames[0] = ScGlobal::GetRscString( STR_EMPTYDATA );
+        std::vector<String> aMeasureName;
+        aMeasureName.push_back(ScGlobal::GetRscString(STR_EMPTYDATA));
+        maMeasureNames.swap(aMeasureName);
     }
 }
 
@@ -881,7 +879,7 @@ String ScDPResultData::GetMeasureString(long nMeasure, bool bForce, ScSubTotalFu
     }
     else
     {
-        OSL_ENSURE( pMeasNames && nMeasure < nMeasCount, "bumm" );
+        OSL_ENSURE( nMeasure < nMeasCount, "bumm" );
         ScDPDimension* pDataDim = pSource->GetDataDimension(nMeasure);
         if (pDataDim)
         {
@@ -898,7 +896,7 @@ String ScDPResultData::GetMeasureString(long nMeasure, bool bForce, ScSubTotalFu
             aRet += ScGlobal::GetRscString(nId);        // function name
             aRet.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " - " ));
         }
-        aRet += pMeasNames[nMeasure];                   // field name
+        aRet += maMeasureNames[nMeasure];                   // field name
 
         return aRet;
     }
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index 545109a..008ea39 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -792,13 +792,13 @@ void ScDPSource::CreateRes_Impl()
         // TODO: Aggreate pDataNames, pDataRefValues, nDataRefOrient, and
         // eDataFunctions into a structure and use vector instead of static
         // or pointer arrays.
-        String* pDataNames = NULL;
+        vector<String> aDataNames;
         sheet::DataPilotFieldReference* pDataRefValues = NULL;
         ScSubTotalFunc eDataFunctions[SC_DAPI_MAXFIELDS];
         sal_uInt16 nDataRefOrient[SC_DAPI_MAXFIELDS];
         if (nDataDimCount)
         {
-            pDataNames = new String[nDataDimCount];
+            aDataNames.resize(nDataDimCount);
             pDataRefValues = new sheet::DataPilotFieldReference[nDataDimCount];
         }
 
@@ -849,12 +849,12 @@ void ScDPSource::CreateRes_Impl()
                 }
             }
 
-            pDataNames[i] = String( pDim->getName() );  //! label?
+            aDataNames[i] = pDim->getName();
 
             //  asterisk is added to duplicated dimension names by ScDPSaveData::WriteToSource
             //! modify user visible strings as in ScDPResultData::GetMeasureString instead!
 
-            pDataNames[i].EraseTrailingChars('*');
+            aDataNames[i].EraseTrailingChars('*');
 
             //! if the name is overridden by user, a flag must be set
             //! so the user defined name replaces the function string and field name.
@@ -869,11 +869,10 @@ void ScDPSource::CreateRes_Impl()
         }
 
         pResData = new ScDPResultData( this );
-        pResData->SetMeasureData( nDataDimCount, eDataFunctions, pDataRefValues, nDataRefOrient, pDataNames );
+        pResData->SetMeasureData( nDataDimCount, eDataFunctions, pDataRefValues, nDataRefOrient, aDataNames );
         pResData->SetDataLayoutOrientation(nDataOrient);
         pResData->SetLateInit( bLateInit );
 
-        delete[] pDataNames;
         delete[] pDataRefValues;
 
         bool bHasAutoShow = false;
commit 13e09805f5058b6fcf700f566ea7935474dd9310
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Tue Nov 15 01:14:11 2011 -0500

    sal_Bool to bool.

diff --git a/sc/inc/dptabres.hxx b/sc/inc/dptabres.hxx
index 4e6c6ed..aedb6f7 100644
--- a/sc/inc/dptabres.hxx
+++ b/sc/inc/dptabres.hxx
@@ -300,12 +300,12 @@ private:
     ::com::sun::star::sheet::DataPilotFieldReference* pMeasRefs;
     sal_uInt16*                 pMeasRefOrient;
     String*                 pMeasNames;
-    sal_Bool                    bLateInit;
-    sal_Bool                    bDataAtCol;
-    sal_Bool                    bDataAtRow;
+    bool                    bLateInit:1;
+    bool                    bDataAtCol:1;
+    bool                    bDataAtRow:1;
 
     //! add "displayed values" settings
-        mutable std::vector< ResultMembers* > mpDimMembers;
+    mutable std::vector< ResultMembers* > mpDimMembers;
 public:
                         ScDPResultData( ScDPSource* pSrc );     //! Ref
                         ~ScDPResultData();
@@ -314,18 +314,18 @@ public:
                                         const ::com::sun::star::sheet::DataPilotFieldReference* pRefs,
                                         const sal_uInt16* pRefOrient, const String* pNames );
     void                SetDataLayoutOrientation( sal_uInt16 nOrient );
-    void                SetLateInit( sal_Bool bSet );
+    void                SetLateInit( bool bSet );
 
     long                GetMeasureCount() const     { return nMeasCount; }
     ScSubTotalFunc      GetMeasureFunction(long nMeasure) const;
-    String              GetMeasureString(long nMeasure, sal_Bool bForce, ScSubTotalFunc eForceFunc, bool& rbTotalResult) const;
+    String              GetMeasureString(long nMeasure, bool bForce, ScSubTotalFunc eForceFunc, bool& rbTotalResult) const;
     String              GetMeasureDimensionName(long nMeasure) const;
     const ::com::sun::star::sheet::DataPilotFieldReference& GetMeasureRefVal(long nMeasure) const;
     sal_uInt16              GetMeasureRefOrient(long nMeasure) const;
 
-    sal_Bool                IsDataAtCol() const             { return bDataAtCol; }
-    sal_Bool                IsDataAtRow() const             { return bDataAtRow; }
-    sal_Bool                IsLateInit() const              { return bLateInit; }
+    bool                IsDataAtCol() const             { return bDataAtCol; }
+    bool                IsDataAtRow() const             { return bDataAtRow; }
+    bool                IsLateInit() const              { return bLateInit; }
 
     long                GetColStartMeasure() const;
     long                GetRowStartMeasure() const;
@@ -333,14 +333,14 @@ public:
     long                GetCountForMeasure( long nMeas ) const
                                 { return ( nMeas == SC_DPMEASURE_ALL ) ? nMeasCount : 1; }
 
-    sal_Bool                IsBaseForGroup( long nDim ) const;              // any group
+    bool                IsBaseForGroup( long nDim ) const;              // any group
     long                GetGroupBase( long nGroupDim ) const;
-    sal_Bool                IsNumOrDateGroup( long nDim ) const;
-    sal_Bool                IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
-                                               long nBaseDataId, long nBaseIndex ) const;
-    sal_Bool                IsInGroup( SCROW nGroupDataId, long nGroupIndex,
-                                              const ScDPItemData& rBaseData, long nBaseIndex ) const;
-    sal_Bool                HasCommonElement( SCROW nFirstDataId, long nFirstIndex,
+    bool                IsNumOrDateGroup( long nDim ) const;
+    bool                IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
+                                   long nBaseDataId, long nBaseIndex ) const;
+    bool                IsInGroup( SCROW nGroupDataId, long nGroupIndex,
+                                   const ScDPItemData& rBaseData, long nBaseIndex ) const;
+    bool                HasCommonElement( SCROW nFirstDataId, long nFirstIndex,
                                           const ScDPItemData& rSecondData, long nSecondIndex ) const;
 
     ResultMembers* GetDimResultMembers( long nDim , ScDPDimension* pDim , ScDPLevel*   pLevel) const ;
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx
index c1a1824..3f18da1 100644
--- a/sc/source/core/data/dptabres.cxx
+++ b/sc/source/core/data/dptabres.cxx
@@ -829,7 +829,7 @@ void ScDPResultData::SetDataLayoutOrientation( sal_uInt16 nOrient )
     bDataAtRow = ( nOrient == sheet::DataPilotFieldOrientation_ROW );
 }
 
-void ScDPResultData::SetLateInit( sal_Bool bSet )
+void ScDPResultData::SetLateInit( bool bSet )
 {
     bLateInit = bSet;
 }
@@ -864,7 +864,7 @@ sal_uInt16 ScDPResultData::GetMeasureRefOrient(long nMeasure) const
     return pMeasRefOrient[nMeasure];
 }
 
-String ScDPResultData::GetMeasureString(long nMeasure, sal_Bool bForce, ScSubTotalFunc eForceFunc, bool& rbTotalResult) const
+String ScDPResultData::GetMeasureString(long nMeasure, bool bForce, ScSubTotalFunc eForceFunc, bool& rbTotalResult) const
 {
     //  with bForce==sal_True, return function instead of "result" for single measure
     //  with eForceFunc != SUBTOTAL_FUNC_NONE, always use eForceFunc
@@ -915,7 +915,7 @@ String ScDPResultData::GetMeasureDimensionName(long nMeasure) const
     return pSource->GetDataDimName( nMeasure );
 }
 
-sal_Bool ScDPResultData::IsBaseForGroup( long nDim ) const
+bool ScDPResultData::IsBaseForGroup( long nDim ) const
 {
     return pSource->GetData()->IsBaseForGroup( nDim );
 }
@@ -925,12 +925,12 @@ long ScDPResultData::GetGroupBase( long nGroupDim ) const
     return pSource->GetData()->GetGroupBase( nGroupDim );
 }
 
-sal_Bool ScDPResultData::IsNumOrDateGroup( long nDim ) const
+bool ScDPResultData::IsNumOrDateGroup( long nDim ) const
 {
     return pSource->GetData()->IsNumOrDateGroup( nDim );
 }
 
-sal_Bool ScDPResultData::IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
+bool ScDPResultData::IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
                                 long nBaseDataId, long nBaseIndex ) const
 {
     const ScDPItemData* pData = pSource->GetItemDataById( nGroupIndex , nBaseDataId);
@@ -939,8 +939,8 @@ sal_Bool ScDPResultData::IsInGroup( const ScDPItemData& rGroupData, long nGroupI
     else
         return false;
 }
-sal_Bool ScDPResultData::IsInGroup( SCROW nGroupDataId, long nGroupIndex,
-                                                               const ScDPItemData& rBaseData, long nBaseIndex ) const
+bool ScDPResultData::IsInGroup( SCROW nGroupDataId, long nGroupIndex,
+                                const ScDPItemData& rBaseData, long nBaseIndex ) const
 {
     const ScDPItemData* pGroupData = pSource->GetItemDataById( nGroupIndex , nGroupDataId);
     if ( pGroupData )
@@ -949,7 +949,7 @@ sal_Bool ScDPResultData::IsInGroup( SCROW nGroupDataId, long nGroupIndex,
         return false;
 }
 
-sal_Bool ScDPResultData::HasCommonElement(/* const ScDPItemData& rFirstData*/SCROW nFirstDataId, long nFirstIndex,
+bool ScDPResultData::HasCommonElement( SCROW nFirstDataId, long nFirstIndex,
                                        const ScDPItemData& rSecondData, long nSecondIndex ) const
 {
     const ScDPItemData* pFirstData = pSource->GetItemDataById( nFirstIndex , nFirstDataId);


More information about the Libreoffice-commits mailing list