[Libreoffice-commits] core.git: 3 commits - include/unotools unotools/source xmloff/source

Eike Rathke erack at redhat.com
Tue Sep 13 10:56:31 UTC 2016


 include/unotools/localedatawrapper.hxx     |   29 ++++++++-----
 unotools/source/i18n/localedatawrapper.cxx |   61 ++++++++++++++++++++++++++++-
 xmloff/source/style/xmlnumfi.cxx           |    5 --
 3 files changed, 78 insertions(+), 17 deletions(-)

New commits:
commit f882555332fffbd3ea82c3a25a05ebebe3884415
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Sep 13 12:46:21 2016 +0200

    switch to using LocaleDataWrapper::doesSecondaryCalendarUseEC()
    
    Change-Id: I6621e82249feeed3d88ee463447d08c4f812259c

diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx
index e2b0f8d..ec363c3 100644
--- a/xmloff/source/style/xmlnumfi.cxx
+++ b/xmloff/source/style/xmlnumfi.cxx
@@ -1205,10 +1205,7 @@ void SvXMLNumFmtElementContext::EndElement()
 //! I18N doesn't provide SYSTEM or extended date information yet
             // Y after G (era) is replaced by E, also if we're switching to the
             // other second known calendar for a locale.
-            /* TODO: here only for zh-TW, handle for other locales as well. */
-            if ( rParent.HasEra() ||
-                    (sCalendar.equalsIgnoreAsciiCase("ROC") &&
-                     rParent.GetLocaleData().getLoadedLanguageTag().getBcp47() == "zh-TW"))
+            if ( rParent.HasEra() || rParent.GetLocaleData().doesSecondaryCalendarUseEC( sCalendar))
             {
                 rParent.AddNfKeyword(
                     sal::static_int_cast< sal_uInt16 >(
commit c22f9f0e00f26015f8019193c0db2fbb895b2cdc
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Sep 13 12:43:05 2016 +0200

    introduce LocaleDataWrapper::doesSecondaryCalendarUseEC()
    
    Preparing to replace the number format import hack of
    95c91f098e8974c41c8d403a351fe53db6822165 and generalizing for known locales.
    
    Change-Id: I0413987e302eaa84ef6a7dde2ecb365144313e81

diff --git a/include/unotools/localedatawrapper.hxx b/include/unotools/localedatawrapper.hxx
index 642cd82..0ea75ef 100644
--- a/include/unotools/localedatawrapper.hxx
+++ b/include/unotools/localedatawrapper.hxx
@@ -58,6 +58,7 @@ class UNOTOOLS_DLLPUBLIC LocaleDataWrapper
     css::uno::Reference< css::i18n::XLocaleData4 >     xLD;
     LanguageTag                                        maLanguageTag;
     std::shared_ptr< css::i18n::Calendar2 >            xDefaultCalendar;
+    std::shared_ptr< css::i18n::Calendar2 >            xSecondaryCalendar;
     css::i18n::LocaleDataItem                          aLocaleDataItem;
     css::uno::Sequence< OUString >                     aReservedWordSeq;
     css::uno::Sequence< OUString >                     aDateAcceptancePatterns;
@@ -74,6 +75,7 @@ class UNOTOOLS_DLLPUBLIC LocaleDataWrapper
     sal_uInt16              nCurrDigits;
     bool                    bLocaleDataItemValid;
     bool                    bReservedWordValid;
+    bool                    bSecondaryCalendarValid;
     mutable ::utl::ReadWriteMutex   aMutex;
     struct Locale_Compare
     {
@@ -105,6 +107,7 @@ class UNOTOOLS_DLLPUBLIC LocaleDataWrapper
     DateFormat          scanDateFormatImpl( const OUString& rCode );
 
     void                getDefaultCalendarImpl();
+    void                getSecondaryCalendarImpl();
 
     sal_Unicode*        ImplAddFormatNum( sal_Unicode* pBuf,
                             sal_Int64 nNumber, sal_uInt16 nDecimals,
@@ -183,6 +186,10 @@ public:
     /// Convenience method to obtain the month names of the default calendar.
     const css::uno::Sequence< css::i18n::CalendarItem2 > getDefaultCalendarMonths() const;
 
+    /** If the secondary calendar, if any, is of the name passed AND number
+        formats using it usually use the E or EE keyword (EC|EEC). */
+    bool doesSecondaryCalendarUseEC( const OUString& rName ) const;
+
     /** Obtain digit grouping. The usually known grouping by thousands (#,###)
         is actually only one of possible groupings. Another one, for example,
         used in India is group by 3 and then by 2 indefinitely (#,##,###). The
diff --git a/unotools/source/i18n/localedatawrapper.cxx b/unotools/source/i18n/localedatawrapper.cxx
index 1a31ba5..1c996c5 100644
--- a/unotools/source/i18n/localedatawrapper.cxx
+++ b/unotools/source/i18n/localedatawrapper.cxx
@@ -89,7 +89,8 @@ LocaleDataWrapper::LocaleDataWrapper(
         xLD( LocaleData::create(rxContext) ),
         maLanguageTag( rLanguageTag ),
         bLocaleDataItemValid( false ),
-        bReservedWordValid( false )
+        bReservedWordValid( false ),
+        bSecondaryCalendarValid( false )
 {
     invalidateData();
 }
@@ -102,7 +103,8 @@ LocaleDataWrapper::LocaleDataWrapper(
         xLD( LocaleData::create(m_xContext) ),
         maLanguageTag( rLanguageTag ),
         bLocaleDataItemValid( false ),
-        bReservedWordValid( false )
+        bReservedWordValid( false ),
+        bSecondaryCalendarValid( false )
 {
     invalidateData();
 }
@@ -149,6 +151,8 @@ void LocaleDataWrapper::invalidateData()
         bReservedWordValid = false;
     }
     xDefaultCalendar.reset();
+    xSecondaryCalendar.reset();
+    bSecondaryCalendarValid = false;
     if (aGrouping.getLength())
         aGrouping[0] = 0;
     if (aDateAcceptancePatterns.getLength())
@@ -475,6 +479,59 @@ MeasurementSystem LocaleDataWrapper::mapMeasurementStringToEnum( const OUString&
     return MEASURE_US;
 }
 
+void LocaleDataWrapper::getSecondaryCalendarImpl()
+{
+    if (!xSecondaryCalendar && !bSecondaryCalendarValid)
+    {
+        Sequence< Calendar2 > xCals = getAllCalendars();
+        sal_Int32 nCount = xCals.getLength();
+        if (nCount > 1)
+        {
+            sal_Int32 nNonDef = -1;
+            const Calendar2* pArr = xCals.getArray();
+            for (sal_Int32 i=0; i<nCount; ++i)
+            {
+                if (!pArr[i].Default)
+                {
+                    nNonDef = i;
+                    break;
+                }
+            }
+            if (nNonDef >= 0)
+                xSecondaryCalendar.reset( new Calendar2( xCals[nNonDef]));
+        }
+        bSecondaryCalendarValid = true;
+    }
+}
+
+bool LocaleDataWrapper::doesSecondaryCalendarUseEC( const OUString& rName ) const
+{
+    if (rName.isEmpty())
+        return false;
+
+    ::utl::ReadWriteGuard aGuard( aMutex );
+
+    if (!bSecondaryCalendarValid)
+    {   // no cached content
+        aGuard.changeReadToWrite();
+        const_cast<LocaleDataWrapper*>(this)->getSecondaryCalendarImpl();
+    }
+    if (!xSecondaryCalendar)
+        return false;
+    if (!xSecondaryCalendar->Name.equalsIgnoreAsciiCase( rName))
+        return false;
+
+    LanguageTag aLoaded( getLoadedLanguageTag());
+    OUString aBcp47( aLoaded.getBcp47());
+    // So far determine only by locale, we know for a few.
+    /* TODO: check date format codes? or add to locale data? */
+    return
+        aBcp47 == "ja-JP" ||
+        aBcp47 == "lo-LA" ||
+        aBcp47 == "zh-TW"
+        ;
+}
+
 void LocaleDataWrapper::getDefaultCalendarImpl()
 {
     if (!xDefaultCalendar)
commit 1e0b7b7e4b95e896e32d49a2fed7a5760e509f36
Author: Eike Rathke <erack at redhat.com>
Date:   Sun Sep 11 18:06:43 2016 +0200

    cosmetics
    
    Change-Id: I32c1df5a8e7164c59ebfe0d1e1d11dd6f3b8edf8

diff --git a/include/unotools/localedatawrapper.hxx b/include/unotools/localedatawrapper.hxx
index ac0352f..642cd82 100644
--- a/include/unotools/localedatawrapper.hxx
+++ b/include/unotools/localedatawrapper.hxx
@@ -63,17 +63,17 @@ class UNOTOOLS_DLLPUBLIC LocaleDataWrapper
     css::uno::Sequence< OUString >                     aDateAcceptancePatterns;
     css::uno::Sequence< sal_Int32 >                    aGrouping;
     // cached items
-    OUString               aLocaleItem[css::i18n::LocaleItem::COUNT];
-    OUString               aReservedWord[css::i18n::reservedWords::COUNT];
-    OUString               aCurrSymbol;
-    OUString               aCurrBankSymbol;
-    int                         nDateFormat;
-    int                         nLongDateFormat;
-    sal_uInt16                      nCurrPositiveFormat;
-    sal_uInt16                      nCurrNegativeFormat;
-    sal_uInt16                      nCurrDigits;
-    bool                        bLocaleDataItemValid;
-    bool                        bReservedWordValid;
+    OUString                aLocaleItem[css::i18n::LocaleItem::COUNT];
+    OUString                aReservedWord[css::i18n::reservedWords::COUNT];
+    OUString                aCurrSymbol;
+    OUString                aCurrBankSymbol;
+    int                     nDateFormat;
+    int                     nLongDateFormat;
+    sal_uInt16              nCurrPositiveFormat;
+    sal_uInt16              nCurrNegativeFormat;
+    sal_uInt16              nCurrDigits;
+    bool                    bLocaleDataItemValid;
+    bool                    bReservedWordValid;
     mutable ::utl::ReadWriteMutex   aMutex;
     struct Locale_Compare
     {


More information about the Libreoffice-commits mailing list