diff options
author | Eike Rathke <erack@redhat.com> | 2013-03-28 20:48:18 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-03-29 14:09:00 +0100 |
commit | 6f4bceef5906c535127fc78c3cc0353b8472eefa (patch) | |
tree | b744a3f4a25fdf3614d2127ed3ee84336f2a3c2f /desktop | |
parent | 80bbe6d1ca9605a94fd028845bda1242cc13a9ba (diff) |
ditch this overengineered nonsense
The umpteenth implementation to parse a partial language tag.
Change-Id: Idaab568acdeb578d174f0968feae6db711120b55
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/source/deployment/misc/dp_resource.cxx | 120 |
1 files changed, 2 insertions, 118 deletions
diff --git a/desktop/source/deployment/misc/dp_resource.cxx b/desktop/source/deployment/misc/dp_resource.cxx index f20941eaae79..0cf266e9102b 100644 --- a/desktop/source/deployment/misc/dp_resource.cxx +++ b/desktop/source/deployment/misc/dp_resource.cxx @@ -26,6 +26,7 @@ #include "rtl/ustring.h" #include "cppuhelper/implbase1.hxx" #include "unotools/configmgr.hxx" +#include <i18npool/languagetag.hxx> using namespace ::com::sun::star; @@ -75,127 +76,10 @@ String getResourceString( sal_uInt16 id ) return ret; } -//throws an Exception on failure -//primary subtag 2 or three letters(A-Z, a-z), i or x -void checkPrimarySubtag(::rtl::OUString const & tag) -{ - sal_Int32 len = tag.getLength(); - sal_Unicode const * arLang = tag.getStr(); - if (len < 1 || len > 3) - throw Exception("Invalid language string.", 0); - - if (len == 1 - && (arLang[0] != 'i' && arLang[0] != 'x')) - throw Exception("Invalid language string.", 0); - - if (len == 2 || len == 3) - { - for (sal_Int32 i = 0; i < len; i++) - { - if ( !((arLang[i] >= 'A' && arLang[i] <= 'Z') - || (arLang[i] >= 'a' && arLang[i] <= 'z'))) - { - throw Exception("Invalid language string.", 0); - } - } - } -} - -//throws an Exception on failure -//second subtag 2 letter country code or 3-8 letter other code(A-Z, a-z, 0-9) -void checkSecondSubtag(::rtl::OUString const & tag, bool & bIsCountry) -{ - sal_Int32 len = tag.getLength(); - sal_Unicode const * arLang = tag.getStr(); - if (len < 2 || len > 8) - throw Exception("Invalid language string.", 0); - //country code - bIsCountry = false; - if (len == 2) - { - for (sal_Int32 i = 0; i < 2; i++) - { - if (!( (arLang[i] >= 'A' && arLang[i] <= 'Z') - || (arLang[i] >= 'a' && arLang[i] <= 'z'))) - { - throw Exception("Invalid language string.", 0); - } - } - bIsCountry = true; - } - - if (len > 2) - { - for (sal_Int32 i = 0; i < len; i++) - { - if (!( (arLang[i] >= 'A' && arLang[i] <= 'Z') - || (arLang[i] >= 'a' && arLang[i] <= 'z') - || (arLang[i] >= '0' && arLang[i] <= '9') )) - { - throw Exception("Invalid language string.", 0); - } - } - } -} - -void checkThirdSubtag(::rtl::OUString const & tag) -{ - sal_Int32 len = tag.getLength(); - sal_Unicode const * arLang = tag.getStr(); - if (len < 1 || len > 8) - throw Exception("Invalid language string.", 0); - - for (sal_Int32 i = 0; i < len; i++) - { - if (!( (arLang[i] >= 'A' && arLang[i] <= 'Z') - || (arLang[i] >= 'a' && arLang[i] <= 'z') - || (arLang[i] >= '0' && arLang[i] <= '9') )) - { - throw Exception("Invalid language string.", 0); - } - } -} - //============================================================================= - -//We parse the string acording to RFC 3066 -//We only use the primary sub-tag and two subtags. That is lang-country-variant -//We do some simple tests if the string is correct. Actually this should do a -//validating parser -//We may have the case that there is no country tag, for example en-welsh ::com::sun::star::lang::Locale toLocale( ::rtl::OUString const & slang ) { - OUString _sLang = slang.trim(); - ::com::sun::star::lang::Locale locale; - sal_Int32 nIndex = 0; - OUString lang = _sLang.getToken( 0, '-', nIndex ); - checkPrimarySubtag(lang); - locale.Language = lang; - OUString country = _sLang.getToken( 0, '-', nIndex ); - if (!country.isEmpty()) - { - bool bIsCountry = false; - checkSecondSubtag(country, bIsCountry); - if (bIsCountry) - { - locale.Country = country; - } - else - { - locale.Variant = country; - } - } - if (locale.Variant.isEmpty()) - { - OUString variant = _sLang.getToken( 0, '-', nIndex ); - if (!variant.isEmpty()) - { - checkThirdSubtag(variant); - locale.Variant = variant; - } - } - - return locale; + return LanguageTag( slang).getLocale(); } //============================================================================== |