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

Eike Rathke erack at kemper.freedesktop.org
Thu Dec 22 10:04:03 PST 2011


 svl/inc/svl/zforlist.hxx        |    3 +
 svl/inc/svl/zformat.hxx         |   20 +++++++++--
 svl/source/numbers/zforlist.cxx |    8 ++--
 svl/source/numbers/zformat.cxx  |   68 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 91 insertions(+), 8 deletions(-)

New commits:
commit daf5b5ce7656fd6b6f318344a45adcbe7f30f91f
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Dec 22 19:00:21 2011 +0100

    recognize arbitrary y-m-d format for editing as ISO 8601 yyyy-mm-dd

diff --git a/svl/inc/svl/zforlist.hxx b/svl/inc/svl/zforlist.hxx
index ffae629..627284a 100644
--- a/svl/inc/svl/zforlist.hxx
+++ b/svl/inc/svl/zforlist.hxx
@@ -596,7 +596,8 @@ public:
     bool IsSpecialStandardFormat( sal_uInt32 nFIndex, LanguageType eLnge );
 
     /** Return the corresponding edit format of a format. */
-    sal_uInt32 GetEditFormat( double fNumber, sal_uInt32 nFIndex, short eType, LanguageType eLnge );
+    sal_uInt32 GetEditFormat( double fNumber, sal_uInt32 nFIndex, short eType,
+            LanguageType eLnge, SvNumberformat* pFormat );
 
     /// Return the reference date
     Date* GetNullDate();
diff --git a/svl/inc/svl/zformat.hxx b/svl/inc/svl/zformat.hxx
index 659b930..2633128 100644
--- a/svl/inc/svl/zformat.hxx
+++ b/svl/inc/svl/zformat.hxx
@@ -456,6 +456,15 @@ public:
             return false;
         }
 #endif
+
+    /// Whether it's a (YY)YY-M(M)-D(D) format.
+    bool IsIso8601( sal_uInt16 nNumFor )
+        {
+            if ( nNumFor < 4 )
+                return ImpIsIso8601( NumFor[nNumFor]);
+            return false;
+        }
+
 private:
     ImpSvNumFor NumFor[4];          // Array for the 4 subformats
     String sFormatstring;           // The format code string
@@ -476,6 +485,11 @@ private:
 
     SVL_DLLPRIVATE bool ImpIsOtherCalendar( const ImpSvNumFor& rNumFor ) const;
 
+#ifdef THE_FUTURE
+    SVL_DLLPRIVATE bool ImpSwitchToSpecifiedCalendar( String& rOrgCalendar,
+            double& fOrgDateTime, const ImpSvNumFor& rNumFor ) const;
+#endif
+
     /** Whether to use possessive genitive case month name, or partitive case 
         month name, instead of nominative name (noun).
 
@@ -496,10 +510,8 @@ private:
      */
     SVL_DLLPRIVATE sal_Int32 ImpUseMonthCase( int & io_nState, const ImpSvNumFor& rNumFor, NfKeywordIndex eCodeType ) const;
 
-#ifdef THE_FUTURE
-    SVL_DLLPRIVATE bool ImpSwitchToSpecifiedCalendar( String& rOrgCalendar,
-            double& fOrgDateTime, const ImpSvNumFor& rNumFor ) const;
-#endif
+    /// Whether it's a (YY)YY-M(M)-D(D) format.
+    SVL_DLLPRIVATE bool ImpIsIso8601( const ImpSvNumFor& rNumFor );
 
 #ifdef _ZFORMAT_CXX     // ----- private implementation methods -----
 
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index 295a618..b248413 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -1437,7 +1437,8 @@ sal_uInt32 SvNumberFormatter::GetStandardFormat( double fNumber, sal_uInt32 nFIn
     }
 }
 
-sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex, short eType, LanguageType eLang )
+sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex,
+        short eType, LanguageType eLang, SvNumberformat* pFormat )
 {
     sal_uInt32 nKey = nFIndex;
     switch ( eType )
@@ -1456,7 +1457,8 @@ sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex,
                 // Preserve ISO 8601 format.
                 if (    nFIndex == GetFormatIndex( NF_DATE_DIN_YYYYMMDD, eLang) ||
                         nFIndex == GetFormatIndex( NF_DATE_DIN_YYMMDD, eLang) ||
-                        nFIndex == GetFormatIndex( NF_DATE_DIN_MMDD, eLang))
+                        nFIndex == GetFormatIndex( NF_DATE_DIN_MMDD, eLang) ||
+                        (pFormat && pFormat->IsIso8601( 0 )))
                     nKey = GetFormatIndex( NF_DATE_DIN_YYYYMMDD, eLang);
                 else
                     nKey = GetFormatIndex( NF_DATE_SYS_DDMMYYYY, eLang );
@@ -1517,7 +1519,7 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber,
         ChangeStandardPrec(INPUTSTRING_PRECISION);
         bPrecChanged = true;
     }
-    sal_uInt32 nKey = GetEditFormat( fOutNumber, nFIndex, eType, eLang);
+    sal_uInt32 nKey = GetEditFormat( fOutNumber, nFIndex, eType, eLang, pFormat);
     if ( nKey != nFIndex )
         pFormat = (SvNumberformat*) aFTable.Get( nKey );
     if (pFormat)
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index a85491e..ff336be 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -3196,6 +3196,74 @@ void SvNumberformat::ImpAppendEraG( String& OutString,
         OutString += rCal.getDisplayString( CalendarDisplayCode::SHORT_ERA, nNatNum );
 }
 
+bool SvNumberformat::ImpIsIso8601( const ImpSvNumFor& rNumFor )
+{
+    bool bIsIso = false;
+    if ((eType & NUMBERFORMAT_DATE) == NUMBERFORMAT_DATE)
+    {
+        enum State
+        {
+            eNone,
+            eAtYear,
+            eAtSep1,
+            eAtMonth,
+            eAtSep2,
+            eNotIso
+        };
+        State eState = eNone;
+        short const * const pType = rNumFor.Info().nTypeArray;
+        sal_uInt16 nAnz = rNumFor.GetCount();
+        for (sal_uInt16 i=0; i < nAnz && !bIsIso && eState != eNotIso; ++i)
+        {
+            switch ( pType[i] )
+            {
+                case NF_KEY_YY:     // two digits not strictly ISO 8601
+                case NF_KEY_YYYY:
+                    if (eState != eNone)
+                        eState = eNotIso;
+                    else
+                        eState = eAtYear;
+                    break;
+                case NF_KEY_M:      // single digit not strictly ISO 8601
+                case NF_KEY_MM:
+                    if (eState != eAtSep1)
+                        eState = eNotIso;
+                    else
+                        eState = eAtMonth;
+                    break;
+                case NF_KEY_D:      // single digit not strictly ISO 8601
+                case NF_KEY_DD:
+                    if (eState != eAtSep2)
+                        eState = eNotIso;
+                    else
+                        bIsIso = true;
+                    break;
+                case NF_SYMBOLTYPE_STRING:
+                case NF_SYMBOLTYPE_DATESEP:
+                    if (rNumFor.Info().sStrArray[i] == '-')
+                    {
+                        if (eState == eAtYear)
+                            eState = eAtSep1;
+                        else if (eState == eAtMonth)
+                            eState = eAtSep2;
+                        else
+                            eState = eNotIso;
+                    }
+                    else
+                        eState = eNotIso;
+                    break;
+                default:
+                    eState = eNotIso;
+            }
+        }
+    }
+    else
+    {
+       OSL_FAIL( "SvNumberformat::ImpIsIso8601: no date" );
+    }
+    return bIsIso;
+}
+
 bool SvNumberformat::ImpGetDateOutput(double fNumber,
                                    sal_uInt16 nIx,
                                    String& OutString)


More information about the Libreoffice-commits mailing list