summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2013-03-27 20:23:08 +0100
committerEike Rathke <erack@redhat.com>2013-03-27 20:38:19 +0100
commitd35ed10d1d75c6ce3a850e844a931b95c12cd127 (patch)
treeedddaeeed5608df8ff96c5f7874c88e9826a226b /i18npool
parent46f47a6ec28dda0436b9c4fb54628a6e2e191285 (diff)
handle x-... privateuse
Change-Id: I9ff44e7f3d3fd8fccc5b7134c18184040f797826
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/inc/i18npool/languagetag.hxx18
-rw-r--r--i18npool/source/languagetag/languagetag.cxx32
2 files changed, 31 insertions, 19 deletions
diff --git a/i18npool/inc/i18npool/languagetag.hxx b/i18npool/inc/i18npool/languagetag.hxx
index 5b88542b7b71..4d99e72d193f 100644
--- a/i18npool/inc/i18npool/languagetag.hxx
+++ b/i18npool/inc/i18npool/languagetag.hxx
@@ -319,17 +319,25 @@ private:
static bool isIsoScript( const OUString& rScript );
static bool isIsoCountry( const OUString& rRegion );
+ enum Extraction
+ {
+ EXTRACTED_NONE,
+ EXTRACTED_LSC,
+ EXTRACTED_X
+ };
+
/** Of a simple language tag of the form lll[-Ssss][-CC] (i.e. one that
would fulfill the isIsoODF() condition) extract the portions.
Does not check case or content!
- @return TRUE if it detected a simple tag, else FALSE.
+ @return EXTRACTED_LSC if simple tag was detected, EXTRACTED_X if x-...
+ privateuse tag was detected, else EXTRACTED_NONE.
*/
- static bool simpleExtract( const OUString& rBcp47,
- OUString& rLanguage,
- OUString& rScript,
- OUString& rCountry );
+ static Extraction simpleExtract( const OUString& rBcp47,
+ OUString& rLanguage,
+ OUString& rScript,
+ OUString& rCountry );
};
#endif // INCLUDED_I18NPOOL_LANGUAGETAG_HXX
diff --git a/i18npool/source/languagetag/languagetag.cxx b/i18npool/source/languagetag/languagetag.cxx
index e43bfe379ce2..7b284b5a4a8c 100644
--- a/i18npool/source/languagetag/languagetag.cxx
+++ b/i18npool/source/languagetag/languagetag.cxx
@@ -429,9 +429,10 @@ bool LanguageTag::canonicalize()
// without using liblangtag just to see if it is a simple known
// locale.
OUString aLanguage, aScript, aCountry;
- if (simpleExtract( maBcp47, aLanguage, aScript, aCountry))
+ Extraction eExt = simpleExtract( maBcp47, aLanguage, aScript, aCountry);
+ if (eExt == EXTRACTED_LSC || eExt == EXTRACTED_X)
{
- if (aScript.isEmpty())
+ if (eExt == EXTRACTED_LSC && aScript.isEmpty())
{
maLocale.Language = aLanguage;
maLocale.Country = aCountry;
@@ -960,7 +961,7 @@ bool LanguageTag::hasScript() const
bool LanguageTag::cacheSimpleLSC()
{
OUString aLanguage, aScript, aCountry;
- bool bRet = simpleExtract( maBcp47, aLanguage, aScript, aCountry);
+ bool bRet = (simpleExtract( maBcp47, aLanguage, aScript, aCountry) == EXTRACTED_LSC);
if (bRet)
{
maCachedLanguage = aLanguage;
@@ -1115,19 +1116,22 @@ bool LanguageTag::operator!=( const LanguageTag & rLanguageTag ) const
// static
-bool LanguageTag::simpleExtract( const OUString& rBcp47,
- OUString& rLanguage,
- OUString& rScript,
- OUString& rCountry )
+LanguageTag::Extraction LanguageTag::simpleExtract( const OUString& rBcp47,
+ OUString& rLanguage, OUString& rScript, OUString& rCountry )
{
- bool bRet = false;
+ Extraction eRet = EXTRACTED_NONE;
const sal_Int32 nLen = rBcp47.getLength();
const sal_Int32 nHyph1 = rBcp47.indexOf( '-');
- if ((nLen == 2 || nLen == 3) && nHyph1 < 0) // ll or lll
+ if (nHyph1 == 1 && rBcp47[0] == 'x') // x-... privateuse
+ {
+ // x-... privateuse tags MUST be known to us by definition.
+ eRet = EXTRACTED_X;
+ }
+ else if ((nLen == 2 || nLen == 3) && nHyph1 < 0) // ll or lll
{
rLanguage = rBcp47;
rScript = rCountry = OUString();
- bRet = true;
+ eRet = EXTRACTED_LSC;
}
else if ( (nLen == 5 && nHyph1 == 2) // ll-CC
|| (nLen == 6 && nHyph1 == 3)) // lll-CC
@@ -1135,7 +1139,7 @@ bool LanguageTag::simpleExtract( const OUString& rBcp47,
rLanguage = rBcp47.copy( 0, nHyph1);
rCountry = rBcp47.copy( nHyph1 + 1, 2);
rScript = OUString();
- bRet = true;
+ eRet = EXTRACTED_LSC;
}
else if ( (nHyph1 == 2 && nLen == 10) // ll-Ssss-CC check
|| (nHyph1 == 3 && nLen == 11)) // lll-Ssss-CC check
@@ -1146,12 +1150,12 @@ bool LanguageTag::simpleExtract( const OUString& rBcp47,
rLanguage = rBcp47.copy( 0, nHyph1);
rScript = rBcp47.copy( nHyph1 + 1, 4);
rCountry = rBcp47.copy( nHyph2 + 1, 2);
- bRet = true;
+ eRet = EXTRACTED_LSC;
}
}
- if (!bRet)
+ if (eRet == EXTRACTED_NONE)
rLanguage = rScript = rCountry = OUString();
- return bRet;
+ return eRet;
}