1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_i18npool.hxx"
30 
31 #include <indexentrysupplier_ja_phonetic.hxx>
32 #include <data/indexdata_alphanumeric.h>
33 #include <data/indexdata_ja_phonetic.h>
34 #include <string.h>
35 
36 using namespace ::rtl;
37 
38 namespace com { namespace sun { namespace star { namespace i18n {
39 
40 OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexCharacter( const OUString& rIndexEntry,
41 	const lang::Locale& /*rLocale*/, const OUString& /*rSortAlgorithm*/ )
42 	throw (com::sun::star::uno::RuntimeException)
43 {
44     sal_Unicode ch=rIndexEntry.toChar();
45 	sal_uInt16 first = idx[ ch >> 8 ];
46     if (first == 0xFFFF) {
47 	    // using alphanumeric index for non-define stirng
48 	    return OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1);
49     } else {
50         sal_Unicode *idx2 = strstr(implementationName, "syllable") ? syllable : consonant;
51         return OUString(&idx2[ first + (ch & 0xff) ], 1);
52     }
53 }
54 
55 OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexKey( const OUString& IndexEntry,
56 	const OUString& PhoneticEntry, const lang::Locale& rLocale )
57 	throw (com::sun::star::uno::RuntimeException)
58 {
59 	return getIndexCharacter( PhoneticEntry.getLength() > 0 ? PhoneticEntry : IndexEntry, rLocale, OUString());
60 }
61 
62 sal_Int16 SAL_CALL IndexEntrySupplier_ja_phonetic::compareIndexEntry(
63 	const OUString& IndexEntry1, const OUString& PhoneticEntry1, const lang::Locale& rLocale1,
64 	const OUString& IndexEntry2, const OUString& PhoneticEntry2, const lang::Locale& rLocale2 )
65 	throw (com::sun::star::uno::RuntimeException)
66 {
67 	sal_Int16 result = sal::static_int_cast<sal_Int16>( collator->compareString(
68 		IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry1, PhoneticEntry1, rLocale1),
69 		IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry2, PhoneticEntry2, rLocale2)) );
70 
71 	if (result == 0)
72         return IndexEntrySupplier_Common::compareIndexEntry(
73                     IndexEntry1, PhoneticEntry1, rLocale1,
74                     IndexEntry2, PhoneticEntry2, rLocale2);
75     return result;
76 }
77 
78 static sal_Char first[] = "ja_phonetic (alphanumeric first)";
79 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_syllable::loadAlgorithm(
80 	const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
81 	sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
82 {
83 	return collator->loadCollatorAlgorithm(OUString::createFromAscii(first), rLocale, collatorOptions) == 0;
84 }
85 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_consonant::loadAlgorithm(
86 	const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
87 	sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
88 {
89 	return collator->loadCollatorAlgorithm(OUString::createFromAscii(first), rLocale, collatorOptions) == 0;
90 }
91 
92 static sal_Char last[] = "ja_phonetic (alphanumeric last)";
93 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_syllable::loadAlgorithm(
94 	const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
95 	sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
96 {
97 	return collator->loadCollatorAlgorithm(OUString::createFromAscii(last), rLocale, collatorOptions) == 0;
98 }
99 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_consonant::loadAlgorithm(
100 	const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
101 	sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
102 {
103 	return collator->loadCollatorAlgorithm(OUString::createFromAscii(last), rLocale, collatorOptions) == 0;
104 }
105 
106 } } } }
107