merged tag ooo/OOO330_m14
[LibreOffice.git] / i18npool / source / indexentry / indexentrysupplier_ja_phonetic.cxx
blobbfc23d100ea3207a64e17a3e5cf4c4294f878cf0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_i18npool.hxx"
31 #include <indexentrysupplier_ja_phonetic.hxx>
32 #include <data/indexdata_alphanumeric.h>
33 #include <data/indexdata_ja_phonetic.h>
34 #include <string.h>
36 using namespace ::rtl;
38 namespace com { namespace sun { namespace star { namespace i18n {
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)
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);
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)
59 return getIndexCharacter( PhoneticEntry.getLength() > 0 ? PhoneticEntry : IndexEntry, rLocale, OUString());
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)
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)) );
71 if (result == 0)
72 return IndexEntrySupplier_Common::compareIndexEntry(
73 IndexEntry1, PhoneticEntry1, rLocale1,
74 IndexEntry2, PhoneticEntry2, rLocale2);
75 return result;
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)
83 return collator->loadCollatorAlgorithm(OUString::createFromAscii(first), rLocale, collatorOptions) == 0;
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)
89 return collator->loadCollatorAlgorithm(OUString::createFromAscii(first), rLocale, collatorOptions) == 0;
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)
97 return collator->loadCollatorAlgorithm(OUString::createFromAscii(last), rLocale, collatorOptions) == 0;
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)
103 return collator->loadCollatorAlgorithm(OUString::createFromAscii(last), rLocale, collatorOptions) == 0;
106 } } } }