Blob Blame History Raw
From 7c4a58833df3931c168c57be3239e904e3a3baba Mon Sep 17 00:00:00 2001
From: Kohei Yoshida <kohei.yoshida@collabora.com>
Date: Tue, 7 Jan 2014 00:48:10 -0500
Subject: [PATCH 3/9] fdo#72645: Case-insensitive string comparison in
 GETPIVOTDATA.

Change-Id: Ibdb2b7ab2bae03875a3462816e860f58d9076457
Reviewed-on: https://gerrit.libreoffice.org/7285
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
---
 sc/source/core/data/dpobject.cxx    | 12 +++++++-----
 sc/source/core/data/dpresfilter.cxx | 29 +++++++++++++++++++++--------
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 3d9f5af..f9344aa 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -1321,24 +1321,24 @@ namespace {
 
 class FindByName : std::unary_function<const ScDPSaveDimension*, bool>
 {
-    OUString maName;
+    OUString maName; // must be all uppercase.
 public:
     FindByName(const OUString& rName) : maName(rName) {}
     bool operator() (const ScDPSaveDimension* pDim) const
     {
         // Layout name takes precedence.
         const OUString* pLayoutName = pDim->GetLayoutName();
-        if (pLayoutName && *pLayoutName == maName)
+        if (pLayoutName && ScGlobal::pCharClass->uppercase(*pLayoutName) == maName)
             return true;
 
         sheet::GeneralFunction eGenFunc = static_cast<sheet::GeneralFunction>(pDim->GetFunction());
         ScSubTotalFunc eFunc = ScDPUtil::toSubTotalFunc(eGenFunc);
         OUString aSrcName = ScDPUtil::getSourceDimensionName(pDim->GetName());
         OUString aFuncName = ScDPUtil::getDisplayedMeasureName(aSrcName, eFunc);
-        if (maName == aFuncName)
+        if (maName == ScGlobal::pCharClass->uppercase(aFuncName))
             return true;
 
-        return maName == aSrcName;
+        return maName == ScGlobal::pCharClass->uppercase(aSrcName);
     }
 };
 
@@ -1382,7 +1382,9 @@ double ScDPObject::GetPivotData(const OUString& rDataFieldName, std::vector<shee
         return fRet;
 
     std::vector<const ScDPSaveDimension*>::iterator it = std::find_if(
-        aDataDims.begin(), aDataDims.end(), FindByName(rDataFieldName));
+        aDataDims.begin(), aDataDims.end(),
+        FindByName(ScGlobal::pCharClass->uppercase(rDataFieldName)));
+
     if (it == aDataDims.end())
         return fRet;
 
diff --git a/sc/source/core/data/dpresfilter.cxx b/sc/source/core/data/dpresfilter.cxx
index 41b2d7e..d4895b8 100644
--- a/sc/source/core/data/dpresfilter.cxx
+++ b/sc/source/core/data/dpresfilter.cxx
@@ -10,6 +10,7 @@
 #include "dpresfilter.hxx"
 #include "global.hxx"
 
+#include <unotools/charclass.hxx>
 #include <rtl/math.hxx>
 
 #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
@@ -113,12 +114,13 @@ void ScDPResultTree::add(
 
         // See if this dimension exists.
         DimensionsType& rDims = pMemNode->maChildDimensions;
-        DimensionsType::iterator itDim = rDims.find(filter.maDimName);
+        OUString aUpperName = ScGlobal::pCharClass->uppercase(filter.maDimName);
+        DimensionsType::iterator itDim = rDims.find(aUpperName);
         if (itDim == rDims.end())
         {
             // New dimenison.  Insert it.
             std::pair<DimensionsType::iterator, bool> r =
-                rDims.insert(DimensionsType::value_type(filter.maDimName, new DimensionNode(pMemNode)));
+                rDims.insert(DimensionsType::value_type(aUpperName, new DimensionNode(pMemNode)));
 
             if (!r.second)
                 // Insertion failed!
@@ -132,13 +134,14 @@ void ScDPResultTree::add(
         // Now, see if this dimension member exists.
         DimensionNode* pDim = itDim->second;
         MembersType& rMembers = pDim->maChildMembers;
-        MembersType::iterator itMem = rMembers.find(filter.maValue);
+        aUpperName = ScGlobal::pCharClass->uppercase(filter.maValue);
+        MembersType::iterator itMem = rMembers.find(aUpperName);
         if (itMem == rMembers.end())
         {
             // New member.  Insert it.
             std::pair<MembersType::iterator, bool> r =
                 rMembers.insert(
-                    MembersType::value_type(filter.maValue, new MemberNode(pDim)));
+                    MembersType::value_type(aUpperName, new MemberNode(pDim)));
 
             if (!r.second)
                 // Insertion failed!
@@ -153,7 +156,10 @@ void ScDPResultTree::add(
 
     if (pDimName && pMemName)
     {
-        NamePairType aNames(*pDimName, *pMemName);
+        NamePairType aNames(
+            ScGlobal::pCharClass->uppercase(*pDimName),
+            ScGlobal::pCharClass->uppercase(*pMemName));
+
         LeafValuesType::iterator it = maLeafValues.find(aNames);
         if (it == maLeafValues.end())
         {
@@ -197,13 +203,17 @@ const ScDPResultTree::ValuesType* ScDPResultTree::getResults(
     const MemberNode* pMember = mpRoot;
     for (; p != pEnd; ++p)
     {
-        DimensionsType::const_iterator itDim = pMember->maChildDimensions.find(p->FieldName);
+        DimensionsType::const_iterator itDim = pMember->maChildDimensions.find(
+            ScGlobal::pCharClass->uppercase(p->FieldName));
+
         if (itDim == pMember->maChildDimensions.end())
             // Specified dimension not found.
             return NULL;
 
         const DimensionNode* pDim = itDim->second;
-        MembersType::const_iterator itMem = pDim->maChildMembers.find(p->MatchValue);
+        MembersType::const_iterator itMem = pDim->maChildMembers.find(
+            ScGlobal::pCharClass->uppercase(p->MatchValue));
+
         if (itMem == pDim->maChildMembers.end())
             // Specified member not found.
             return NULL;
@@ -216,7 +226,10 @@ const ScDPResultTree::ValuesType* ScDPResultTree::getResults(
 
 double ScDPResultTree::getLeafResult(const com::sun::star::sheet::DataPilotFieldFilter& rFilter) const
 {
-    NamePairType aPair(rFilter.FieldName, rFilter.MatchValue);
+    NamePairType aPair(
+        ScGlobal::pCharClass->uppercase(rFilter.FieldName),
+        ScGlobal::pCharClass->uppercase(rFilter.MatchValue));
+
     LeafValuesType::const_iterator it = maLeafValues.find(aPair);
     if (it != maLeafValues.end())
         // Found!
-- 
1.8.4.2