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

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Sat Oct 19 09:03:33 UTC 2019


 include/svl/zformat.hxx         |    5 ++
 svl/source/numbers/zforfind.cxx |    5 ++
 svl/source/numbers/zformat.cxx  |   80 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+)

New commits:
commit 87660c3334c5150f20f3a7dbcd8f660922a203a5
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Sat Oct 19 01:06:24 2019 +0200
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Sat Oct 19 11:02:57 2019 +0200

    Resolves: tdf#76441 accept two digit groups MM:SS input if formatted as such
    
    ... instead of producing the usual HH:MM:00
    
    Works on the formats
    MM:SS
    [MM]:SS
    MM:SS.00
    [MM]:SS.00
    
    and even
    MM:[SS]
    MM:[SS].00
    although these two don't make much sense except of displaying
    leading 00:, but were always accepted.
    
    Change-Id: I1dbe147cafaa934efa1d86b187eaab61f0981fca
    Reviewed-on: https://gerrit.libreoffice.org/81117
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins

diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx
index 55a3d3c6f76c..b6d962d1fc98 100644
--- a/include/svl/zformat.hxx
+++ b/include/svl/zformat.hxx
@@ -220,6 +220,11 @@ public:
             return maLocale.meSubstitute == LocaleType::Substitute::LONGDATE && maLocale.meLanguage == LANGUAGE_SYSTEM;
         }
 
+    /** If the format is a MM:SS or [MM]:SS format, or MM:[SS] (sic!) or even
+        MM:SS.00 or [MM]:SS.00 or MM:[SS].00
+     */
+    bool IsMinuteSecondFormat() const;
+
     const OUString& GetFormatstring() const   { return sFormatstring; }
 
     // Build a format string of application defined keywords
diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index 2ad9bfea50df..90debaadb205 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -962,6 +962,11 @@ bool ImpSvNumberInputScan::GetTimeRef( double& fOutNumber,
     {
         nHour = 0;
     }
+    else if (mpFormat && nDecPos == 0 && nCnt == 2 && mpFormat->IsMinuteSecondFormat())
+    {
+        // Input on MM:SS format, instead of doing HH:MM:00
+        nHour = 0;
+    }
     else if (nIndex - nStartIndex < nCnt)
     {
         nHour   = static_cast<sal_uInt16>(sStrArray[nNums[nIndex++]].toInt32());
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index dfb41fb0f496..e215ca40f84c 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -5754,6 +5754,86 @@ sal_uInt16 SvNumberformat::ImpGetNumForStringElementCount( sal_uInt16 nNumFor )
     return nCnt;
 }
 
+bool SvNumberformat::IsMinuteSecondFormat() const
+{
+    if (GetMaskedType() != SvNumFormatType::TIME)
+        return false;
+
+    constexpr sal_uInt16 k00 = 0x00;    // Nada, Nilch
+    constexpr sal_uInt16 kLB = 0x01;    // '[' Left Bracket
+    constexpr sal_uInt16 kRB = 0x02;    // ']' Right Bracket
+    constexpr sal_uInt16 kMM = 0x04;    // M or MM
+    constexpr sal_uInt16 kTS = 0x08;    // Time Separator
+    constexpr sal_uInt16 kSS = 0x10;    // S or SS
+#define HAS_MINUTE_SECOND(state) ((state) == (kMM|kTS|kSS) || (state) == (kLB|kMM|kRB|kTS|kSS))
+    // Also (kMM|kTS|kLB|kSS|kRB) but those are the same bits.
+
+    sal_uInt16 nState = k00;
+    bool bSep = false;
+    sal_uInt16 nNumForCnt = NumFor[0].GetCount();
+    auto const & rTypeArray = NumFor[0].Info().nTypeArray;
+    for (sal_uInt16 j=0; j < nNumForCnt; ++j)
+    {
+        switch (rTypeArray[j])
+        {
+            case NF_SYMBOLTYPE_DEL:
+                {
+                    // '[' or ']' before/after MM or SS
+                    const OUString& rStr = NumFor[0].Info().sStrArray[j];
+                    if (rStr == "[")
+                    {
+                        if (nState != k00 && nState != (kMM|kTS))
+                            return false;
+                        nState |= kLB;
+                    }
+                    else if (rStr == "]")
+                    {
+                        if (nState != (kLB|kMM) && nState != (kMM|kTS|kLB|kSS))
+                            return false;
+                        nState |= kRB;
+                    }
+                    else
+                        return false;
+                }
+            break;
+            case NF_KEY_MI:
+            case NF_KEY_MMI:
+                if (nState != k00 && nState != kLB)
+                    return false;
+                nState |= kMM;
+            break;
+            case NF_SYMBOLTYPE_TIMESEP:
+                if (nState != kMM && nState != (kLB|kMM|kRB))
+                    return false;
+                nState |= kTS;
+            break;
+            case NF_KEY_S:
+            case NF_KEY_SS:
+                if (nState != (kMM|kTS) && nState != (kLB|kMM|kRB|kTS) && nState != (kMM|kTS|kLB))
+                    return false;
+                nState |= kSS;
+            break;
+            case NF_SYMBOLTYPE_TIME100SECSEP:
+                // Trailing fraction of seconds allowed.
+                if (!HAS_MINUTE_SECOND(nState))
+                    return false;
+                bSep = true;
+            break;
+            case NF_SYMBOLTYPE_DIGIT:
+                if (!bSep)
+                    return false;
+            break;
+            case NF_SYMBOLTYPE_STRING:
+                // nothing, display literal
+            break;
+            default:
+                return false;
+        }
+    }
+    return HAS_MINUTE_SECOND(nState);
+#undef HAS_MINUTE_SECOND
+}
+
 const CharClass& SvNumberformat::rChrCls() const
 {
     return rScan.GetChrCls();


More information about the Libreoffice-commits mailing list