1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_i18npool.hxx" 26 27 #include <indexentrysupplier_ja_phonetic.hxx> 28 #include <data/indexdata_alphanumeric.h> 29 #include <data/indexdata_ja_phonetic.h> 30 #include <string.h> 31 32 using namespace ::rtl; 33 34 namespace com { namespace sun { namespace star { namespace i18n { 35 36 OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexCharacter( const OUString& rIndexEntry, 37 const lang::Locale& /*rLocale*/, const OUString& /*rSortAlgorithm*/ ) 38 { 39 sal_Unicode ch=rIndexEntry.toChar(); 40 sal_uInt16 first = idx[ ch >> 8 ]; 41 if (first == 0xFFFF) { 42 // using alphanumeric index for non-define string 43 return OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1); 44 } else { 45 sal_Unicode *idx2 = strstr(implementationName, "syllable") ? syllable : consonant; 46 return OUString(&idx2[ first + (ch & 0xff) ], 1); 47 } 48 } 49 50 OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexKey( const OUString& IndexEntry, 51 const OUString& PhoneticEntry, const lang::Locale& rLocale ) 52 { 53 return getIndexCharacter( PhoneticEntry.getLength() > 0 ? PhoneticEntry : IndexEntry, rLocale, OUString()); 54 } 55 56 sal_Int16 SAL_CALL IndexEntrySupplier_ja_phonetic::compareIndexEntry( 57 const OUString& IndexEntry1, const OUString& PhoneticEntry1, const lang::Locale& rLocale1, 58 const OUString& IndexEntry2, const OUString& PhoneticEntry2, const lang::Locale& rLocale2 ) 59 { 60 sal_Int16 result = sal::static_int_cast<sal_Int16>( collator->compareString( 61 IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry1, PhoneticEntry1, rLocale1), 62 IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry2, PhoneticEntry2, rLocale2)) ); 63 64 if (result == 0) 65 return IndexEntrySupplier_Common::compareIndexEntry( 66 IndexEntry1, PhoneticEntry1, rLocale1, 67 IndexEntry2, PhoneticEntry2, rLocale2); 68 return result; 69 } 70 71 static sal_Char first[] = "ja_phonetic (alphanumeric first)"; 72 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_syllable::loadAlgorithm( 73 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/, 74 sal_Int32 collatorOptions ) 75 { 76 return collator->loadCollatorAlgorithm(OUString::createFromAscii(first), rLocale, collatorOptions) == 0; 77 } 78 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_consonant::loadAlgorithm( 79 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/, 80 sal_Int32 collatorOptions ) 81 { 82 return collator->loadCollatorAlgorithm(OUString::createFromAscii(first), rLocale, collatorOptions) == 0; 83 } 84 85 static sal_Char last[] = "ja_phonetic (alphanumeric last)"; 86 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_syllable::loadAlgorithm( 87 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/, 88 sal_Int32 collatorOptions ) 89 { 90 return collator->loadCollatorAlgorithm(OUString::createFromAscii(last), rLocale, collatorOptions) == 0; 91 } 92 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_consonant::loadAlgorithm( 93 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/, 94 sal_Int32 collatorOptions ) 95 { 96 return collator->loadCollatorAlgorithm(OUString::createFromAscii(last), rLocale, collatorOptions) == 0; 97 } 98 99 } } } } 100