[Libreoffice-commits] .: Branch 'libreoffice-3-6' - svl/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Dec 21 01:13:21 PST 2012


 svl/source/numbers/zforfind.cxx |   66 +++++++++++++++++++++++++++++++++++++---
 svl/source/numbers/zforfind.hxx |   10 ++++++
 2 files changed, 72 insertions(+), 4 deletions(-)

New commits:
commit fd7a679774088cfbbadcca9434b10f0089fd2a49
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Dec 19 19:21:55 2012 +0100

    resolved fdo#54336 accept abbreviated combined date/time input
    
    Abbreviated combined date/time input was not accepted if the date
    acceptance pattern ended in a separator, like "D.M." with input
    "D.M. hh:mm".
    
    Additionally check that for "D.M. #" input against a "D.M." pattern the
    '#' (any number) is not interpreted as year if the input so far was
    recognized to possibly match a date without time, in which case the
    count of numbers in input must match the count of numbers in pattern and
    input here is not a date.
    
    (cherry picked from commit f2851a270eb9c617fce9bfdde5c8f2428ced7014)
    
    Conflicts:
    
    	svl/source/numbers/zforfind.cxx
    
    Change-Id: I7f1f9c8477e35241ee747bf92b9d8832b2de16fe
    Reviewed-on: https://gerrit.libreoffice.org/1423
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index ef6015e..9c4018c 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -148,6 +148,7 @@ void ImpSvNumberInputScan::Reset()
     nMayBeMonthDate = 0;
     nAcceptedDatePattern = -2;
     nDatePatternStart = 0;
+    nDatePatternNumbers = 0;
     nCanForceToIso8601 = 0;
 }
 
@@ -1103,6 +1104,7 @@ bool ImpSvNumberInputScan::IsAcceptedDatePattern( sal_uInt16 nStartPatternAt )
     for (sal_Int32 nPattern=0; nPattern < sDateAcceptancePatterns.getLength(); ++nPattern)
     {
         sal_uInt16 nNext = nDatePatternStart;
+        nDatePatternNumbers = 0;
         bool bOk = true;
         const rtl::OUString& rPat = sDateAcceptancePatterns[nPattern];
         sal_Int32 nPat = 0;
@@ -1114,6 +1116,8 @@ bool ImpSvNumberInputScan::IsAcceptedDatePattern( sal_uInt16 nStartPatternAt )
                 case 'M':
                 case 'D':
                     bOk = IsNum[nNext];
+                    if (bOk)
+                        ++nDatePatternNumbers;
                     break;
                 default:
                     bOk = !IsNum[nNext];
@@ -1145,10 +1149,43 @@ bool ImpSvNumberInputScan::IsAcceptedDatePattern( sal_uInt16 nStartPatternAt )
             if (nNext < nAnzStrings)
             {
                 // Pattern end but not input end.
-                if (!IsNum[nNext])
+                // A trailing blank may be part of the current pattern input,
+                // if pattern is "D.M." and input is "D.M. hh:mm" last was
+                // ". ", or may be following the current pattern input, if
+                // pattern is "D.M" and input is "D.M hh:mm" last was "M".
+                xub_StrLen nPos = 0;
+                sal_uInt16 nCheck;
+                if (nPat > 0 && nNext > 0)
+                {
+                    // nPat is one behind after the for loop.
+                    sal_Int32 nPatCheck = nPat - 1;
+                    switch (rPat[nPatCheck])
+                    {
+                        case 'Y':
+                        case 'M':
+                        case 'D':
+                            nCheck = nNext;
+                            break;
+                        default:
+                            {
+                                nCheck = nNext - 1;
+                                // Advance position in input to match length of
+                                // non-YMD (separator) characters in pattern.
+                                sal_Unicode c;
+                                do
+                                {
+                                    ++nPos;
+                                } while ((c = rPat[--nPatCheck]) != 'Y' && c != 'M' && c != 'D');
+                            }
+                    }
+                }
+                else
+                {
+                    nCheck = nNext;
+                }
+                if (!IsNum[nCheck])
                 {
                     // Trailing (or separating if time follows) blanks are ok.
-                    xub_StrLen nPos = 0;
                     SkipBlanks( sStrArray[nNext], nPos);
                     if (nPos == sStrArray[nNext].Len())
                     {
@@ -1222,6 +1259,18 @@ bool ImpSvNumberInputScan::SkipDatePatternSeparator( sal_uInt16 nParticle, xub_S
 
 //---------------------------------------------------------------------------
 
+sal_uInt16 ImpSvNumberInputScan::GetDatePatternNumbers()
+{
+    // If not initialized yet start with first number, if any.
+    if (!IsAcceptedDatePattern( (nAnzNums ? nNums[0] : 0)))
+    {
+        return 0;
+    }
+    return nDatePatternNumbers;
+}
+
+//---------------------------------------------------------------------------
+
 sal_uInt32 ImpSvNumberInputScan::GetDatePatternOrder()
 {
     // If not initialized yet start with first number, if any.
@@ -3044,8 +3093,17 @@ bool ImpSvNumberInputScan::IsNumberFormat(
                         if (nAnzNums > 3)
                             res = false;
                         else
-                            res = IsAcceptedDatePattern( nNums[0]) ||
-                                MayBeIso8601() || nMatchedAllStrings;
+                        {
+                            // Even if a date pattern was matched, for abbreviated
+                            // pattern like "D.M." an input of "D.M. #" was
+                            // accepted because # could had been a time. Here we do
+                            // not have a combined date/time input though and #
+                            // would be taken as Year in this example, which it is
+                            // not. The count of numbers in pattern must match the
+                            // count of numbers in input.
+                            res = (GetDatePatternNumbers() == nAnzNums)
+                                || MayBeIso8601() || nMatchedAllStrings;
+                        }
                     }
                     break;
 
diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx
index 233b012..8bf4c9b 100644
--- a/svl/source/numbers/zforfind.hxx
+++ b/svl/source/numbers/zforfind.hxx
@@ -190,6 +190,12 @@ private:
      */
     sal_uInt16  nDatePatternStart;
 
+    /** Count of numbers that matched the accepted pattern, if any, else 0.
+
+        @see GetDatePatternNumbers()
+     */
+    sal_uInt16  nDatePatternNumbers;
+
 #ifdef _ZFORFIND_CXX        // methods private to implementation
     void Reset();                               // Reset all variables before start of analysis
 
@@ -368,6 +374,10 @@ private:
      */
     bool SkipDatePatternSeparator( sal_uInt16 nParticle, xub_StrLen & rPos );
 
+    /** Returns count of numbers in accepted date pattern.
+     */
+    sal_uInt16 GetDatePatternNumbers();
+
     /** Obtain order of accepted date pattern coded as, for example,
         ('D'<<16)|('M'<<8)|'Y'
     */


More information about the Libreoffice-commits mailing list