Kaydet (Commit) 0d0c51d1 authored tarafından Eike Rathke's avatar Eike Rathke

return const reference for getBcp47() and getLocale()

And use the rtl::Static pattern for statics.

Change-Id: I80d8cc0a4a35771f86bec27edf41224d71cdea14
üst 3dab6fba
......@@ -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.
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment