[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - svl/source

Eike Rathke erack at redhat.com
Mon Sep 11 15:54:13 UTC 2017


 svl/source/numbers/zforfind.cxx |   63 ++++++++++++++++++++++++++--------------
 svl/source/numbers/zforfind.hxx |   21 +++----------
 svl/source/numbers/zforlist.cxx |    2 -
 3 files changed, 48 insertions(+), 38 deletions(-)

New commits:
commit 54bb595027197b6ffba9b95b2eafedefa03f3996
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Aug 29 18:24:05 2017 +0200

    Resolves: tdf#91758 more stringent check for ISO date like looking input
    
     This is a combination of 4 commits.
    
    Related: tdf#91758 don't remember nCanForceToIso8601 state
    
    CanForceToIso8601() can be called twice for different DateOrder.
    
    (cherry picked from commit ae6c5083f04f8fad299cdc7a6b6558f1270cc619)
    
    Related: tdf#91758 shortcut CanForceToIso8601() for MayBeIso8601() results
    
    (cherry picked from commit 6254fbf8a76a0d8edb290b03e0632ef6513a8d98)
    
    Resolves: tdf#91758 more stringent check for ISO date like looking input
    
    Already check at the end of input analysis whether it could be an ISO date to
    not apply x-y-z onto MDY or DMY later. For an acceptable ISO input, apart from
    M and D restrictions, Y-M-D year numbers must be greater than 12 in MDY order
    or greater than 31 in DMY order, or have at least 3 digits (possibly leading 0).
    
    (cherry picked from commit 1cfe6a904d3349413173f5d412c280936f938a9e)
    
     Conflicts:
            svl/source/numbers/zforfind.cxx
    
    Backported.
    
    3cd6967931abcbf806a539a19f7f9371398567c2
    8d3eb7e2403421469050850e45d1db5c0be018f5
    
    Force ISO date format again if ISO input, tdf#91758 follow-up
    
    ... and input doesn't match a date acceptance pattern, even if less than 3
    digits in year.
    
    (cherry picked from commit f49ef5b771910384de0bc2d4c86ad3e0442b295a)
    
    b25aa8e813c06a224cfa95ead79c0f3bf2d2d672
    
    Change-Id: I656d499b8a557814326fe71333fcb644c7d3e909
    Reviewed-on: https://gerrit.libreoffice.org/41726
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index 08fc26e20435..b900f3856296 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -132,7 +132,6 @@ void ImpSvNumberInputScan::Reset()
     nAcceptedDatePattern = -2;
     nDatePatternStart = 0;
     nDatePatternNumbers = 0;
-    nCanForceToIso8601 = 0;
 
     for (sal_uInt32 i = 0; i < SV_MAX_ANZ_INPUT_STRINGS; i++)
     {
@@ -1046,47 +1045,69 @@ bool ImpSvNumberInputScan::MayBeIso8601()
 
 bool ImpSvNumberInputScan::CanForceToIso8601( DateOrder eDateOrder )
 {
-    if (nCanForceToIso8601 == 0)
+    int nCanForceToIso8601 = 0;
+    if (!MayBeIso8601())
     {
-
-        if (!MayBeIso8601())
-        {
-            nCanForceToIso8601 = 1;
-        }
-        else if (nMayBeIso8601 >= 3)
-        {
-            nCanForceToIso8601 = 2; // at least 3 digits in year
-        }
-        else
+        return false;
+    }
+    else if (nMayBeIso8601 >= 3)
+    {
+        return true;    // at least 3 digits in year
+    }
+    else
+    {
+        if (eDateOrder == DateOrder::Invalid)
         {
-            nCanForceToIso8601 = 1;
+            // As if any of the cases below can be applied, but only if a
+            // locale dependent date pattern was not matched.
+            return (GetDatePatternNumbers() != nAnzNums) || !IsDatePatternNumberOfType(0,'Y');
         }
 
-        sal_Int32 n;
-        switch (eDateOrder)
-        {
+        nCanForceToIso8601 = 1;
+    }
+
+    sal_Int32 n;
+    switch (eDateOrder)
+    {
         case DateOrder::DMY:               // "day" value out of range => ISO 8601 year
             if ((n = sStrArray[nNums[0]].toInt32()) < 1 || n > 31)
             {
                 nCanForceToIso8601 = 2;
             }
-            break;
+        break;
         case DateOrder::MDY:               // "month" value out of range => ISO 8601 year
             if ((n = sStrArray[nNums[0]].toInt32()) < 1 || n > 12)
             {
                 nCanForceToIso8601 = 2;
             }
-            break;
+        break;
         case DateOrder::YMD:               // always possible
             nCanForceToIso8601 = 2;
-            break;
+        break;
         default: break;
-        }
     }
     return nCanForceToIso8601 > 1;
 }
 
 
+bool ImpSvNumberInputScan::IsAcceptableIso8601( const SvNumberformat* pFormat )
+{
+    if (pFormat && (pFormat->GetType() & css::util::NumberFormat::DATE))
+    {
+        switch (pFormatter->GetEvalDateFormat())
+        {
+            case NF_EVALDATEFORMAT_INTL:
+                return CanForceToIso8601( GetDateOrder());
+            case NF_EVALDATEFORMAT_FORMAT:
+                return CanForceToIso8601( pFormat->GetDateOrder());
+            default:
+                return CanForceToIso8601( GetDateOrder()) || CanForceToIso8601( pFormat->GetDateOrder());
+        }
+    }
+    return CanForceToIso8601( GetDateOrder());
+}
+
+
 bool ImpSvNumberInputScan::MayBeMonthDate()
 {
     if (nMayBeMonthDate == 0)
@@ -3644,7 +3665,7 @@ bool ImpSvNumberInputScan::IsNumberFormat( const OUString& rString,         // s
                         // not. The count of numbers in pattern must match the
                         // count of numbers in input.
                         res = (GetDatePatternNumbers() == nAnzNums)
-                            || MayBeIso8601() || nMatchedAllStrings;
+                            || IsAcceptableIso8601( pFormat) || nMatchedAllStrings;
                     }
                 }
                 break;
diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx
index 6f95d4c6e6b3..819fef30d374 100644
--- a/svl/source/numbers/zforfind.hxx
+++ b/svl/source/numbers/zforfind.hxx
@@ -61,12 +61,6 @@ public:
     /** Whether input can be forced to ISO 8601 format.
 
         Depends on locale's date separator and a specific date format order.
-
-        @param eDateOrder
-            Evaluated only on first call during one scan process, subsequent
-            calls return state of nCanForceToIso8601!
-
-        @see nCanForceToIso8601
      */
     bool CanForceToIso8601( DateOrder eDateOrder );
 
@@ -142,16 +136,6 @@ private:
      */
     sal_uInt8    nMayBeIso8601;
 
-    /** State of ISO 8601 can be forced.
-
-        0:= don't know yet
-        1:= no
-        2:= yes
-
-        @see CanForceToIso8601()
-     */
-    sal_uInt8   nCanForceToIso8601;
-
     /** State of dd-month-yy or yy-month-dd detection, with month name.
 
         0:= don't know yet
@@ -427,6 +411,11 @@ private:
         @see nMayBeMonthDate
      */
     bool MayBeMonthDate();
+
+    /** Whether input is acceptable as ISO 8601 date format in the current
+        NfEvalDateFormat setting.
+     */
+    bool IsAcceptableIso8601( const SvNumberformat* pFormat );
 };
 
 #endif // INCLUDED_SVL_SOURCE_NUMBERS_ZFORFIND_HXX
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index 27d5a3a50592..7db681089cc1 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -1105,7 +1105,7 @@ bool SvNumberFormatter::IsNumberFormat(const OUString& sString,
         {
         case css::util::NumberFormat::DATE :
             // Preserve ISO 8601 input.
-            if (pStringScanner->CanForceToIso8601( DateOrder::DMY))
+            if (pStringScanner->CanForceToIso8601( DateOrder::Invalid))
             {
                 F_Index = GetFormatIndex( NF_DATE_DIN_YYYYMMDD, ActLnge );
             }


More information about the Libreoffice-commits mailing list