From a17dcc5a32fb57335fc4350e5e78d7d513c72e35 Mon Sep 17 00:00:00 2001 From: Kurt Zenker Date: Tue, 31 Jan 2006 17:37:25 +0000 Subject: [PATCH] INTEGRATION: CWS i18n24 (1.5.36); FILE MERGED 2006/01/11 08:49:52 khong 1.5.36.2: #i60331 extract index data to external library 2006/01/10 23:08:57 khong 1.5.36.1: #i60331 extract index data to external library --- .../indexentry/indexentrysupplier_asian.cxx | 118 +++++++++++++++--- 1 file changed, 100 insertions(+), 18 deletions(-) diff --git a/i18npool/source/indexentry/indexentrysupplier_asian.cxx b/i18npool/source/indexentry/indexentrysupplier_asian.cxx index 5415d02b7f97..04777d870a94 100644 --- a/i18npool/source/indexentry/indexentrysupplier_asian.cxx +++ b/i18npool/source/indexentry/indexentrysupplier_asian.cxx @@ -4,9 +4,9 @@ * * $RCSfile: indexentrysupplier_asian.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: rt $ $Date: 2005-09-07 17:09:15 $ + * last change: $Author: kz $ $Date: 2006-01-31 18:37:25 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -33,34 +33,116 @@ * ************************************************************************/ +#include #include #include using namespace ::com::sun::star::uno; -using namespace ::com::sun::star; +using namespace ::com::sun::star::lang; using namespace ::rtl; namespace com { namespace sun { namespace star { namespace i18n { -OUString SAL_CALL IndexEntrySupplier_CJK::getIndexString( const sal_Unicode ch, - const sal_Unicode CJK_idxStr[], const sal_uInt16 idx1[], const sal_uInt16 idx2[]) +IndexEntrySupplier_asian::IndexEntrySupplier_asian( + const Reference < XMultiServiceFactory >& rxMSF ) : IndexEntrySupplier_Common(rxMSF) +{ + implementationName = "com.sun.star.i18n.IndexEntrySupplier_asian"; +#ifdef SAL_DLLPREFIX + OUString lib=OUString::createFromAscii(SAL_DLLPREFIX"index_data"SAL_DLLEXTENSION); +#else + OUString lib=OUString::createFromAscii("index_data"SAL_DLLEXTENSION); +#endif + hModule = osl_loadModule( lib.pData, SAL_LOADMODULE_DEFAULT ); +} + +IndexEntrySupplier_asian::~IndexEntrySupplier_asian() +{ + if (hModule) osl_unloadModule(hModule); +} + +OUString SAL_CALL +IndexEntrySupplier_asian::getIndexCharacter( const OUString& rIndexEntry, + const Locale& rLocale, const OUString& rAlgorithm ) throw (RuntimeException) +{ + sal_Unicode ch = rIndexEntry.toChar(); + if (hModule) { + OUString get=OUString::createFromAscii("get_indexdata_"); + int (*func)()=NULL; + if (rLocale.Language.equalsAscii("zh") && OUString::createFromAscii("TW HK MO").indexOf(rLocale.Country) >= 0) + func=(int (*)())osl_getSymbol(hModule, (get+rLocale.Language+OUString::createFromAscii("_TW_")+rAlgorithm).pData); + if (!func) + func=(int (*)())osl_getSymbol(hModule, (get+rLocale.Language+OUString('_')+rAlgorithm).pData); + if (func) { + sal_uInt16** idx=(sal_uInt16**)func(); + sal_uInt16 address=idx[0][ch >> 8]; + if (address != 0xFFFF) { + address=idx[1][address+(ch & 0xFF)]; + return idx[2] ? OUString(&idx[2][address]) : OUString(address); + } + } + } + // using alphanumeric index for non-define stirng + return OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1); +} + +OUString SAL_CALL +IndexEntrySupplier_asian::getIndexKey( const OUString& rIndexEntry, + const OUString& rPhoneticEntry, const Locale& rLocale) throw (RuntimeException) +{ + return getIndexCharacter(getEntry(rIndexEntry, rPhoneticEntry, rLocale), rLocale, aAlgorithm); +} + +sal_Int16 SAL_CALL +IndexEntrySupplier_asian::compareIndexEntry( + const OUString& rIndexEntry1, const OUString& rPhoneticEntry1, const Locale& rLocale1, + const OUString& rIndexEntry2, const OUString& rPhoneticEntry2, const Locale& rLocale2 ) throw (RuntimeException) { - sal_uInt16 first = idx1[ ch >> 8 ]; - return first == 0xFFFF ? - // using alphanumeric index for non-define stirng - OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1) : - OUString(&CJK_idxStr[idx2[ first + (ch & 0xff) ]]); + sal_Int16 result = collator->compareString(getEntry(rIndexEntry1, rPhoneticEntry1, rLocale1), + getEntry(rIndexEntry2, rPhoneticEntry2, rLocale2)); + + // equivalent of phonetic entries does not mean equivalent of index entries. + // we have to continue comparing index entry here. + if (result == 0 && usePhonetic && rPhoneticEntry1.getLength() > 0 && + rLocale1.Language == rLocale2.Language && rLocale1.Country == rLocale2.Country && + rLocale1.Variant == rLocale2.Variant) + result = collator->compareString(rIndexEntry1, rIndexEntry2); + return result; } -OUString SAL_CALL IndexEntrySupplier_CJK::getIndexString( const sal_Unicode ch, - const sal_uInt16 idx1[], const sal_Unicode idx2[]) throw (RuntimeException) +OUString SAL_CALL +IndexEntrySupplier_asian::getPhoneticCandidate( const OUString& rIndexEntry, + const Locale& rLocale ) throw (RuntimeException) { - sal_uInt16 first = idx1[ ch >> 8 ]; - return first == 0xFFFF ? - // using alphanumeric index for non-define stirng - OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1) : - OUString(&idx2[ first + (ch & 0xff) ], 1); + if (hModule) { + int (*func)()=NULL; + const sal_Char *func_name=NULL; + if (rLocale.Language.equalsAscii("zh")) + func_name=(OUString::createFromAscii("TW HK MO").indexOf(rLocale.Country) >= 0) ? "get_zh_zhuyin" : func_name="get_zh_pinyin"; + else if (rLocale.Language.equalsAscii("ko")) + func_name="get_ko_phonetic"; + if (func_name) + func=(int (*)())osl_getSymbol(hModule, OUString::createFromAscii(func_name).pData); + if (func) { + OUStringBuffer candidate; + sal_uInt16** idx=(sal_uInt16**)func(); + for (sal_Int32 i=0; i < rIndexEntry.getLength(); i++) { + sal_Unicode ch = rIndexEntry[i]; + sal_uInt16 address = idx[0][ch>>8]; + if (address != 0xFFFF) { + address = idx[1][address + (ch & 0xFF)]; + if (i > 0 && rLocale.Language.equalsAscii("zh")) + candidate.appendAscii(" "); + if (idx[2]) + candidate.append(&idx[2][address]); + else + candidate.append(address); + } else + candidate.appendAscii(" "); + } + return candidate.makeStringAndClear(); + } + } + return OUString(); } - } } } }