summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/inc/numberformatcode.hxx15
-rw-r--r--i18npool/source/numberformatcode/numberformatcode.cxx77
2 files changed, 55 insertions, 37 deletions
diff --git a/i18npool/inc/numberformatcode.hxx b/i18npool/inc/numberformatcode.hxx
index 48c64c24de70..9c7d78066d3e 100644
--- a/i18npool/inc/numberformatcode.hxx
+++ b/i18npool/inc/numberformatcode.hxx
@@ -29,9 +29,6 @@
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
-#include <deque>
-#include <utility>
-
class NumberFormatCodeMapper : public cppu::WeakImplHelper
<
css::i18n::XNumberFormatCode,
@@ -58,15 +55,19 @@ public:
private:
osl::Mutex maMutex;
- css::uno::Reference < css::i18n::XLocaleData4 > m_xLocaleData;
- typedef std::pair< css::lang::Locale, css::uno::Sequence< css::i18n::FormatElement > > FormatElementCacheItem;
- std::deque < FormatElementCacheItem > m_aFormatElementCache;
+ css::lang::Locale aLocale;
+ css::uno::Reference < css::uno::XComponentContext > mxContext;
+ css::uno::Sequence< css::i18n::FormatElement > aFormatSeq;
+ css::uno::Reference < css::i18n::XLocaleData4 > mxLocaleData;
+ bool bFormatsValid;
- const css::uno::Sequence< css::i18n::FormatElement >& getFormats( const css::lang::Locale& rLocale );
+ void setupLocale( const css::lang::Locale& rLocale );
+ void getFormats( const css::lang::Locale& rLocale );
static OUString mapElementTypeShortToString(sal_Int16 formatType);
static sal_Int16 mapElementTypeStringToShort(const OUString& formatType);
static OUString mapElementUsageShortToString(sal_Int16 formatUsage);
static sal_Int16 mapElementUsageStringToShort(const OUString& formatUsage);
+ void createLocaleDataObject();
};
diff --git a/i18npool/source/numberformatcode/numberformatcode.cxx b/i18npool/source/numberformatcode/numberformatcode.cxx
index fe56556009d8..4a5e14782cef 100644
--- a/i18npool/source/numberformatcode/numberformatcode.cxx
+++ b/i18npool/source/numberformatcode/numberformatcode.cxx
@@ -25,8 +25,10 @@
NumberFormatCodeMapper::NumberFormatCodeMapper(
const css::uno::Reference < css::uno::XComponentContext >& rxContext )
+ :
+ mxContext( rxContext ),
+ bFormatsValid( false )
{
- m_xLocaleData.set( css::i18n::LocaleData::create( rxContext ) );
}
@@ -43,10 +45,10 @@ NumberFormatCodeMapper::getDefault( sal_Int16 formatType, sal_Int16 formatUsage,
OUString elementUsage = mapElementUsageShortToString(formatUsage);
osl::MutexGuard g(maMutex);
- const css::uno::Sequence< css::i18n::FormatElement > &aFormatSeq = getFormats( rLocale );
+ getFormats( rLocale );
- for (sal_Int32 i = 0; i < aFormatSeq.getLength(); i++) {
- if (aFormatSeq[i].isDefault && aFormatSeq[i].formatType == elementType &&
+ for(sal_Int32 i = 0; i < aFormatSeq.getLength(); i++) {
+ if(aFormatSeq[i].isDefault && aFormatSeq[i].formatType == elementType &&
aFormatSeq[i].formatUsage == elementUsage) {
css::i18n::NumberFormatCode anumberFormatCode(formatType,
formatUsage,
@@ -67,10 +69,10 @@ css::i18n::NumberFormatCode SAL_CALL
NumberFormatCodeMapper::getFormatCode( sal_Int16 formatIndex, const css::lang::Locale& rLocale ) throw(css::uno::RuntimeException, std::exception)
{
osl::MutexGuard g(maMutex);
- const css::uno::Sequence< css::i18n::FormatElement > &aFormatSeq = getFormats( rLocale );
+ getFormats( rLocale );
- for (sal_Int32 i = 0; i < aFormatSeq.getLength(); i++) {
- if (aFormatSeq[i].formatIndex == formatIndex) {
+ for(sal_Int32 i = 0; i < aFormatSeq.getLength(); i++) {
+ if(aFormatSeq[i].formatIndex == formatIndex) {
css::i18n::NumberFormatCode anumberFormatCode(mapElementTypeStringToShort(aFormatSeq[i].formatType),
mapElementUsageStringToShort(aFormatSeq[i].formatUsage),
aFormatSeq[i].formatCode,
@@ -83,6 +85,7 @@ NumberFormatCodeMapper::getFormatCode( sal_Int16 formatIndex, const css::lang::L
}
css::i18n::NumberFormatCode defaultNumberFormatCode;
return defaultNumberFormatCode;
+
}
@@ -90,21 +93,21 @@ css::uno::Sequence< css::i18n::NumberFormatCode > SAL_CALL
NumberFormatCodeMapper::getAllFormatCode( sal_Int16 formatUsage, const css::lang::Locale& rLocale ) throw(css::uno::RuntimeException, std::exception)
{
osl::MutexGuard g(maMutex);
- const css::uno::Sequence< css::i18n::FormatElement > &aFormatSeq = getFormats( rLocale );
+ getFormats( rLocale );
sal_Int32 i, count;
count = 0;
- for (i = 0; i < aFormatSeq.getLength(); i++) {
+ for(i = 0; i < aFormatSeq.getLength(); i++) {
sal_Int16 elementUsage = mapElementUsageStringToShort(aFormatSeq[i].formatUsage);
- if ( elementUsage == formatUsage )
+ if( elementUsage == formatUsage)
count++;
}
css::uno::Sequence<css::i18n::NumberFormatCode> seq(count);
sal_Int32 j = 0;
- for (i = 0; i < aFormatSeq.getLength(); i++) {
+ for(i = 0; i < aFormatSeq.getLength(); i++) {
sal_Int16 elementUsage = mapElementUsageStringToShort(aFormatSeq[i].formatUsage);
- if ( elementUsage == formatUsage ) {
+ if( elementUsage == formatUsage) {
seq[j] = css::i18n::NumberFormatCode(mapElementTypeStringToShort(aFormatSeq[i].formatType),
formatUsage,
aFormatSeq[i].formatCode,
@@ -116,6 +119,7 @@ NumberFormatCodeMapper::getAllFormatCode( sal_Int16 formatUsage, const css::lang
}
}
return seq;
+
}
@@ -123,10 +127,10 @@ css::uno::Sequence< css::i18n::NumberFormatCode > SAL_CALL
NumberFormatCodeMapper::getAllFormatCodes( const css::lang::Locale& rLocale ) throw(css::uno::RuntimeException, std::exception)
{
osl::MutexGuard g(maMutex);
- const css::uno::Sequence< css::i18n::FormatElement > &aFormatSeq = getFormats( rLocale );
+ getFormats( rLocale );
css::uno::Sequence<css::i18n::NumberFormatCode> seq(aFormatSeq.getLength());
- for (sal_Int32 i = 0; i < aFormatSeq.getLength(); i++)
+ for(sal_Int32 i = 0; i < aFormatSeq.getLength(); i++)
{
seq[i] = css::i18n::NumberFormatCode(mapElementTypeStringToShort(aFormatSeq[i].formatType),
mapElementUsageStringToShort(aFormatSeq[i].formatUsage),
@@ -142,26 +146,30 @@ NumberFormatCodeMapper::getAllFormatCodes( const css::lang::Locale& rLocale ) th
// --- private implementation -----------------------------------------
-const css::uno::Sequence< css::i18n::FormatElement >& NumberFormatCodeMapper::getFormats( const css::lang::Locale& rLocale )
+void NumberFormatCodeMapper::setupLocale( const css::lang::Locale& rLocale )
{
- /* Find the FormatElement Sequence in the cache */
- for (const FormatElementCacheItem& item : m_aFormatElementCache)
+ if ( aLocale.Country != rLocale.Country
+ || aLocale.Language != rLocale.Language
+ || aLocale.Variant != rLocale.Variant )
{
- if ( item.first == rLocale )
- return item.second;
+ bFormatsValid = false;
+ aLocale = rLocale;
}
+}
- /* Not found; Get the FormatElement Sequence for the given Locale */
- css::uno::Sequence< css::i18n::FormatElement > aFormatElementSequence;
- if ( m_xLocaleData.is() )
- aFormatElementSequence = m_xLocaleData->getAllFormats( rLocale );
-
- /* Add the FormatElement Sequence to the cache */
- const int FORMATELEMENTCACHE_SIZE = 3;
- if ( m_aFormatElementCache.size() > FORMATELEMENTCACHE_SIZE )
- m_aFormatElementCache.pop_front();
- m_aFormatElementCache.emplace_back( rLocale, aFormatElementSequence );
- return m_aFormatElementCache.back().second;
+
+void NumberFormatCodeMapper::getFormats( const css::lang::Locale& rLocale )
+{
+ setupLocale( rLocale );
+ if ( !bFormatsValid )
+ {
+ createLocaleDataObject();
+ if( !mxLocaleData.is() )
+ aFormatSeq = css::uno::Sequence< css::i18n::FormatElement > (0);
+ else
+ aFormatSeq = mxLocaleData->getAllFormats( aLocale );
+ bFormatsValid = true;
+ }
}
@@ -244,6 +252,15 @@ NumberFormatCodeMapper::mapElementUsageStringToShort(const OUString& formatUsage
}
+void
+NumberFormatCodeMapper::createLocaleDataObject() {
+
+ if(mxLocaleData.is())
+ return;
+
+ mxLocaleData.set( css::i18n::LocaleData::create(mxContext) );
+}
+
OUString SAL_CALL
NumberFormatCodeMapper::getImplementationName()
throw( css::uno::RuntimeException, std::exception )