Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / i18npool / source / indexentry / indexentrysupplier_ja_phonetic.cxx
blobec0dc421a4e9cf57969041f77fdd8d12cc8eaced
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <indexentrysupplier_ja_phonetic.hxx>
22 #include <data/indexdata_alphanumeric.h>
23 #include <data/indexdata_ja_phonetic.h>
24 #include <string.h>
26 using namespace ::rtl;
28 namespace com { namespace sun { namespace star { namespace i18n {
30 OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexCharacter( const OUString& rIndexEntry,
31 const lang::Locale& /*rLocale*/, const OUString& /*rSortAlgorithm*/ )
32 throw (com::sun::star::uno::RuntimeException)
34 sal_Unicode ch=rIndexEntry.toChar();
35 sal_uInt16 first = idx[ ch >> 8 ];
36 if (first == 0xFFFF) {
37 // using alphanumeric index for non-define stirng
38 return OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1);
39 } else {
40 sal_Unicode *idx2 = strstr(implementationName, "syllable") ? syllable : consonant;
41 return OUString(&idx2[ first + (ch & 0xff) ], 1);
45 OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexKey( const OUString& IndexEntry,
46 const OUString& PhoneticEntry, const lang::Locale& rLocale )
47 throw (com::sun::star::uno::RuntimeException)
49 return getIndexCharacter( PhoneticEntry.isEmpty() ? IndexEntry : PhoneticEntry , rLocale, OUString());
52 sal_Int16 SAL_CALL IndexEntrySupplier_ja_phonetic::compareIndexEntry(
53 const OUString& IndexEntry1, const OUString& PhoneticEntry1, const lang::Locale& rLocale1,
54 const OUString& IndexEntry2, const OUString& PhoneticEntry2, const lang::Locale& rLocale2 )
55 throw (com::sun::star::uno::RuntimeException)
57 sal_Int16 result = sal::static_int_cast<sal_Int16>( collator->compareString(
58 IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry1, PhoneticEntry1, rLocale1),
59 IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry2, PhoneticEntry2, rLocale2)) );
61 if (result == 0)
62 return IndexEntrySupplier_Common::compareIndexEntry(
63 IndexEntry1, PhoneticEntry1, rLocale1,
64 IndexEntry2, PhoneticEntry2, rLocale2);
65 return result;
68 static sal_Char first[] = "ja_phonetic (alphanumeric first)";
69 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_syllable::loadAlgorithm(
70 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
71 sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
73 return collator->loadCollatorAlgorithm(OUString::createFromAscii(first), rLocale, collatorOptions) == 0;
75 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_consonant::loadAlgorithm(
76 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
77 sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
79 return collator->loadCollatorAlgorithm(OUString::createFromAscii(first), rLocale, collatorOptions) == 0;
82 static sal_Char last[] = "ja_phonetic (alphanumeric last)";
83 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_syllable::loadAlgorithm(
84 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
85 sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
87 return collator->loadCollatorAlgorithm(OUString::createFromAscii(last), rLocale, collatorOptions) == 0;
89 sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_consonant::loadAlgorithm(
90 const com::sun::star::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/,
91 sal_Int32 collatorOptions ) throw (com::sun::star::uno::RuntimeException)
93 return collator->loadCollatorAlgorithm(OUString::createFromAscii(last), rLocale, collatorOptions) == 0;
96 } } } }
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */