summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2016-09-13 12:43:05 +0200
committerEike Rathke <erack@redhat.com>2016-09-13 12:54:41 +0200
commitc22f9f0e00f26015f8019193c0db2fbb895b2cdc (patch)
tree9e08c7727255f8c9dcf63d139ad9f6fc22287249 /unotools
parent1e0b7b7e4b95e896e32d49a2fed7a5760e509f36 (diff)
introduce LocaleDataWrapper::doesSecondaryCalendarUseEC()
Preparing to replace the number format import hack of 95c91f098e8974c41c8d403a351fe53db6822165 and generalizing for known locales. Change-Id: I0413987e302eaa84ef6a7dde2ecb365144313e81
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/i18n/localedatawrapper.cxx61
1 files changed, 59 insertions, 2 deletions
diff --git a/unotools/source/i18n/localedatawrapper.cxx b/unotools/source/i18n/localedatawrapper.cxx
index 1a31ba56755e..1c996c54f9b6 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)