summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2012-11-16 12:07:53 +0100
committerEike Rathke <erack@redhat.com>2012-11-16 12:10:24 +0100
commit0d0c51d155dfc6a51a5da3c4d61ab6f40c5e0e5f (patch)
tree278a986064ce06443481d6a5ea94c5cd961bce42 /i18npool
parent3dab6fba4a53c12da0fc886cca61b9a89a311a4e (diff)
return const reference for getBcp47() and getLocale()
And use the rtl::Static pattern for statics. Change-Id: I80d8cc0a4a35771f86bec27edf41224d71cdea14
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/inc/i18npool/languagetag.hxx4
-rw-r--r--i18npool/source/languagetag/languagetag.cxx32
2 files changed, 23 insertions, 13 deletions
diff --git a/i18npool/inc/i18npool/languagetag.hxx b/i18npool/inc/i18npool/languagetag.hxx
index abc7ed1bf17c..aaf4ca3769de 100644
--- a/i18npool/inc/i18npool/languagetag.hxx
+++ b/i18npool/inc/i18npool/languagetag.hxx
@@ -68,7 +68,7 @@ public:
locale to the real locale used.
If FALSE, return an empty OUString for such a tag.
*/
- rtl::OUString getBcp47( bool bResolveSystem = true ) const;
+ const rtl::OUString & getBcp47( bool bResolveSystem = true ) const;
/** Obtain language tag as Locale.
@@ -84,7 +84,7 @@ public:
locale to the real locale used.
If FALSE, return an empty Locale for such a tag.
*/
- com::sun::star::lang::Locale getLocale( bool bResolveSystem = true ) const;
+ const com::sun::star::lang::Locale & getLocale( bool bResolveSystem = true ) const;
/** Obtain mapping to MS-LangID.
diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx
index 2b3dbc404a9c..ad8b9c138dd8 100644
--- a/i18npool/source/languagetag/languagetag.cxx
+++ b/i18npool/source/languagetag/languagetag.cxx
@@ -12,6 +12,7 @@
#include <rtl/ustrbuf.hxx>
#include <rtl/bootstrap.hxx>
#include <osl/file.hxx>
+#include <rtl/instance.hxx>
//#define erDEBUG
@@ -42,6 +43,13 @@ using namespace com::sun::star;
#define ISO639_LANGUAGE_TAG "qlt"
+// "statics" to be returned as const reference to an empty locale and string.
+namespace {
+struct theEmptyLocale : public rtl::Static< lang::Locale, theEmptyLocale > {};
+struct theEmptyBcp47 : public rtl::Static< OUString, theEmptyBcp47 > {};
+}
+
+
/** A reference holder for liblangtag data de/initialization, one static
instance. Currently implemented such that the first "ref" inits and dtor
(our library deinitialized) tears down.
@@ -71,7 +79,9 @@ private:
void teardown();
};
-static LiblantagDataRef theDataRef;
+namespace {
+struct theDataRef : public rtl::Static< LiblantagDataRef, theDataRef > {};
+}
LiblantagDataRef::LiblantagDataRef()
:
@@ -154,7 +164,7 @@ LanguageTag::LanguageTag( const rtl::OUString & rBcp47LanguageTag, bool bCanonic
mbCachedScript( false),
mbCachedCountry( false)
{
- theDataRef.incRef();
+ theDataRef::get().incRef();
if (bCanonicalize)
canonicalize();
@@ -177,7 +187,7 @@ LanguageTag::LanguageTag( const com::sun::star::lang::Locale & rLocale )
mbCachedScript( false),
mbCachedCountry( false)
{
- theDataRef.incRef();
+ theDataRef::get().incRef();
}
@@ -196,7 +206,7 @@ LanguageTag::LanguageTag( LanguageType nLanguage )
mbCachedScript( false),
mbCachedCountry( false)
{
- theDataRef.incRef();
+ theDataRef::get().incRef();
}
@@ -216,7 +226,7 @@ LanguageTag::LanguageTag( const rtl::OUString& rLanguage, const rtl::OUString& r
mbCachedScript( false),
mbCachedCountry( false)
{
- theDataRef.incRef();
+ theDataRef::get().incRef();
}
@@ -241,7 +251,7 @@ LanguageTag::LanguageTag( const LanguageTag & rLanguageTag )
mbCachedScript( rLanguageTag.mbCachedScript),
mbCachedCountry( rLanguageTag.mbCachedCountry)
{
- theDataRef.incRef();
+ theDataRef::get().incRef();
}
@@ -274,7 +284,7 @@ LanguageTag::~LanguageTag()
{
lt_tag_unref( MPLANGTAG);
- theDataRef.decRef();
+ theDataRef::get().decRef();
}
@@ -448,10 +458,10 @@ void LanguageTag::convertLangToBcp47()
}
-rtl::OUString LanguageTag::getBcp47( bool bResolveSystem ) const
+const rtl::OUString & LanguageTag::getBcp47( bool bResolveSystem ) const
{
if (!bResolveSystem && mbSystemLocale)
- return OUString();
+ return theEmptyBcp47::get();
if (!mbInitializedBcp47)
{
if (mbInitializedLocale)
@@ -520,10 +530,10 @@ rtl::OUString LanguageTag::getRegionFromLangtag() const
}
-com::sun::star::lang::Locale LanguageTag::getLocale( bool bResolveSystem ) const
+const com::sun::star::lang::Locale & LanguageTag::getLocale( bool bResolveSystem ) const
{
if (!bResolveSystem && mbSystemLocale)
- return lang::Locale();
+ return theEmptyLocale::get();
if (!mbInitializedLocale)
{
if (mbInitializedBcp47)