[Libreoffice-commits] core.git: include/svl svl/source

Eike Rathke erack at redhat.com
Fri Jul 10 06:12:20 PDT 2015


 include/svl/zformat.hxx         |    6 ++++++
 svl/source/numbers/zforfind.cxx |   21 +++++++++++++++++++--
 svl/source/numbers/zforlist.cxx |    6 +++++-
 svl/source/numbers/zformat.cxx  |   16 ++++++++++++++++
 svl/source/numbers/zforscan.hxx |    3 +++
 5 files changed, 49 insertions(+), 3 deletions(-)

New commits:
commit f7f4d985ad44ba0c644b2be02d09002b13d749f7
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jul 10 15:07:59 2015 +0200

    Resolves: tdf#92457 handle trailing text subformat if others omitted
    
    Change-Id: I597a5019540cef4700355df4d170c103e973797e

diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx
index 21c106c..2858563 100644
--- a/include/svl/zformat.hxx
+++ b/include/svl/zformat.hxx
@@ -277,6 +277,12 @@ public:
             return false;
         }
 
+    /** Get the scanned type of the specified subformat. */
+    short GetNumForInfoScannedType( sal_uInt16 nNumFor ) const
+    {
+        return (nNumFor < 4) ? NumFor[nNumFor].Info().eScannedType : css::util::NumberFormat::UNDEFINED;
+    }
+
     // Whether the second subformat code is really for negative numbers
     // or another limit set.
     bool IsSecondSubformatRealNegative() const
diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index f0b08b5..77832ea 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -3222,7 +3222,16 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const OUString& rString,        /
         }
         if ( nMatchedAllStrings )
         {
-            eScannedType = eSetType;
+            // A type DEFINED means that no category could be assigned to the
+            // overall format because of mixed type subformats. Use the scan
+            // matched subformat's type if any.
+            short eForType = eSetType;
+            if ((eForType == css::util::NumberFormat::UNDEFINED || eForType == css::util::NumberFormat::DEFINED) && pFormat)
+                eForType = pFormat->GetNumForInfoScannedType( nStringScanNumFor);
+            if (eForType != css::util::NumberFormat::UNDEFINED && eForType != css::util::NumberFormat::DEFINED)
+                eScannedType = eForType;
+            else
+                eScannedType = css::util::NumberFormat::NUMBER;
         }
         else if ( bDidMatch )
         {
@@ -3250,7 +3259,15 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const OUString& rString,        /
         }
         if ( nMatchedAllStrings )
         {
-            eScannedType = eSetType;
+            // A type DEFINED means that no category could be assigned to the
+            // overall format because of mixed type subformats. Do not override
+            // the scanned type in this case. Otherwise in IsNumberFormat() the
+            // first numeric particle would be accepted as number.
+            short eForType = eSetType;
+            if ((eForType == css::util::NumberFormat::UNDEFINED || eForType == css::util::NumberFormat::DEFINED) && pFormat)
+                eForType = pFormat->GetNumForInfoScannedType( nStringScanNumFor);
+            if (eForType != css::util::NumberFormat::UNDEFINED && eForType != css::util::NumberFormat::DEFINED)
+                eScannedType = eForType;
         }
         else if ( bWasReturn )
         {
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index 19c5d95..afca600 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -1322,7 +1322,11 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber,
     short eType = pFormat->GetType() & ~css::util::NumberFormat::DEFINED;
     if (eType == 0)
     {
-        eType = css::util::NumberFormat::DEFINED;
+        // Mixed types in subformats, use first.
+        /* XXX we could choose a subformat according to fOutNumber and
+         * subformat conditions, but they may exist to suppress 0 or negative
+         * numbers so wouldn't be a safe bet. */
+        eType = pFormat->GetNumForInfoScannedType(0);
     }
 
     sal_uInt16 nOldPrec = pFormatScanner->GetStandardPrec();
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index ec65c7c..e7501ff 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -943,6 +943,22 @@ SvNumberformat::SvNumberformat(OUString& rString,
                             sBuff.insert(nPos, ";");
                             nPos++;
                         }
+                        else
+                        {
+                            // The last subformat. If it is a trailing text
+                            // format the omitted subformats act like they were
+                            // not specified and "inherited" the first format,
+                            // e.g.  0;@  behaves like  0;-0;0;@
+                            if (pSc->GetScannedType() == css::util::NumberFormat::TEXT)
+                            {
+                                // Reset conditions, reverting any set above.
+                                if (nIndex == 1)
+                                    eOp1 = NUMBERFORMAT_OP_NO;
+                                else if (nIndex == 2)
+                                    eOp2 = NUMBERFORMAT_OP_NO;
+                                nIndex = 3;
+                            }
+                        }
                         NumFor[nIndex].Enlarge(nAnz);
                         pSc->CopyInfo(&(NumFor[nIndex].Info()), nAnz);
                         // type check
diff --git a/svl/source/numbers/zforscan.hxx b/svl/source/numbers/zforscan.hxx
index c593320..54eec03 100644
--- a/svl/source/numbers/zforscan.hxx
+++ b/svl/source/numbers/zforscan.hxx
@@ -144,6 +144,9 @@ public:
 
     SvNumberFormatter* GetNumberformatter() { return pFormatter; } // Access to formatter (for zformat.cxx)
 
+    /// Get type scanned (so far).
+    short GetScannedType() const { return eScannedType; }
+
 private: // Private section
     NfKeywordTable sKeyword;                    // Syntax keywords
     Color StandardColor[NF_MAX_DEFAULT_COLORS]; // Standard color array


More information about the Libreoffice-commits mailing list