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/source/indexentry/indexentrysupplier_default.cxx | |
parent | c2adf960d7ffa5e4609aea4f59684d87618909d9 (diff) |
#99877#First implementation for XExtendedIndexEntrySupplier
Diffstat (limited to 'i18npool/source/indexentry/indexentrysupplier_default.cxx')
-rw-r--r-- | i18npool/source/indexentry/indexentrysupplier_default.cxx | 80 |
1 files changed, 74 insertions, 6 deletions
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); } } } } } |