diff options
author | Karl Hong <khong@openoffice.org> | 2002-06-18 21:29:26 +0000 |
---|---|---|
committer | Karl Hong <khong@openoffice.org> | 2002-06-18 21:29:26 +0000 |
commit | abc65d5612cb2c525183e61e4c0e94a756093188 (patch) | |
tree | 1032a9c431c2e08882f0ad7e94a19063953793d6 /i18npool | |
parent | c2adf960d7ffa5e4609aea4f59684d87618909d9 (diff) |
#99877#First implementation for XExtendedIndexEntrySupplier
Diffstat (limited to 'i18npool')
4 files changed, 244 insertions, 28 deletions
diff --git a/i18npool/source/indexentry/indexentrysupplier.cxx b/i18npool/source/indexentry/indexentrysupplier.cxx index 491b936f678f..5ac2737f1a7e 100644 --- a/i18npool/source/indexentry/indexentrysupplier.cxx +++ b/i18npool/source/indexentry/indexentrysupplier.cxx @@ -2,9 +2,9 @@ * * $RCSfile: indexentrysupplier.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: er $ $Date: 2002-03-26 17:06:09 $ + * last change: $Author: khong $ $Date: 2002-06-18 22:29:26 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -69,6 +69,47 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::rtl; +static const sal_Unicode under = sal_Unicode('_'); + +static const struct { + const char* pLocale; + const char* pAlgorithms; + sal_Int16 pAlgorithmCount; +} aLocaleList[] = { + { "ar", "alphanumeric", 1 }, + { "bg", "alphanumeric", 1 }, + { "ca", "alphanumeric", 1 }, + { "cs", "alphanumeric", 1 }, + { "da", "alphanumeric", 1 }, + { "de", "alphanumeric", 1 }, + { "el", "alphanumeric", 1 }, + { "en", "alphanumeric", 1 }, + { "es", "alphanumeric", 1 }, + { "fi", "alphanumeric", 1 }, + { "fr", "alphanumeric", 1 }, + { "he", "alphanumeric", 1 }, + { "hi", "alphanumeric", 1 }, + { "hu", "alphanumeric", 1 }, + { "is", "alphanumeric", 1 }, + { "it", "alphanumeric", 1 }, + { "ja", "phonetic", 1 }, + { "ko", "dict", 1 }, + { "nb", "alphanumeric", 1 }, + { "nl", "alphanumeric", 1 }, + { "nn", "alphanumeric", 1 }, + { "no", "alphanumeric", 1 }, + { "pl", "alphanumeric", 1 }, + { "pt", "alphanumeric", 1 }, + { "ru", "alphanumeric", 1 }, + { "sv", "alphanumeric", 1 }, + { "tr", "alphanumeric", 1 }, + { "th", "alphanumeric", 1 }, + { "zh_CN", "pinyin stroke radical", 3 }, + { "zh_TW", "stroke radical zhuyin pinyin", 4 }, +}; + +static const sal_Int16 nbOfLocales = sizeof(aLocaleList) / sizeof(aLocaleList[0]); + namespace com { namespace sun { namespace star { namespace i18n { IndexEntrySupplier::IndexEntrySupplier( const Reference < XMultiServiceFactory >& rxMSF ) : xMSF( rxMSF ) @@ -76,6 +117,100 @@ IndexEntrySupplier::IndexEntrySupplier( const Reference < XMultiServiceFactory > implementationName = "com.sun.star.i18n.IndexEntrySupplier"; } + +Sequence < Locale > SAL_CALL IndexEntrySupplier::getLocaleList() throw (RuntimeException) +{ + Sequence < Locale > localeList(nbOfLocales); + + for( sal_Int16 i=0; i<nbOfLocales; i++ ) { + OUString name = OUString::createFromAscii( aLocaleList[i].pLocale ); + sal_Int32 index = 0; + localeList[i].Language = name.getToken(0, under, index); + if (index >= 0) { + localeList[i].Country = name.getToken(0, under, index); + if (index >= 0) + localeList[i].Variant = name.getToken(0, under, index); + } + } + + return localeList; +} + +Sequence < OUString > SAL_CALL IndexEntrySupplier::getAlgorithmList( const Locale& rLocale ) throw (RuntimeException) +{ + Sequence < OUString > algorithmList; + + for( sal_Int16 i=0; i<nbOfLocales; i++ ) { + OUString name = OUString::createFromAscii( aLocaleList[i].pLocale ); + sal_Int32 index = 0; + + if (rLocale.Language.equals(name.getToken(0, under, index))) { + if (index >= 0 && rLocale.Language.compareToAscii("zh") == 0) { + + OUString country = name.getToken(0, under, index); + + // make sure Simplified and Traditional Chinese use right list. + if ((country.compareToAscii("TW") == 0 && + rLocale.Country.compareToAscii("TW") != 0 && + rLocale.Country.compareToAscii("HK") != 0 && + rLocale.Country.compareToAscii("MO") != 0) + || (country.compareToAscii("CN") == 0 && + rLocale.Country.getLength() > 0 && + rLocale.Country.compareToAscii("CN") != 0 && + rLocale.Country.compareToAscii("SG") != 0)) { + continue; + } + } + + OUString algorithms = OUString::createFromAscii( aLocaleList[i].pAlgorithms ); + + algorithmList.realloc(aLocaleList[i].pAlgorithmCount); + index = 0; + for (sal_Int16 j=0; j<aLocaleList[i].pAlgorithmCount; j++) + algorithmList[j] = algorithms.getToken(0, sal_Unicode(' '), index); + + break; + } + } + return algorithmList; +} + +sal_Bool SAL_CALL IndexEntrySupplier::loadAlgorithm( const Locale& rLocale, const OUString& SortAlgorithm, + sal_Int32 collatorOptions ) throw (RuntimeException) +{ + if (getLocaleSpecificIndexEntrySupplier(rLocale, SortAlgorithm).is()) + return xIES->loadAlgorithm(rLocale, SortAlgorithm, collatorOptions); + return sal_False; +} + +sal_Bool SAL_CALL IndexEntrySupplier::usePhoneticEntry( const Locale& rLocale ) throw (RuntimeException) +{ + // First implementation only turns the feature on for Japanese language. + return rLocale.Language.compareToAscii("ja") == 0; +} + +OUString SAL_CALL IndexEntrySupplier::getPhoneticCandidate( const OUString& rIndexEntry, + const Locale& rLocale ) throw (RuntimeException) +{ + // TODO: the phonetic candidate will be provided by language engine for CJK. + return OUString(); +} + +OUString SAL_CALL IndexEntrySupplier::getIndexKey( const OUString& rIndexEntry, + const OUString& rPhoneticEntry, const Locale& rLocale ) throw (RuntimeException) +{ + return xIES->getIndexKey(rIndexEntry, rPhoneticEntry, rLocale); +} + +sal_Int16 SAL_CALL IndexEntrySupplier::compareIndexEntry( + const OUString& rIndexEntry1, const OUString& rPhoneticEntry1, const Locale& rLocale1, + const OUString& rIndexEntry2, const OUString& rPhoneticEntry2, const Locale& rLocale2 ) + throw (com::sun::star::uno::RuntimeException) +{ + return xIES->compareIndexEntry(rIndexEntry1, rPhoneticEntry1, rLocale1, + rIndexEntry2, rPhoneticEntry2, rLocale2); +} + OUString SAL_CALL IndexEntrySupplier::getIndexCharacter( const OUString& rIndexEntry, const Locale& rLocale, const OUString& rSortAlgorithm ) throw (RuntimeException) @@ -84,7 +219,7 @@ OUString SAL_CALL IndexEntrySupplier::getIndexCharacter( const OUString& rIndexE getIndexCharacter( rIndexEntry, rLocale, rSortAlgorithm ); } -static inline sal_Bool operator == (const Locale& l1, const Locale& l2) { +sal_Bool SAL_CALL operator == (const Locale& l1, const Locale& l2) { return l1.Language == l2.Language && l1.Country == l2.Country && l1.Variant == l2.Variant; } @@ -94,13 +229,13 @@ sal_Bool SAL_CALL IndexEntrySupplier::createLocaleSpecificIndexEntrySupplier(con OUString::createFromAscii("com.sun.star.i18n.IndexEntrySupplier_") + name); if ( xI.is() ) { - xI->queryInterface( ::getCppuType((const Reference< XIndexEntrySupplier>*)0) ) >>= xIES; + xI->queryInterface( ::getCppuType((const Reference< drafts::com::sun::star::i18n::XExtendedIndexEntrySupplier>*)0) ) >>= xIES; return xIES.is(); } return sal_False; } -Reference < XIndexEntrySupplier > SAL_CALL +Reference < drafts::com::sun::star::i18n::XExtendedIndexEntrySupplier > SAL_CALL IndexEntrySupplier::getLocaleSpecificIndexEntrySupplier(const Locale& rLocale, const OUString& rSortAlgorithm) throw (RuntimeException) { if (xIES.is() && rLocale == aLocale && rSortAlgorithm == aSortAlgorithm) @@ -109,7 +244,6 @@ IndexEntrySupplier::getLocaleSpecificIndexEntrySupplier(const Locale& rLocale, c aLocale = rLocale; aSortAlgorithm = rSortAlgorithm; - static sal_Unicode under = (sal_Unicode)'_'; static OUString tw(OUString::createFromAscii("TW")); static OUString unicode(OUString::createFromAscii("Unicode")); diff --git a/i18npool/source/indexentry/indexentrysupplier_asian.cxx b/i18npool/source/indexentry/indexentrysupplier_asian.cxx index 45edb38f1cbd..ebc19fa3c3f3 100644 --- a/i18npool/source/indexentry/indexentrysupplier_asian.cxx +++ b/i18npool/source/indexentry/indexentrysupplier_asian.cxx @@ -2,9 +2,9 @@ * * $RCSfile: indexentrysupplier_asian.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: khong $ $Date: 2002-05-31 04:51:19 $ + * last change: $Author: khong $ $Date: 2002-06-18 22:29:26 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -62,26 +62,40 @@ #include <indexentrysupplier_asian.hxx> #include <data/indexdata_alphanumeric.h> +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::rtl; + namespace com { namespace sun { namespace star { namespace i18n { -rtl::OUString SAL_CALL IndexEntrySupplier_CJK::getIndexString( const rtl::OUString & rIndexEntry, +OUString SAL_CALL IndexEntrySupplier_CJK::getIndexString( const sal_Unicode ch, const sal_Unicode CJK_idxStr[], const sal_uInt16 idx1[], const sal_uInt16 idx2[]) - throw (com::sun::star::uno::RuntimeException) { - sal_uInt16 ch = *(rIndexEntry.getStr()), first = idx1[ ch >> 8 ]; + throw (RuntimeException) +{ + sal_uInt16 first = idx1[ ch >> 8 ]; return first == 0xFFFF ? // using alphanumeric index for non-define stirng - rtl::OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1) : - rtl::OUString(&CJK_idxStr[idx2[ first + (ch & 0xff) ]]); + OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1) : + OUString(&CJK_idxStr[idx2[ first + (ch & 0xff) ]]); } -rtl::OUString SAL_CALL IndexEntrySupplier_CJK::getIndexString( const rtl::OUString & rIndexEntry, - const sal_uInt16 idx1[], const sal_Unicode idx2[]) - throw (com::sun::star::uno::RuntimeException) { - sal_uInt16 ch = *(rIndexEntry.getStr()), first = idx1[ ch >> 8 ]; +OUString SAL_CALL IndexEntrySupplier_CJK::getIndexString( const sal_Unicode ch, + const sal_uInt16 idx1[], const sal_Unicode idx2[]) throw (RuntimeException) +{ + sal_uInt16 first = idx1[ ch >> 8 ]; return first == 0xFFFF ? // using alphanumeric index for non-define stirng - rtl::OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1) : - rtl::OUString(&idx2[ first + (ch & 0xff) ], 1); + OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1) : + OUString(&idx2[ first + (ch & 0xff) ], 1); +} + +// for CJK we only need to compare index entry, which contains key information in first characters implicitly. +sal_Int16 SAL_CALL IndexEntrySupplier_CJK::compareIndexKey( + const OUString& rIndexEntry1, const OUString& rPhoneticEntry1, const Locale& rLocale1, + const OUString& rIndexEntry2, const OUString& rPhoneticEntry2, const Locale& rLocale2 ) + throw (RuntimeException) +{ + return 0; } } } } } diff --git a/i18npool/source/indexentry/indexentrysupplier_default.cxx b/i18npool/source/indexentry/indexentrysupplier_default.cxx index f7762474be83..012e83105955 100644 --- a/i18npool/source/indexentry/indexentrysupplier_default.cxx +++ b/i18npool/source/indexentry/indexentrysupplier_default.cxx @@ -2,9 +2,9 @@ * * $RCSfile: indexentrysupplier_default.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: er $ $Date: 2002-03-28 00:31:29 $ + * last change: $Author: khong $ $Date: 2002-06-18 22:29:26 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -63,13 +63,81 @@ #include <indexentrysupplier_default.hxx> #include <data/indexdata_unicode.h> +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::rtl; + namespace com { namespace sun { namespace star { namespace i18n { -rtl::OUString SAL_CALL IndexEntrySupplier_Unicode::getIndexCharacter( const rtl::OUString& rIndexEntry, - const lang::Locale& rLocale, const rtl::OUString& rSortAlgorithm ) throw (com::sun::star::uno::RuntimeException) { - sal_uInt16 ch = *(rIndexEntry.getStr()); +IndexEntrySupplier_Unicode::IndexEntrySupplier_Unicode(const Reference < XMultiServiceFactory >& rxMSF) : + IndexEntrySupplier(rxMSF) +{ + implementationName = "com.sun.star.i18n.IndexEntrySupplier_Unicode"; + collator = new CollatorImpl(rxMSF); + usePhonetic = sal_False; +} + +IndexEntrySupplier_Unicode::~IndexEntrySupplier_Unicode() +{ + delete collator; +} + +sal_Bool SAL_CALL IndexEntrySupplier_Unicode::loadAlgorithm( const Locale& rLocale, + const OUString& SortAlgorithm, sal_Int32 collatorOptions ) throw (RuntimeException) +{ + aSortAlgorithm = SortAlgorithm; + aLocale = rLocale; + return collator->loadCollatorAlgorithm(SortAlgorithm, rLocale, collatorOptions) == 0; +} + +const OUString& SAL_CALL IndexEntrySupplier_Unicode::getEntry( const OUString& IndexEntry, + const OUString& PhoneticEntry, const Locale& rLocale ) throw (RuntimeException) +{ + // The condition for using phonetic entry is: + // usePhonetic is set for the algorithm; + // rLocale for phonetic entry is same as aLocale for algorithm, + // which means Chinese phonetic will not be used for Japanese algorithm; + // phonetic entry is not blank. + if (usePhonetic && rLocale == aLocale && PhoneticEntry.getLength() > 0) + return PhoneticEntry; + else + return IndexEntry; +} + +OUString SAL_CALL IndexEntrySupplier_Unicode::getIndexKey( const OUString& IndexEntry, + const OUString& PhoneticEntry, const Locale& rLocale ) throw (RuntimeException) +{ + return getIndexCharacter(getEntry(IndexEntry, PhoneticEntry, rLocale), aLocale, OUString()); +} + +// this method can be overwriten by sub class for better performing key comparison. +sal_Int16 SAL_CALL IndexEntrySupplier_Unicode::compareIndexKey( + const OUString& IndexEntry1, const OUString& PhoneticEntry1, const Locale& rLocale1, + const OUString& IndexEntry2, const OUString& PhoneticEntry2, const Locale& rLocale2 ) + throw (RuntimeException) +{ + return collator->compareString( getIndexKey(IndexEntry1, PhoneticEntry1, rLocale1), + getIndexKey(IndexEntry2, PhoneticEntry2, rLocale2)); +} + +sal_Int16 SAL_CALL IndexEntrySupplier_Unicode::compareIndexEntry( + const OUString& IndexEntry1, const OUString& PhoneticEntry1, const Locale& rLocale1, + const OUString& IndexEntry2, const OUString& PhoneticEntry2, const Locale& rLocale2 ) + throw (RuntimeException) +{ + sal_Int16 result = compareIndexKey( IndexEntry1, PhoneticEntry1, rLocale1, + IndexEntry2, PhoneticEntry2, rLocale2); + if (result == 0) + return collator->compareString( getEntry(IndexEntry1, PhoneticEntry1, rLocale1), + getEntry(IndexEntry2, PhoneticEntry2, rLocale2)); + return 0; +} + +OUString SAL_CALL IndexEntrySupplier_Unicode::getIndexCharacter( const OUString& rIndexEntry, + const Locale& rLocale, const OUString& rSortAlgorithm ) throw (RuntimeException) { + sal_uInt16 ch = rIndexEntry.toChar(); sal_uInt16 address = idx[ch >> 8]; - return rtl::OUString((address != 0xFFFF ? &idxStr[address + (ch & 0xFF)] : &ch), 1); + return OUString((address != 0xFFFF ? &idxStr[address + (ch & 0xFF)] : &ch), 1); } } } } } diff --git a/i18npool/source/indexentry/indexentrysupplier_ja_phonetic.cxx b/i18npool/source/indexentry/indexentrysupplier_ja_phonetic.cxx index ab3c1767a08e..82981a324ddd 100644 --- a/i18npool/source/indexentry/indexentrysupplier_ja_phonetic.cxx +++ b/i18npool/source/indexentry/indexentrysupplier_ja_phonetic.cxx @@ -2,9 +2,9 @@ * * $RCSfile: indexentrysupplier_ja_phonetic.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: khong $Date: 2002/05/24 22:35:58 $ + * last change: $Author: khong $Date: 2002/05/31 04:51:19 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -67,7 +67,7 @@ namespace com { namespace sun { namespace star { namespace i18n { rtl::OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexCharacter( const rtl::OUString& rIndexEntry, const lang::Locale& rLocale, const rtl::OUString& rSortAlgorithm ) throw (com::sun::star::uno::RuntimeException) { - return getIndexString(rIndexEntry, idx1, idx2); + return IndexEntrySupplier_CJK::getIndexString(rIndexEntry.toChar(), idx1, idx2); } } } } } |