summaryrefslogtreecommitdiff
path: root/i18nlangtag
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2014-05-21 14:13:23 +0200
committerEike Rathke <erack@redhat.com>2014-05-21 14:15:24 +0200
commita6e6cc49bfbf594aa59804ee0d9751d5ff19caba (patch)
treea0b22ab7085a7ba7016cd8636e75b1231f99495d /i18nlangtag
parentf824604b5c1b480bf6680935362eb1d4617187c9 (diff)
add static LanguageTag::isValidBcp47()
Change-Id: I2c646b3e2f13a6fccc845ce8eb82fccee154f3c6
Diffstat (limited to 'i18nlangtag')
-rw-r--r--i18nlangtag/source/languagetag/languagetag.cxx40
1 files changed, 40 insertions, 0 deletions
diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx
index 33816b3c7e0f..8a96bde83f81 100644
--- a/i18nlangtag/source/languagetag/languagetag.cxx
+++ b/i18nlangtag/source/languagetag/languagetag.cxx
@@ -2685,4 +2685,44 @@ com::sun::star::lang::Locale LanguageTag::convertToLocaleWithFallback( const OUS
return LanguageTag( rBcp47).makeFallback().getLocale( true);
}
+
+// static
+bool LanguageTag::isValidBcp47( const OUString& rString, OUString* o_pCanonicalized )
+{
+ struct guard
+ {
+ lt_tag_t* mpLangtag;
+ guard()
+ {
+ theDataRef::get().incRef();
+ mpLangtag = lt_tag_new();
+ }
+ ~guard()
+ {
+ lt_tag_unref( mpLangtag);
+ theDataRef::get().decRef();
+ }
+ } aVar;
+
+ myLtError aError;
+
+ if (lt_tag_parse( aVar.mpLangtag, OUStringToOString( rString, RTL_TEXTENCODING_UTF8).getStr(), &aError.p))
+ {
+ char* pTag = lt_tag_canonicalize( aVar.mpLangtag, &aError.p);
+ SAL_WARN_IF( !pTag, "i18nlangtag", "LanguageTag:isValidBcp47: could not canonicalize '" << rString << "'");
+ if (pTag)
+ {
+ if (o_pCanonicalized)
+ *o_pCanonicalized = OUString::createFromAscii( pTag);
+ free( pTag);
+ return true;
+ }
+ }
+ else
+ {
+ SAL_INFO( "i18nlangtag", "LanguageTag:isValidBcp47: could not parse '" << rString << "'");
+ }
+ return false;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */