[Libreoffice-commits] .: i18npool/inc i18npool/qa i18npool/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Nov 16 05:34:11 PST 2012


 i18npool/inc/i18npool/languagetag.hxx       |   12 +++++
 i18npool/qa/cppunit/test_languagetag.cxx    |   30 ++++++++++++++
 i18npool/source/languagetag/languagetag.cxx |   58 ++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+)

New commits:
commit 2eb9470c14b665f69c87035fe33a71860fcf2600
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Nov 16 14:33:12 2012 +0100

    added LanguageTag::reset() methods
    
    Change-Id: Id78a989ab981d658dd8f331b030e00ce201c8bc9

diff --git a/i18npool/inc/i18npool/languagetag.hxx b/i18npool/inc/i18npool/languagetag.hxx
index aaf4ca3..5666fd1 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 3bb7163..deaeecd 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 ad8b9c1..3e655ee 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


More information about the Libreoffice-commits mailing list