From babbd149aa9b2b5a28c55cb38fbbe24586bf8e22 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Thu, 4 Apr 2013 21:27:53 +0200 Subject: added the dreaded jolly joker Change-Id: I1bd840391496daab2cfe32af6ac00e98de3ed72e --- i18npool/inc/i18npool/lang.h | 1 + i18npool/inc/i18npool/languagetag.hxx | 6 ++++-- i18npool/qa/cppunit/test_languagetag.cxx | 20 ++++++++++++++++++++ i18npool/source/isolang/isolang.cxx | 1 + i18npool/source/isolang/mslangid.cxx | 9 +++++---- i18npool/source/languagetag/languagetag.cxx | 9 +++++++-- 6 files changed, 38 insertions(+), 8 deletions(-) (limited to 'i18npool') diff --git a/i18npool/inc/i18npool/lang.h b/i18npool/inc/i18npool/lang.h index e3643fc1cf15..81a6d87f74c9 100644 --- a/i18npool/inc/i18npool/lang.h +++ b/i18npool/inc/i18npool/lang.h @@ -555,6 +555,7 @@ typedef unsigned short LanguageType; #define LANGUAGE_USER_YOMBE_CONGO 0x8284 /* makeLangID( 0x20, getPrimaryLanguage( LANGUAGE_USER_YOMBE)) */ #define LANGUAGE_USER_SIDAMA 0x0685 +#define LANGUAGE_USER_PRIV_JOKER 0xFFEB /* privateuse "*" (sic! bad! nasty!), primary 0x3eb, sub 0x3f */ #define LANGUAGE_USER_PRIV_COMMENT 0xFFEC /* privateuse "x-comment", primary 0x3ec, sub 0x3f */ #define LANGUAGE_USER_PRIV_DEFAULT 0xFFED /* privateuse "x-default", primary 0x3ed, sub 0x3f */ #define LANGUAGE_USER_PRIV_NOTRANSLATE 0xFFEE /* privateuse "x-no-translate" (sic!), primary 0x3ee, sub 0x3f */ diff --git a/i18npool/inc/i18npool/languagetag.hxx b/i18npool/inc/i18npool/languagetag.hxx index 0bba7a1afbe3..c3d605571c90 100644 --- a/i18npool/inc/i18npool/languagetag.hxx +++ b/i18npool/inc/i18npool/languagetag.hxx @@ -376,7 +376,8 @@ private: { EXTRACTED_NONE, EXTRACTED_LSC, - EXTRACTED_X + EXTRACTED_X, + EXTRACTED_X_JOKER }; /** Of a simple language tag of the form lll[-Ssss][-CC] (i.e. one that @@ -385,7 +386,8 @@ private: Does not check case or content! @return EXTRACTED_LSC if simple tag was detected, EXTRACTED_X if x-... - privateuse tag was detected, else EXTRACTED_NONE. + privateuse tag was detected, EXTRACTED_X_JOKER if "*" joker was + detected, else EXTRACTED_NONE. */ static Extraction simpleExtract( const OUString& rBcp47, OUString& rLanguage, diff --git a/i18npool/qa/cppunit/test_languagetag.cxx b/i18npool/qa/cppunit/test_languagetag.cxx index 227be2068677..4e57b39a791a 100644 --- a/i18npool/qa/cppunit/test_languagetag.cxx +++ b/i18npool/qa/cppunit/test_languagetag.cxx @@ -232,6 +232,26 @@ void TestLanguageTag::testAllTags() CPPUNIT_ASSERT( xfoobar.getLanguageType() == LANGUAGE_SYSTEM ); } + // '*' the dreaded jolly joker is a "privateuse" known "locale" + { + OUString s_joker( "*" ); + LanguageTag joker( s_joker ); + lang::Locale aLocale = joker.getLocale(); + CPPUNIT_ASSERT( joker.getBcp47() == s_joker ); + CPPUNIT_ASSERT( aLocale.Language == "qlt" ); + CPPUNIT_ASSERT( aLocale.Country == "" ); + CPPUNIT_ASSERT( aLocale.Variant == "*" ); + CPPUNIT_ASSERT( joker.getLanguageType() == LANGUAGE_USER_PRIV_JOKER ); + + joker.reset( LANGUAGE_USER_PRIV_JOKER ); + aLocale = joker.getLocale(); + CPPUNIT_ASSERT( joker.getBcp47() == s_joker ); + CPPUNIT_ASSERT( aLocale.Language == "qlt" ); + CPPUNIT_ASSERT( aLocale.Country == "" ); + CPPUNIT_ASSERT( aLocale.Variant == "*" ); + CPPUNIT_ASSERT( joker.getLanguageType() == LANGUAGE_USER_PRIV_JOKER ); + } + // test reset() methods { LanguageTag aTag( LANGUAGE_DONTKNOW ); diff --git a/i18npool/source/isolang/isolang.cxx b/i18npool/source/isolang/isolang.cxx index e41d22892967..17a803343877 100644 --- a/i18npool/source/isolang/isolang.cxx +++ b/i18npool/source/isolang/isolang.cxx @@ -643,6 +643,7 @@ static IsoLangOtherEntry const aImplPrivateUseEntries[] = { LANGUAGE_USER_PRIV_NOTRANSLATE, "x-no-translate" }, //! not BCP47 but legacy in .xcu configmgr { LANGUAGE_USER_PRIV_DEFAULT, "x-default" }, { LANGUAGE_USER_PRIV_COMMENT, "x-comment" }, + { LANGUAGE_USER_PRIV_JOKER, "*" }, //! not BCP47 but transferable in configmgr { LANGUAGE_DONTKNOW, NULL } // marks end of table }; diff --git a/i18npool/source/isolang/mslangid.cxx b/i18npool/source/isolang/mslangid.cxx index 6afde6252c34..12cf5a3ad1da 100644 --- a/i18npool/source/isolang/mslangid.cxx +++ b/i18npool/source/isolang/mslangid.cxx @@ -149,8 +149,8 @@ void MsLangId::Conversion::convertLanguageToLocale( LanguageType nLang, rLocale.Variant = OUString(); convertLanguageToIsoNames( nLang, rLocale.Language, rLocale.Country); /* FIXME: this x-... is temporary until conversion will be moved up to - * LanguageTag */ - if (rLocale.Language.startsWith( "x-")) + * LanguageTag. Also handle the nasty "*" joker as privateuse. */ + if (rLocale.Language.startsWith( "x-") || (rLocale.Language == "*")) { rLocale.Variant = rLocale.Language; rLocale.Language = "qlt"; @@ -186,8 +186,9 @@ LanguageType MsLangId::Conversion::convertLocaleToLanguage( return LANGUAGE_SYSTEM; /* FIXME: this x-... is temporary until conversion will be moved up to - * LanguageTag */ - LanguageType nRet = ((!rLocale.Variant.isEmpty() && rLocale.Variant.startsWithIgnoreAsciiCase( "x-")) ? + * LanguageTag. Also handle the nasty "*" joker as privateuse. */ + LanguageType nRet = ((!rLocale.Variant.isEmpty() && + (rLocale.Variant.startsWithIgnoreAsciiCase( "x-") || (rLocale.Variant == "*"))) ? convertPrivateUseToLanguage( rLocale.Variant) : convertIsoNamesToLanguage( rLocale.Language, rLocale.Country)); if (nRet == LANGUAGE_DONTKNOW) diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx index 16b81d8427dc..c93943d52362 100644 --- a/i18npool/source/languagetag/languagetag.cxx +++ b/i18npool/source/languagetag/languagetag.cxx @@ -430,7 +430,7 @@ bool LanguageTag::canonicalize() // locale. OUString aLanguage, aScript, aCountry; Extraction eExt = simpleExtract( maBcp47, aLanguage, aScript, aCountry); - if (eExt == EXTRACTED_LSC || eExt == EXTRACTED_X) + if (eExt != EXTRACTED_NONE) { if (eExt == EXTRACTED_LSC && aScript.isEmpty()) { @@ -1160,7 +1160,12 @@ LanguageTag::Extraction LanguageTag::simpleExtract( const OUString& rBcp47, Extraction eRet = EXTRACTED_NONE; const sal_Int32 nLen = rBcp47.getLength(); const sal_Int32 nHyph1 = rBcp47.indexOf( '-'); - if (nHyph1 == 1 && rBcp47[0] == 'x') // x-... privateuse + if (nLen == 1 && rBcp47[0] == '*') // * the dreaded jolly joker + { + // It's f*d up but we need to recognize this. + eRet = EXTRACTED_X_JOKER; + } + else if (nHyph1 == 1 && rBcp47[0] == 'x') // x-... privateuse { // x-... privateuse tags MUST be known to us by definition. eRet = EXTRACTED_X; -- cgit