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
getIndexCharacter(const OUString & rIndexEntry,const lang::Locale &,const OUString &)36 OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexCharacter( const OUString& rIndexEntry,
37 const lang::Locale& /*rLocale*/, const OUString& /*rSortAlgorithm*/ )
38 throw (com::sun::star::uno::RuntimeException)
39 {
40 sal_Unicode ch=rIndexEntry.toChar();
41 sal_uInt16 first = idx[ ch >> 8 ];
42 if (first == 0xFFFF) {
43 // using alphanumeric index for non-define stirng
44 return OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1);
45 } else {
46 sal_Unicode *idx2 = strstr(implementationName, "syllable") ? syllable : consonant;
47 return OUString(&idx2[ first + (ch & 0xff) ], 1);
48 }
49 }
50
getIndexKey(const OUString & IndexEntry,const OUString & PhoneticEntry,const lang::Locale & rLocale)51 OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexKey( const OUString& IndexEntry,
52 const OUString& PhoneticEntry, const lang::Locale& rLocale )
53 throw (com::sun::star::uno::RuntimeException)
54 {
55 return getIndexCharacter( PhoneticEntry.getLength() > 0 ? PhoneticEntry : IndexEntry, rLocale, OUString());
56 }
57
compareIndexEntry(const OUString & IndexEntry1,const OUString & PhoneticEntry1,const lang::Locale & rLocale1,const OUString & IndexEntry2,const OUString & PhoneticEntry2,const lang::Locale & rLocale2)58 sal_Int16 SAL_CALL IndexEntrySupplier_ja_phonetic::compareIndexEntry(
59 const OUString& IndexEntry1, const OUString& PhoneticEntry1, const lang::Locale& rLocale1,
60 const OUString& IndexEntry2, const OUString& PhoneticEntry2, const lang::Locale& rLocale2 )
61 throw (com::sun::star::uno::RuntimeException)
62 {
63 sal_Int16 result = sal::static_int_cast<sal_Int16>( collator->compareString(
64 IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry1, PhoneticEntry1, rLocale1),
65 IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry2, PhoneticEntry2, rLocale2)) );
66
67 if (result == 0)
68 return IndexEntrySupplier_Common::compareIndexEntry(
69 IndexEntry1, PhoneticEntry1, rLocale1,
70 IndexEntry2, PhoneticEntry2, rLocale2);
71 return result;
72 }
73
74 static sal_Char first[] = "ja_phonetic (alphanumeric first)";
loadAlgorithm(const com::sun::star::lang::Locale & rLocale,const OUString &,sal_Int32 collatorOptions)75 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_syllable::loadAlgorithm(
76 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
77 sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
78 {
79 return collator->loadCollatorAlgorithm(OUString::createFromAscii(first), rLocale, collatorOptions) == 0;
80 }
loadAlgorithm(const com::sun::star::lang::Locale & rLocale,const OUString &,sal_Int32 collatorOptions)81 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_consonant::loadAlgorithm(
82 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
83 sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
84 {
85 return collator->loadCollatorAlgorithm(OUString::createFromAscii(first), rLocale, collatorOptions) == 0;
86 }
87
88 static sal_Char last[] = "ja_phonetic (alphanumeric last)";
loadAlgorithm(const com::sun::star::lang::Locale & rLocale,const OUString &,sal_Int32 collatorOptions)89 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_syllable::loadAlgorithm(
90 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
91 sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
92 {
93 return collator->loadCollatorAlgorithm(OUString::createFromAscii(last), rLocale, collatorOptions) == 0;
94 }
loadAlgorithm(const com::sun::star::lang::Locale & rLocale,const OUString &,sal_Int32 collatorOptions)95 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_consonant::loadAlgorithm(
96 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
97 sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
98 {
99 return collator->loadCollatorAlgorithm(OUString::createFromAscii(last), rLocale, collatorOptions) == 0;
100 }
101
102 } } } }
103