| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | /* |
| 3 | * This file is part of the LibreOffice project. |
| 4 | * |
| 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/. |
| 8 | * |
| 9 | * This file incorporates work covered by the following license notice: |
| 10 | * |
| 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 . |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #include <indexentrysupplier_ja_phonetic.hxx> |
| 22 | #include <collatorImpl.hxx> |
| 23 | #include "data/indexdata_alphanumeric.h" |
| 24 | #include "data/indexdata_ja_phonetic.h" |
| 25 | #include <string.h> |
| 26 | |
| 27 | namespace i18npool { |
| 28 | |
| 29 | OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexCharacter( const OUString& rIndexEntry, |
| 30 | const css::lang::Locale& /*rLocale*/, const OUString& /*rSortAlgorithm*/ ) |
| 31 | { |
| 32 | sal_Unicode ch=rIndexEntry.toChar(); |
| 33 | sal_uInt16 first = idx[ ch >> 8 ]; |
| 34 | if (first == 0xFFFF) { |
| 35 | // using alphanumeric index for non-define string |
| 36 | return OUString(&idxStr[(ch & 0xFF00) ? 0 : ch], 1); |
| 37 | } else { |
| 38 | const sal_Unicode *idx2 = strstr(implementationName, "syllable") ? syllable : consonant; |
| 39 | return OUString(&idx2[ first + (ch & 0xff) ], 1); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | OUString SAL_CALL IndexEntrySupplier_ja_phonetic::getIndexKey( const OUString& IndexEntry, |
| 44 | const OUString& PhoneticEntry, const css::lang::Locale& rLocale ) |
| 45 | { |
| 46 | return getIndexCharacter( PhoneticEntry.isEmpty() ? IndexEntry : PhoneticEntry , rLocale, OUString()); |
| 47 | } |
| 48 | |
| 49 | sal_Int16 SAL_CALL IndexEntrySupplier_ja_phonetic::compareIndexEntry( |
| 50 | const OUString& IndexEntry1, const OUString& PhoneticEntry1, const css::lang::Locale& rLocale1, |
| 51 | const OUString& IndexEntry2, const OUString& PhoneticEntry2, const css::lang::Locale& rLocale2 ) |
| 52 | { |
| 53 | sal_Int16 result = sal::static_int_cast<sal_Int16>( collator->compareString( |
| 54 | IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry1, PhoneticEntry1, rLocale1), |
| 55 | IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry2, PhoneticEntry2, rLocale2)) ); |
| 56 | |
| 57 | if (result == 0) |
| 58 | return IndexEntrySupplier_Common::compareIndexEntry( |
| 59 | IndexEntry1, PhoneticEntry1, rLocale1, |
| 60 | IndexEntry2, PhoneticEntry2, rLocale2); |
| 61 | return result; |
| 62 | } |
| 63 | |
| 64 | constexpr OUString first = u"phonetic (alphanumeric first)"_ustr; |
| 65 | sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_syllable::loadAlgorithm( |
| 66 | const css::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/, |
| 67 | sal_Int32 collatorOptions ) |
| 68 | { |
| 69 | return collator->loadCollatorAlgorithm(first, rLocale, collatorOptions) == 0; |
| 70 | } |
| 71 | sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_consonant::loadAlgorithm( |
| 72 | const css::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/, |
| 73 | sal_Int32 collatorOptions ) |
| 74 | { |
| 75 | return collator->loadCollatorAlgorithm(first, rLocale, collatorOptions) == 0; |
| 76 | } |
| 77 | |
| 78 | constexpr OUString last = u"phonetic (alphanumeric last)"_ustr; |
| 79 | sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_syllable::loadAlgorithm( |
| 80 | const css::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/, |
| 81 | sal_Int32 collatorOptions ) |
| 82 | { |
| 83 | return collator->loadCollatorAlgorithm(last, rLocale, collatorOptions) == 0; |
| 84 | } |
| 85 | sal_Bool SAL_CALL IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_consonant::loadAlgorithm( |
| 86 | const css::lang::Locale& rLocale, const OUString& /*SortAlgorithm*/, |
| 87 | sal_Int32 collatorOptions ) |
| 88 | { |
| 89 | return collator->loadCollatorAlgorithm(last, rLocale, collatorOptions) == 0; |
| 90 | } |
| 91 | |
| 92 | } |
| 93 | |
| 94 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |