1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <collatorImpl.hxx>
23 #include "data/indexdata_alphanumeric.h"
24 #include "data/indexdata_ja_phonetic.h"
27 using namespace ::com::sun::star::i18n
;
31 OUString SAL_CALL
IndexEntrySupplier_ja_phonetic::getIndexCharacter( const OUString
& rIndexEntry
,
32 const css::lang::Locale
& /*rLocale*/, const OUString
& /*rSortAlgorithm*/ )
34 sal_Unicode ch
=rIndexEntry
.toChar();
35 sal_uInt16 first
= idx
[ ch
>> 8 ];
36 if (first
== 0xFFFF) {
37 // using alphanumeric index for non-define string
38 return OUString(&idxStr
[(ch
& 0xFF00) ? 0 : ch
], 1);
40 const 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 css::lang::Locale
& rLocale
)
48 return getIndexCharacter( PhoneticEntry
.isEmpty() ? IndexEntry
: PhoneticEntry
, rLocale
, OUString());
51 sal_Int16 SAL_CALL
IndexEntrySupplier_ja_phonetic::compareIndexEntry(
52 const OUString
& IndexEntry1
, const OUString
& PhoneticEntry1
, const css::lang::Locale
& rLocale1
,
53 const OUString
& IndexEntry2
, const OUString
& PhoneticEntry2
, const css::lang::Locale
& rLocale2
)
55 sal_Int16 result
= sal::static_int_cast
<sal_Int16
>( collator
->compareString(
56 IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry1
, PhoneticEntry1
, rLocale1
),
57 IndexEntrySupplier_ja_phonetic::getIndexKey(IndexEntry2
, PhoneticEntry2
, rLocale2
)) );
60 return IndexEntrySupplier_Common::compareIndexEntry(
61 IndexEntry1
, PhoneticEntry1
, rLocale1
,
62 IndexEntry2
, PhoneticEntry2
, rLocale2
);
66 static const sal_Char first
[] = "ja_phonetic (alphanumeric first)";
67 sal_Bool SAL_CALL
IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_syllable::loadAlgorithm(
68 const css::lang::Locale
& rLocale
, const OUString
& /*SortAlgorithm*/,
69 sal_Int32 collatorOptions
)
71 return collator
->loadCollatorAlgorithm(first
, rLocale
, collatorOptions
) == 0;
73 sal_Bool SAL_CALL
IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_consonant::loadAlgorithm(
74 const css::lang::Locale
& rLocale
, const OUString
& /*SortAlgorithm*/,
75 sal_Int32 collatorOptions
)
77 return collator
->loadCollatorAlgorithm(first
, rLocale
, collatorOptions
) == 0;
80 static const sal_Char last
[] = "ja_phonetic (alphanumeric last)";
81 sal_Bool SAL_CALL
IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_syllable::loadAlgorithm(
82 const css::lang::Locale
& rLocale
, const OUString
& /*SortAlgorithm*/,
83 sal_Int32 collatorOptions
)
85 return collator
->loadCollatorAlgorithm(last
, rLocale
, collatorOptions
) == 0;
87 sal_Bool SAL_CALL
IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_consonant::loadAlgorithm(
88 const css::lang::Locale
& rLocale
, const OUString
& /*SortAlgorithm*/,
89 sal_Int32 collatorOptions
)
91 return collator
->loadCollatorAlgorithm(last
, rLocale
, collatorOptions
) == 0;
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */