[Libreoffice-commits] core.git: i18npool/source

Eike Rathke erack at redhat.com
Mon Feb 18 14:23:29 PST 2013


 i18npool/source/languagetag/languagetag.cxx |   48 +++++++++++++++++++++++-----
 1 file changed, 41 insertions(+), 7 deletions(-)

New commits:
commit 6c89f2e74aa9b202d6d6a41a178ba9aadb2b10e4
Author: Eike Rathke <erack at redhat.com>
Date:   Mon Feb 18 23:22:17 2013 +0100

    prepare LanguageTag(rtl_Locale) for handling variant/modifier
    
    Change-Id: Ic500bb2eecd090d5568703740c3700c6d50635ae

diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx
index 33b2c57..8494735 100644
--- a/i18npool/source/languagetag/languagetag.cxx
+++ b/i18npool/source/languagetag/languagetag.cxx
@@ -44,6 +44,15 @@ using namespace com::sun::star;
 #define ISO639_LANGUAGE_TAG "qlt"
 
 
+// Helper to ensure lt_error_t is free'd
+struct myLtError
+{
+    lt_error_t* p;
+    myLtError() : p(NULL) {}
+    ~myLtError() { if (p) lt_error_unref( p); }
+};
+
+
 // "statics" to be returned as const reference to an empty locale and string.
 namespace {
 struct theEmptyLocale : public rtl::Static< lang::Locale, theEmptyLocale > {};
@@ -239,6 +248,37 @@ LanguageTag::LanguageTag( const rtl_Locale & rLocale )
         mbCachedCountry( false),
         mbIsFallback( false)
 {
+    // The rtl_Locale follows the Open Group Base Specification,
+    // 8.2 Internationalization Variables
+    // language[_territory][.codeset][@modifier]
+    // On GNU/Linux systems usually being glibc locales.
+    // sal/osl/unx/nlsupport.c _parse_locale() parses them into
+    // Language: language               2 or 3 alpha code
+    // Country: [territory]             2 alpha code
+    // Variant: [.codeset][@modifier]
+    // Variant effectively contains anything that follows the territory, not
+    // looking for '.' dot delimiter or '@' modifier content.
+    if (!maLocale.Variant.isEmpty())
+    {
+        /* FIXME: let liblangtag parse this entirely with
+         * lt_tag_convert_from_locale() but that needs a patch to pass the
+         * string. */
+#if 0
+        OString aStr = OUStringToOString( maLocale.Language + "-" + maLocale.Country + maLocale.Variant,
+                RTL_TEXTENCODING_UTF8);
+        myLtError aError;
+        theDataRef::get().incRef();
+        mpImplLangtag = lt_tag_convert_from_locale( aStr.getStr(), &aError.p);
+        maBcp47 = OStringToOUString( lt_tag_get_string( MPLANGTAG), RTL_TEXTENCODING_UTF8);
+        mbInitializedBcp47 = true;
+        maLocale = lang::Locale();
+        mbInitializedLocale = false;
+#else
+        SAL_WARN( "i18npool.langtag", "rtl_Locale Variant modifier not handled");
+        // For now clear anything unknown to us.
+        maLocale.Variant = OUString();
+#endif
+    }
 }
 
 
@@ -480,13 +520,7 @@ bool LanguageTag::canonicalize()
         mpImplLangtag = lt_tag_new();
     }
 
-    // ensure error is free'd
-    struct myerror
-    {
-        lt_error_t* p;
-        myerror() : p(NULL) {}
-        ~myerror() { if (p) lt_error_unref( p); }
-    } aError;
+    myLtError aError;
 
     if (lt_tag_parse( MPLANGTAG, OUStringToOString( maBcp47, RTL_TEXTENCODING_UTF8).getStr(), &aError.p))
     {


More information about the Libreoffice-commits mailing list