[Libreoffice-commits] core.git: 2 commits - i18nlangtag/qa i18nlangtag/source

Eike Rathke erack at redhat.com
Thu Sep 19 04:08:52 PDT 2013


 i18nlangtag/qa/cppunit/test_languagetag.cxx    |   20 ++++++++++++++++-
 i18nlangtag/source/languagetag/languagetag.cxx |   28 +++++++++++++++++--------
 2 files changed, 39 insertions(+), 9 deletions(-)

New commits:
commit 99899543ee59b9753bfbcea565fd678b5f4f7f0f
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Sep 19 13:07:09 2013 +0200

    accept (DIGIT 3*ALNUM) variant in place of (4*ALPHA) script
    
    Change-Id: If622619bd2e282ab8298ac8a29f8bb57a8fe968f

diff --git a/i18nlangtag/qa/cppunit/test_languagetag.cxx b/i18nlangtag/qa/cppunit/test_languagetag.cxx
index 9f7c797..079973e 100644
--- a/i18nlangtag/qa/cppunit/test_languagetag.cxx
+++ b/i18nlangtag/qa/cppunit/test_languagetag.cxx
@@ -318,6 +318,24 @@ void TestLanguageTag::testAllTags()
         CPPUNIT_ASSERT( de_DE.getLanguageType() == LANGUAGE_GERMAN );
     }
 
+    // 'de-1901' derived from 'de-DE-1901' grandfathered to check that it is
+    // accepted as (DIGIT 3*ALNUM) variant
+    {
+        OUString s_de_1901( "de-1901" );
+        LanguageTag de_1901( s_de_1901 );
+        lang::Locale aLocale = de_1901.getLocale();
+        CPPUNIT_ASSERT( de_1901.getBcp47() == s_de_1901 );
+        CPPUNIT_ASSERT( aLocale.Language == "qlt" );
+        CPPUNIT_ASSERT( aLocale.Country == "" );
+        CPPUNIT_ASSERT( aLocale.Variant == s_de_1901 );
+        CPPUNIT_ASSERT( de_1901.getLanguageType() == LANGUAGE_SYSTEM );
+        CPPUNIT_ASSERT( de_1901.isValidBcp47() == true );
+        CPPUNIT_ASSERT( de_1901.isIsoLocale() == false );
+        CPPUNIT_ASSERT( de_1901.isIsoODF() == false );
+        CPPUNIT_ASSERT( de_1901.getLanguageAndScript() == "de" );
+        CPPUNIT_ASSERT( de_1901.getVariants() == "1901" );
+    }
+
     // 'en-GB-oed' is known grandfathered for English, Oxford English
     // Dictionary spelling
     {
@@ -327,7 +345,7 @@ void TestLanguageTag::testAllTags()
         CPPUNIT_ASSERT( en_GB_oed.getBcp47() == s_en_GB_oed );
         CPPUNIT_ASSERT( aLocale.Language == "qlt" );
         CPPUNIT_ASSERT( aLocale.Country == "GB" );  // only 'GB' because we handle it, liblangtag would not fill this
-        CPPUNIT_ASSERT( aLocale.Variant == "en-GB-oed" );
+        CPPUNIT_ASSERT( aLocale.Variant == s_en_GB_oed );
         CPPUNIT_ASSERT( en_GB_oed.getLanguageType() == LANGUAGE_USER_ENGLISH_UK_OED );
         CPPUNIT_ASSERT( en_GB_oed.isValidBcp47() == true );
         CPPUNIT_ASSERT( en_GB_oed.isIsoLocale() == false );
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 20d542b..3aad527 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -1789,16 +1789,28 @@ LanguageTagImpl::Extraction LanguageTagImpl::simpleExtract( const OUString& rBcp
             eRet = EXTRACTED_LSC;
         }
     }
-    else if (  (nHyph1 == 2 && nLen ==  7)          // ll-Ssss
-            || (nHyph1 == 3 && nLen ==  8))         // lll-Ssss
+    else if (  (nHyph1 == 2 && nLen ==  7)          // ll-Ssss or ll-vvvv
+            || (nHyph1 == 3 && nLen ==  8))         // lll-Ssss or lll-vvvv
     {
-        /* TODO: also accept a (DIGIT 3*ALNUM) vvvv variant instead of Ssss */
         if (nHyph2 < 0)
         {
-            rLanguage = rBcp47.copy( 0, nHyph1).toAsciiLowerCase();
-            rScript   = rBcp47.copy( nHyph1 + 1, 1).toAsciiUpperCase() + rBcp47.copy( nHyph1 + 2, 3).toAsciiLowerCase();
-            rCountry  = rVariants = OUString();
-            eRet = EXTRACTED_LSC;
+            sal_Unicode c = rBcp47[nHyph1+1];
+            if ('0' <= c && c <= '9')
+            {
+                // (DIGIT 3*ALNUM) vvvv variant instead of Ssss script
+                rLanguage = rBcp47.copy( 0, nHyph1).toAsciiLowerCase();
+                rScript   = rCountry = OUString();
+                rVariants = rBcp47.copy( nHyph1 + 1);
+                eRet = EXTRACTED_LV;
+            }
+            else
+            {
+                rLanguage = rBcp47.copy( 0, nHyph1).toAsciiLowerCase();
+                rScript   = rBcp47.copy( nHyph1 + 1, 1).toAsciiUpperCase() +
+                            rBcp47.copy( nHyph1 + 2, 3).toAsciiLowerCase();
+                rCountry  = rVariants = OUString();
+                eRet = EXTRACTED_LSC;
+            }
         }
     }
     else if (  (nHyph1 == 2 && nHyph2 == 7 && nLen == 10)   // ll-Ssss-CC
commit 1eccc6dedf5710cf3009c15fcbe1b44a8dd393fb
Author: Eike Rathke <erack at redhat.com>
Date:   Thu Sep 19 12:43:55 2013 +0200

    use equalsIgnoreAsciiCaseAscii() with ASCII string
    
    ... instead of equalsIgnoreAsciiCase() that converts to OUString first
    
    Change-Id: I20e6ac93e1af40b01285e49670770d0e4c453dfa

diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 7f70186..20d542b 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -1858,7 +1858,7 @@ LanguageTagImpl::Extraction LanguageTagImpl::simpleExtract( const OUString& rBcp
             // Known and handled grandfathered; ugly but effective ...
             // Note that nLen must have matched above.
             // Strictly not a variant, but so far we treat it as such.
-            if (rBcp47.equalsIgnoreAsciiCase( "en-GB-oed"))
+            if (rBcp47.equalsIgnoreAsciiCaseAscii( "en-GB-oed"))
             {
                 rLanguage = "en";
                 rScript   = OUString();


More information about the Libreoffice-commits mailing list