diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2006-08-11 16:16:52 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2006-08-11 16:16:52 +0000 |
commit | 5daf1a8d9381475812ebc46308b78cb5bf55a099 (patch) | |
tree | 5ca2c980a0b64e539a9ec08ac7e128ce0a1b3f18 /desktop | |
parent | 7504a1464e62c9cd73ac3a06f12389e7e4bfd245 (diff) |
INTEGRATION: CWS jl40 (1.12.70); FILE MERGED
2006/07/27 11:44:10 jl 1.12.70.1: #67372# schema of description.xml changed
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/source/deployment/misc/dp_resource.cxx | 127 |
1 files changed, 125 insertions, 2 deletions
diff --git a/desktop/source/deployment/misc/dp_resource.cxx b/desktop/source/deployment/misc/dp_resource.cxx index 0ce0b4758afd..a43dcc870aae 100644 --- a/desktop/source/deployment/misc/dp_resource.cxx +++ b/desktop/source/deployment/misc/dp_resource.cxx @@ -4,9 +4,9 @@ * * $RCSfile: dp_resource.cxx,v $ * - * $Revision: 1.12 $ + * $Revision: 1.13 $ * - * last change: $Author: vg $ $Date: 2006-04-07 14:46:03 $ + * last change: $Author: hr $ $Date: 2006-08-11 17:16:52 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -97,6 +97,129 @@ String getResourceString( USHORT 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(OUSTR("Invalid language string."), 0); + + if (len == 1 + && (arLang[0] != 'i' && arLang[0] != 'x')) + throw Exception(OUSTR("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(OUSTR("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(OUSTR("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(OUSTR("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(OUSTR("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(OUSTR("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(OUSTR("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.getLength() > 0) + { + bool bIsCountry = false; + checkSecondSubtag(country, bIsCountry); + if (bIsCountry) + { + locale.Country = country; + } + else + { + locale.Variant = country; + } + } + if (locale.Variant.getLength() == 0) + { + OUString variant = _sLang.getToken( 0, '-', nIndex ); + if (variant.getLength() > 0) + { + checkThirdSubtag(variant); + locale.Variant = variant; + } + } + + return locale; +} + //============================================================================== lang::Locale const & getOfficeLocale() { |