Kaydet (Commit) 5c1ea4f2 authored tarafından Vladimir Glazounov's avatar Vladimir Glazounov

INTEGRATION: CWS i18n39 (1.17.8); FILE MERGED

2008/01/11 07:30:04 khong 1.17.8.2: i78055 provide UCA as base for ICU collator constructor from image rule
2008/01/08 04:26:40 khong 1.17.8.1: i78055 move simple collator tailoring to localedata
üst 3f0b5177
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
* *
* $RCSfile: collator_unicode.cxx,v $ * $RCSfile: collator_unicode.cxx,v $
* *
* $Revision: 1.18 $ * $Revision: 1.19 $
* *
* last change: $Author: ihi $ $Date: 2008-01-16 14:32:11 $ * last change: $Author: vg $ $Date: 2008-01-28 15:34:01 $
* *
* The Contents of this file are made available subject to * The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1. * the terms of GNU Lesser General Public License Version 2.1.
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <collator_unicode.hxx> #include <collator_unicode.hxx>
#include <localedata.hxx>
#include <com/sun/star/i18n/CollatorOptions.hpp> #include <com/sun/star/i18n/CollatorOptions.hpp>
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -54,12 +55,14 @@ Collator_Unicode::Collator_Unicode() ...@@ -54,12 +55,14 @@ Collator_Unicode::Collator_Unicode()
{ {
implementationName = "com.sun.star.i18n.Collator_Unicode"; implementationName = "com.sun.star.i18n.Collator_Unicode";
collator = NULL; collator = NULL;
uca_base = NULL;
hModule = NULL; hModule = NULL;
} }
Collator_Unicode::~Collator_Unicode() Collator_Unicode::~Collator_Unicode()
{ {
if (collator) delete collator; if (collator) delete collator;
if (uca_base) delete uca_base;
if (hModule) osl_unloadModule(hModule); if (hModule) osl_unloadModule(hModule);
} }
...@@ -83,22 +86,13 @@ Collator_Unicode::loadCollatorAlgorithm(const OUString& rAlgorithm, const lang:: ...@@ -83,22 +86,13 @@ Collator_Unicode::loadCollatorAlgorithm(const OUString& rAlgorithm, const lang::
throw(RuntimeException) throw(RuntimeException)
{ {
if (!collator) { if (!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());
// load ICU collator
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
collator = (RuleBasedCollator*) icu::Collator::createInstance(icuLocale, status); OUString rule = LocaleData().getCollatorRuleByAlgorithm(rLocale, rAlgorithm);
if (! U_SUCCESS(status)) if (rule.getLength() > 0) {
throw RuntimeException(); collator = new RuleBasedCollator(rule.getStr(), status);
if (OUString::createFromAscii(LOCAL_RULE_LANGS).indexOf(rLocale.Language) >= 0) { if (! U_SUCCESS(status)) throw RuntimeException();
}
if (!collator && OUString::createFromAscii(LOCAL_RULE_LANGS).indexOf(rLocale.Language) >= 0) {
OUStringBuffer aBuf; OUStringBuffer aBuf;
#ifdef SAL_DLLPREFIX #ifdef SAL_DLLPREFIX
aBuf.appendAscii(SAL_DLLPREFIX); aBuf.appendAscii(SAL_DLLPREFIX);
...@@ -131,12 +125,28 @@ Collator_Unicode::loadCollatorAlgorithm(const OUString& rAlgorithm, const lang:: ...@@ -131,12 +125,28 @@ Collator_Unicode::loadCollatorAlgorithm(const OUString& rAlgorithm, const lang::
} }
if (func) { if (func) {
const sal_uInt8* ruleImage=func(); const sal_uInt8* ruleImage=func();
collator = new RuleBasedCollator(reinterpret_cast<const uint8_t*>(ruleImage), -1, collator, status); uca_base = new RuleBasedCollator((sal_Unicode*)NULL, status);
if (! U_SUCCESS(status)) if (! U_SUCCESS(status)) throw RuntimeException();
throw RuntimeException(); collator = new RuleBasedCollator(reinterpret_cast<const uint8_t*>(ruleImage), -1, uca_base, status);
if (! U_SUCCESS(status)) throw RuntimeException();
} }
} }
} }
if (!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());
// load ICU collator
collator = (RuleBasedCollator*) icu::Collator::createInstance(icuLocale, status);
if (! U_SUCCESS(status)) throw RuntimeException();
}
} }
if (options & CollatorOptions::CollatorOptions_IGNORE_CASE_ACCENT) if (options & CollatorOptions::CollatorOptions_IGNORE_CASE_ACCENT)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment