Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / i18npool / source / indexentry / indexentrysupplier_ja_phonetic.cxx
blob1d44ba958fe311f896ec9fce0c16f83f09d7e656
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <indexentrysupplier_ja_phonetic.hxx>
31 #include <data/indexdata_alphanumeric.h>
32 #include <data/indexdata_ja_phonetic.h>
33 #include <string.h>
35 using namespace ::rtl;
37 namespace com { namespace sun { namespace star { namespace i18n {
39 OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexCharacter( const OUString& rIndexEntry,
40 const lang::Locale& /*rLocale*/, const OUString& /*rSortAlgorithm*/ )
41 throw (com::sun::star::uno::RuntimeException)
43 sal_Unicode ch=rIndexEntry.toChar();
44 sal_uInt16 first = idx[ ch >> 8 ];
45 if (first == 0xFFFF) {
46 // using alphanumeric index for non-define stirng
47 return OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1);
48 } else {
49 sal_Unicode *idx2 = strstr(implementationName, "syllable") ? syllable : consonant;
50 return OUString(&idx2[ first + (ch & 0xff) ], 1);
54 OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexKey( const OUString& IndexEntry,
55 const OUString& PhoneticEntry, const lang::Locale& rLocale )
56 throw (com::sun::star::uno::RuntimeException)
58 return getIndexCharacter( PhoneticEntry.isEmpty() ? IndexEntry : PhoneticEntry , rLocale, OUString());
61 sal_Int16 SAL_CALL IndexEntrySupplier_ja_phonetic::compareIndexEntry(
62 const OUString& IndexEntry1, const OUString& PhoneticEntry1, const lang::Locale& rLocale1,
63 const OUString& IndexEntry2, const OUString& PhoneticEntry2, const lang::Locale& rLocale2 )
64 throw (com::sun::star::uno::RuntimeException)
66 sal_Int16 result = sal::static_int_cast<sal_Int16>( collator->compareString(
67 IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry1, PhoneticEntry1, rLocale1),
68 IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry2, PhoneticEntry2, rLocale2)) );
70 if (result == 0)
71 return IndexEntrySupplier_Common::compareIndexEntry(
72 IndexEntry1, PhoneticEntry1, rLocale1,
73 IndexEntry2, PhoneticEntry2, rLocale2);
74 return result;
77 static sal_Char first[] = "ja_phonetic (alphanumeric first)";
78 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_syllable::loadAlgorithm(
79 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
80 sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
82 return collator->loadCollatorAlgorithm(OUString::createFromAscii(first), rLocale, collatorOptions) == 0;
84 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_consonant::loadAlgorithm(
85 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
86 sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
88 return collator->loadCollatorAlgorithm(OUString::createFromAscii(first), rLocale, collatorOptions) == 0;
91 static sal_Char last[] = "ja_phonetic (alphanumeric last)";
92 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_syllable::loadAlgorithm(
93 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
94 sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
96 return collator->loadCollatorAlgorithm(OUString::createFromAscii(last), rLocale, collatorOptions) == 0;
98 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_consonant::loadAlgorithm(
99 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
100 sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
102 return collator->loadCollatorAlgorithm(OUString::createFromAscii(last), rLocale, collatorOptions) == 0;
105 } } } }
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */