diff options
author | RĂ¼diger Timm <rt@openoffice.org> | 2004-01-20 12:24:21 +0000 |
---|---|---|
committer | RĂ¼diger Timm <rt@openoffice.org> | 2004-01-20 12:24:21 +0000 |
commit | bc11e12af85f74b77dba18870e09b7761077dda5 (patch) | |
tree | ba37e8973c50fab4bd9e53b274b2694a53505150 /i18npool | |
parent | f9cea3bf765ddbd446730f04d8c708165d413645 (diff) |
INTEGRATION: CWS i18n10 (1.5.48); FILE MERGED
2003/12/17 20:12:37 khong 1.5.48.1: #i22138# #112506# migrate to ICU collator and remove link to tool library
Diffstat (limited to 'i18npool')
-rw-r--r-- | i18npool/source/collator/collator_unicode.cxx | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/i18npool/source/collator/collator_unicode.cxx b/i18npool/source/collator/collator_unicode.cxx index ff980257acd6..9de3f9556883 100644 --- a/i18npool/source/collator/collator_unicode.cxx +++ b/i18npool/source/collator/collator_unicode.cxx @@ -2,9 +2,9 @@ * * $RCSfile: collator_unicode.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: vg $ $Date: 2003-04-24 11:06:55 $ + * last change: $Author: rt $ $Date: 2004-01-20 13:24:21 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,9 +59,9 @@ * ************************************************************************/ +#include <rtl/ustrbuf.hxx> #include <collator_unicode.hxx> #include <com/sun/star/i18n/CollatorOptions.hpp> -#include <i18nutil/casefolding.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::lang; @@ -73,59 +73,60 @@ namespace com { namespace sun { namespace star { namespace i18n { Collator_Unicode::Collator_Unicode() { implementationName = "com.sun.star.i18n.Collator_Unicode"; - tranModules = TransliterationModules_END_OF_MODULE; + collator = NULL; + rulesImage = NULL; } Collator_Unicode::~Collator_Unicode() { + if (collator) delete collator; } sal_Int32 SAL_CALL Collator_Unicode::compareSubstring( const OUString& str1, sal_Int32 off1, sal_Int32 len1, const OUString& str2, sal_Int32 off2, sal_Int32 len2) throw(RuntimeException) { - sal_Unicode *uniStr1 = (sal_Unicode*) str1.getStr() + off1; - sal_Unicode *uniStr2 = (sal_Unicode*) str2.getStr() + off2; - - MappingElement e1, e2; - sal_Int32 idx1, idx2; - sal_Unicode c1, c2; - - idx1 = idx2 = 0; - while (idx1 < len1 && idx2 < len2) { - if (tranModules != TransliterationModules_END_OF_MODULE) { - c1 = casefolding::getNextChar(uniStr1, idx1, len1, e1, aLocale, MappingTypeFullFolding, tranModules); - c2 = casefolding::getNextChar(uniStr2, idx2, len2, e2, aLocale, MappingTypeFullFolding, tranModules); - } else { - c1 = uniStr1[idx1++]; - c2 = uniStr1[idx2++]; - } - if (c1 != c2) - return c1 < c2 ? -1 : 1; - } - return idx1 == len1 && idx2 == len2 ? 0 : (idx1 == len1 ? -1 : 1); + return collator->compare(str1.getStr() + off1, len1, str2.getStr() + off2, len2); } sal_Int32 SAL_CALL Collator_Unicode::compareString( const OUString& str1, const OUString& str2) throw(RuntimeException) { - return compareSubstring(str1, 0, str1.getLength(), str2, 0, str2.getLength()); + return collator->compare(str1.getStr(), str2.getStr()); } - sal_Int32 SAL_CALL Collator_Unicode::loadCollatorAlgorithm(const OUString& rAlgorithm, const lang::Locale& rLocale, sal_Int32 options) throw(RuntimeException) { - aLocale = rLocale; + if (!collator) { + // load ICU collator + UErrorCode status = U_ZERO_ERROR; + if (rulesImage) { + collator = new RuleBasedCollator(rulesImage, status); + } else { + // load ICU collator + /** ICU collators are loaded using a locale only. + ICU uses Variant as collation algorithm name (like de__PHONEBOOK + locale), note the empty territory (Country) designator in this special + case here. The icu::Locale contructor changes the algorithm name to + uppercase itself, so we don't have to bother with that. + */ + icu::Locale icuLocale( + OUStringToOString(rLocale.Language, RTL_TEXTENCODING_ASCII_US).getStr(), + OUStringToOString(rLocale.Country, RTL_TEXTENCODING_ASCII_US).getStr(), + OUStringToOString(rAlgorithm, RTL_TEXTENCODING_ASCII_US).getStr()); + + collator = (RuleBasedCollator*) icu::Collator::createInstance(icuLocale, status); + } + if (! U_SUCCESS(status)) + throw RuntimeException(); + } - tranModules = TransliterationModules_END_OF_MODULE; if (options & CollatorOptions::CollatorOptions_IGNORE_CASE) - tranModules = (TransliterationModules)(tranModules | TransliterationModules_IGNORE_CASE); - if (options & CollatorOptions::CollatorOptions_IGNORE_KANA) - tranModules = (TransliterationModules) (tranModules | TransliterationModules_IGNORE_KANA); - if (options & CollatorOptions::CollatorOptions_IGNORE_WIDTH) - tranModules = (TransliterationModules) (tranModules | TransliterationModules_IGNORE_WIDTH); + collator->setStrength(Collator::PRIMARY); + else + collator->setStrength(Collator::TERTIARY); return(0); } |