diff options
author | Eike Rathke <erack@redhat.com> | 2014-06-03 14:17:17 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2014-06-03 14:48:45 +0200 |
commit | fecde4c7099fdb7c5ee396b0f68ec517f3a08955 (patch) | |
tree | 8d60af84c27de0ec4972fa4c8b6c5e9aa1c81376 | |
parent | 59371dfca363601b051ebd289d695ca040a97531 (diff) |
add bDisallowPrivate parameter to LanguageTag::isValidBcp47()
Change-Id: I0924b0fa268c38c238226d082cf26595bba72f0c
-rw-r--r-- | i18nlangtag/source/languagetag/languagetag.cxx | 15 | ||||
-rw-r--r-- | include/i18nlangtag/languagetag.hxx | 8 |
2 files changed, 19 insertions, 4 deletions
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx index 483cf98af7da..237fdcadfa7a 100644 --- a/i18nlangtag/source/languagetag/languagetag.cxx +++ b/i18nlangtag/source/languagetag/languagetag.cxx @@ -2691,8 +2691,10 @@ com::sun::star::lang::Locale LanguageTag::convertToLocaleWithFallback( const OUS // static -bool LanguageTag::isValidBcp47( const OUString& rString, OUString* o_pCanonicalized ) +bool LanguageTag::isValidBcp47( const OUString& rString, OUString* o_pCanonicalized, bool bDisallowPrivate ) { + bool bValid = false; + struct guard { lt_tag_t* mpLangtag; @@ -2716,17 +2718,24 @@ bool LanguageTag::isValidBcp47( const OUString& rString, OUString* o_pCanonicali SAL_WARN_IF( !pTag, "i18nlangtag", "LanguageTag:isValidBcp47: could not canonicalize '" << rString << "'"); if (pTag) { + bValid = true; + if (bDisallowPrivate) + { + const lt_string_t* pPrivate = lt_tag_get_privateuse( aVar.mpLangtag); + if (pPrivate && lt_string_length( pPrivate) > 0) + bValid = false; + } if (o_pCanonicalized) *o_pCanonicalized = OUString::createFromAscii( pTag); free( pTag); - return true; + return bValid; } } else { SAL_INFO( "i18nlangtag", "LanguageTag:isValidBcp47: could not parse '" << rString << "'"); } - return false; + return bValid; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/i18nlangtag/languagetag.hxx b/include/i18nlangtag/languagetag.hxx index 0e12235c34ba..f3cf64293cd9 100644 --- a/include/i18nlangtag/languagetag.hxx +++ b/include/i18nlangtag/languagetag.hxx @@ -492,8 +492,14 @@ public: canonicalized form is assigned, which may differ from the original string even if that was a valid tag. If rString is not a valid tag, nothing is assigned. + + @param bDisallowPrivate + If TRUE, valid tags according to BCP 47 but reserved for + private use, like 'x-...', are not allowed and FALSE is + returned in this case. */ - static bool isValidBcp47( const OUString& rString, OUString* o_pCanonicalized = NULL ); + static bool isValidBcp47( const OUString& rString, OUString* o_pCanonicalized = NULL, + bool bDisallowPrivate = false ); /** If nLang is a generated on-the-fly LangID */ static bool isOnTheFlyID( LanguageType nLang ); |