[Libreoffice-commits] core.git: 4 commits - i18nlangtag/qa i18nlangtag/source include/i18nlangtag svx/source
Eike Rathke
erack at redhat.com
Tue Jun 3 05:49:20 PDT 2014
i18nlangtag/qa/cppunit/test_languagetag.cxx | 4 +++
i18nlangtag/source/languagetag/languagetag.cxx | 15 +++++++++++--
i18nlangtag/source/languagetag/simple-langtag.cxx | 24 ++++++++++++++++++++++
include/i18nlangtag/languagetag.hxx | 8 ++++++-
svx/source/dialog/langbox.cxx | 2 -
5 files changed, 48 insertions(+), 5 deletions(-)
New commits:
commit a8c5adabb98d4152527b553f904c1841c7393748
Author: Eike Rathke <erack at redhat.com>
Date: Tue Jun 3 14:47:47 2014 +0200
disallow private use language tags in combo box edit
Change-Id: I75f0b93507d31a12b07e4bb7d2c86671aa074486
diff --git a/svx/source/dialog/langbox.cxx b/svx/source/dialog/langbox.cxx
index 194a0d8..de8c251 100644
--- a/svx/source/dialog/langbox.cxx
+++ b/svx/source/dialog/langbox.cxx
@@ -736,7 +736,7 @@ IMPL_LINK( SvxLanguageComboBox, EditModifyHdl, SvxLanguageComboBox*, /*pEd*/ )
else
{
OUString aCanonicalized;
- bool bValid = LanguageTag::isValidBcp47( aStr, &aCanonicalized);
+ bool bValid = LanguageTag::isValidBcp47( aStr, &aCanonicalized, true);
meEditedAndValid = (bValid ? EDITED_VALID : EDITED_INVALID);
if (bValid && aCanonicalized != aStr)
{
commit 4516b18f9a2e9c1bbbf013ccaedf0a526ba69dea
Author: Eike Rathke <erack at redhat.com>
Date: Tue Jun 3 14:43:27 2014 +0200
and some replacement code for lt_tag_get_privateuse(), sigh..
Change-Id: Ida5064f32a16269b16ec16c0ce9f42ea895641f9
diff --git a/i18nlangtag/source/languagetag/simple-langtag.cxx b/i18nlangtag/source/languagetag/simple-langtag.cxx
index 7693c3a..8afa42d 100644
--- a/i18nlangtag/source/languagetag/simple-langtag.cxx
+++ b/i18nlangtag/source/languagetag/simple-langtag.cxx
@@ -141,6 +141,12 @@ struct lt_variant_t : public my_t_impl
virtual ~lt_variant_t() {}
};
+struct lt_string_t : public my_t_impl
+{
+ explicit lt_string_t() : my_t_impl() {}
+ virtual ~lt_string_t() {}
+};
+
struct lt_list_t : public my_t_impl
{
lt_list_t* mpPrev;
@@ -260,6 +266,7 @@ struct lt_tag_t : public my_t_impl
lt_script_t maScript;
lt_region_t maRegion;
my_t_list maVariants;
+ lt_string_t maPrivateUse;
explicit lt_tag_t() : my_t_impl(), maLanguage(), maScript(), maRegion(), maVariants() {}
virtual ~lt_tag_t() {}
explicit lt_tag_t( const lt_tag_t& r )
@@ -354,6 +361,13 @@ static lt_bool_t lt_tag_parse(lt_tag_t *tag,
{
(*ppSub)->assign( pStart, p);
bPrivate = true;
+ if (*pStart == 'x')
+ {
+ // Simply copy all to privateuse field, we
+ // do not care here what part actually is
+ // private.
+ tag->maPrivateUse.assign( pStart, pEnd);
+ }
}
else
return 0; // bad
@@ -531,6 +545,11 @@ static const lt_list_t *lt_tag_get_variants(const lt_tag_t *tag)
return tag ? tag->maVariants.mpList : NULL;
}
+static const lt_string_t *lt_tag_get_privateuse(const lt_tag_t *tag)
+{
+ return tag && tag->maPrivateUse.mpStr ? &tag->maPrivateUse : NULL;
+}
+
static const char *lt_lang_get_tag(const lt_lang_t *lang)
{
return lang ? lang->mpStr : NULL;
@@ -551,6 +570,11 @@ static const char *lt_variant_get_tag(const lt_variant_t *variant)
return variant ? variant->mpStr : NULL;
}
+static size_t lt_string_length(const lt_string_t *string)
+{
+ return string ? strlen(string->mpStr) : 0;
+}
+
#ifdef erDEBUG
static void lt_tag_dump(const lt_tag_t *tag)
{
commit a31f53d0587b39bec9dca62b49a63cee0f08f3fe
Author: Eike Rathke <erack at redhat.com>
Date: Tue Jun 3 14:18:45 2014 +0200
add unit test for LanguageTag::isValidBcp47() with bDisallowPrivate
Change-Id: I58089bc00c640bb1d8461d8f482ad623f9566e76
diff --git a/i18nlangtag/qa/cppunit/test_languagetag.cxx b/i18nlangtag/qa/cppunit/test_languagetag.cxx
index b86e263..2bbad1c 100644
--- a/i18nlangtag/qa/cppunit/test_languagetag.cxx
+++ b/i18nlangtag/qa/cppunit/test_languagetag.cxx
@@ -592,7 +592,11 @@ void TestLanguageTag::testAllTags()
OUString aCanonicalized;
CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "en-US", &aCanonicalized) && aCanonicalized == "en-US" );
CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "x-foobar", &aCanonicalized) && aCanonicalized == "x-foobar" );
+ CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "qaa", &aCanonicalized) && aCanonicalized == "qaa" );
CPPUNIT_ASSERT( !LanguageTag::isValidBcp47( "unreg-and-bad", &aCanonicalized) );
+ CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "en-US", &aCanonicalized, true) && aCanonicalized == "en-US" );
+ CPPUNIT_ASSERT( !LanguageTag::isValidBcp47( "x-foobar", &aCanonicalized, true) && aCanonicalized == "x-foobar" );
+ CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "qaa", &aCanonicalized, true) && aCanonicalized == "qaa" );
#if USE_LIBLANGTAG
CPPUNIT_ASSERT( LanguageTag::isValidBcp47( "de-Latn-DE", &aCanonicalized) && aCanonicalized == "de-DE" );
/* TODO: at least some (those we know) grandfathered tags should be
commit fecde4c7099fdb7c5ee396b0f68ec517f3a08955
Author: Eike Rathke <erack at redhat.com>
Date: Tue Jun 3 14:17:17 2014 +0200
add bDisallowPrivate parameter to LanguageTag::isValidBcp47()
Change-Id: I0924b0fa268c38c238226d082cf26595bba72f0c
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 483cf98..237fdca 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 0e12235..f3cf642 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 );
More information about the Libreoffice-commits
mailing list