summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2012-11-16 14:33:12 +0100
committerEike Rathke <erack@redhat.com>2012-11-16 14:33:46 +0100
commit2eb9470c14b665f69c87035fe33a71860fcf2600 (patch)
tree2a89851f94d85a7f8a99c8ab5ef566fc94c683bd /i18npool
parent6527f30e24e889810c9a895508dec0c9e6309076 (diff)
added LanguageTag::reset() methods
Change-Id: Id78a989ab981d658dd8f331b030e00ce201c8bc9
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/inc/i18npool/languagetag.hxx12
-rw-r--r--i18npool/qa/cppunit/test_languagetag.cxx30
-rw-r--r--i18npool/source/languagetag/languagetag.cxx58
3 files changed, 100 insertions, 0 deletions
diff --git a/i18npool/inc/i18npool/languagetag.hxx b/i18npool/inc/i18npool/languagetag.hxx
index aaf4ca3769de..5666fd158600 100644
--- a/i18npool/inc/i18npool/languagetag.hxx
+++ b/i18npool/inc/i18npool/languagetag.hxx
@@ -162,6 +162,16 @@ public:
*/
bool isSystemLocale() const;
+
+ /** Reset with existing BCP 47 language tag string. See ctor. */
+ void reset( const rtl::OUString & rBcp47LanguageTag, bool bCanonicalize = false );
+
+ /** Reset with Locale. */
+ void reset( const com::sun::star::lang::Locale & rLocale );
+
+ /** Reset with LanguageType MS-LangID. */
+ void reset( LanguageType nLanguage );
+
private:
enum Decision
@@ -202,6 +212,8 @@ private:
rtl::OUString getScriptFromLangtag() const;
rtl::OUString getRegionFromLangtag() const;
+ void resetVars();
+
static bool isIsoLanguage( const rtl::OUString& rLanguage );
static bool isIsoScript( const rtl::OUString& rScript );
static bool isIsoCountry( const rtl::OUString& rRegion );
diff --git a/i18npool/qa/cppunit/test_languagetag.cxx b/i18npool/qa/cppunit/test_languagetag.cxx
index 3bb71630d40b..deaeecd92768 100644
--- a/i18npool/qa/cppunit/test_languagetag.cxx
+++ b/i18npool/qa/cppunit/test_languagetag.cxx
@@ -165,6 +165,36 @@ void TestLanguageTag::testAllTags()
CPPUNIT_ASSERT( de_DE.getLanguageType() == LANGUAGE_GERMAN );
}
+ // test reset() methods
+ {
+ LanguageTag aTag( LANGUAGE_DONTKNOW );
+ lang::Locale aLocale;
+
+ aTag.reset( LANGUAGE_GERMAN );
+ aLocale = aTag.getLocale();
+ CPPUNIT_ASSERT( aTag.getBcp47() == "de-DE" );
+ CPPUNIT_ASSERT( aLocale.Language == "de" );
+ CPPUNIT_ASSERT( aLocale.Country == "DE" );
+ CPPUNIT_ASSERT( aLocale.Variant == "" );
+ CPPUNIT_ASSERT( aTag.getLanguageType() == LANGUAGE_GERMAN );
+
+ aTag.reset( "en-US" );
+ aLocale = aTag.getLocale();
+ CPPUNIT_ASSERT( aTag.getBcp47() == "en-US" );
+ CPPUNIT_ASSERT( aLocale.Language == "en" );
+ CPPUNIT_ASSERT( aLocale.Country == "US" );
+ CPPUNIT_ASSERT( aLocale.Variant == "" );
+ CPPUNIT_ASSERT( aTag.getLanguageType() == LANGUAGE_ENGLISH_US );
+
+ aTag.reset( lang::Locale( "de", "DE", "" ) );
+ aLocale = aTag.getLocale();
+ CPPUNIT_ASSERT( aTag.getBcp47() == "de-DE" );
+ CPPUNIT_ASSERT( aLocale.Language == "de" );
+ CPPUNIT_ASSERT( aLocale.Country == "DE" );
+ CPPUNIT_ASSERT( aLocale.Variant == "" );
+ CPPUNIT_ASSERT( aTag.getLanguageType() == LANGUAGE_GERMAN );
+ }
+
{
OUString s_uab( "unreg-and-bad" );
LanguageTag uab( s_uab, true );
diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx
index ad8b9c138dd8..3e655ee87bb3 100644
--- a/i18npool/source/languagetag/languagetag.cxx
+++ b/i18npool/source/languagetag/languagetag.cxx
@@ -288,6 +288,64 @@ LanguageTag::~LanguageTag()
}
+void LanguageTag::resetVars()
+{
+ lt_tag_unref( MPLANGTAG);
+ mpImplLangtag = NULL;
+
+ maLocale = lang::Locale();
+ if (!maBcp47.isEmpty())
+ maBcp47 = OUString();
+ if (!maCachedLanguage.isEmpty())
+ maCachedLanguage= OUString();
+ if (!maCachedScript.isEmpty())
+ maCachedScript = OUString();
+ if (!maCachedCountry.isEmpty())
+ maCachedCountry = OUString();
+ mnLangID = LANGUAGE_DONTKNOW;
+ meIsValid = DECISION_DONTKNOW;
+ meIsIsoLocale = DECISION_DONTKNOW;
+ meIsIsoODF = DECISION_DONTKNOW;
+ mbSystemLocale = true;
+ mbInitializedBcp47 = false;
+ mbInitializedLocale = false;
+ mbInitializedLangID = false;
+ mbCachedLanguage = false;
+ mbCachedScript = false;
+ mbCachedCountry = false;
+}
+
+
+void LanguageTag::reset( const rtl::OUString & rBcp47LanguageTag, bool bCanonicalize )
+{
+ resetVars();
+ maBcp47 = rBcp47LanguageTag;
+ mbSystemLocale = rBcp47LanguageTag.isEmpty();
+ mbInitializedBcp47 = !mbSystemLocale;
+
+ if (bCanonicalize)
+ canonicalize();
+}
+
+
+void LanguageTag::reset( const com::sun::star::lang::Locale & rLocale )
+{
+ resetVars();
+ maLocale = rLocale;
+ mbSystemLocale = rLocale.Language.isEmpty();
+ mbInitializedLocale = !mbSystemLocale;
+}
+
+
+void LanguageTag::reset( LanguageType nLanguage )
+{
+ resetVars();
+ mnLangID = nLanguage;
+ mbSystemLocale = nLanguage == LANGUAGE_SYSTEM;
+ mbInitializedLangID = !mbSystemLocale;
+}
+
+
bool LanguageTag::canonicalize() const
{
#ifdef erDEBUG