Kaydet (Commit) fecde4c7 authored tarafından Eike Rathke's avatar Eike Rathke

add bDisallowPrivate parameter to LanguageTag::isValidBcp47()

Change-Id: I0924b0fa268c38c238226d082cf26595bba72f0c
üst 59371dfc
...@@ -2691,8 +2691,10 @@ com::sun::star::lang::Locale LanguageTag::convertToLocaleWithFallback( const OUS ...@@ -2691,8 +2691,10 @@ com::sun::star::lang::Locale LanguageTag::convertToLocaleWithFallback( const OUS
// static // 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 struct guard
{ {
lt_tag_t* mpLangtag; lt_tag_t* mpLangtag;
...@@ -2716,17 +2718,24 @@ bool LanguageTag::isValidBcp47( const OUString& rString, OUString* o_pCanonicali ...@@ -2716,17 +2718,24 @@ bool LanguageTag::isValidBcp47( const OUString& rString, OUString* o_pCanonicali
SAL_WARN_IF( !pTag, "i18nlangtag", "LanguageTag:isValidBcp47: could not canonicalize '" << rString << "'"); SAL_WARN_IF( !pTag, "i18nlangtag", "LanguageTag:isValidBcp47: could not canonicalize '" << rString << "'");
if (pTag) 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) if (o_pCanonicalized)
*o_pCanonicalized = OUString::createFromAscii( pTag); *o_pCanonicalized = OUString::createFromAscii( pTag);
free( pTag); free( pTag);
return true; return bValid;
} }
} }
else else
{ {
SAL_INFO( "i18nlangtag", "LanguageTag:isValidBcp47: could not parse '" << rString << "'"); SAL_INFO( "i18nlangtag", "LanguageTag:isValidBcp47: could not parse '" << rString << "'");
} }
return false; return bValid;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -492,8 +492,14 @@ public: ...@@ -492,8 +492,14 @@ public:
canonicalized form is assigned, which may differ from the canonicalized form is assigned, which may differ from the
original string even if that was a valid tag. If rString is not original string even if that was a valid tag. If rString is not
a valid tag, nothing is assigned. 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 */ /** If nLang is a generated on-the-fly LangID */
static bool isOnTheFlyID( LanguageType nLang ); static bool isOnTheFlyID( LanguageType nLang );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment