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