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 .
20 #include <collatorImpl.hxx>
21 #include <indexentrysupplier_common.hxx>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <localedata.hxx>
24 #include <o3tl/temporary.hxx>
26 using namespace ::com::sun::star::uno
;
27 using namespace ::com::sun::star
;
31 IndexEntrySupplier_Common::IndexEntrySupplier_Common(const Reference
< uno::XComponentContext
>& rxContext
)
33 implementationName
= "com.sun.star.i18n.IndexEntrySupplier_Common";
34 collator
= new CollatorImpl(rxContext
);
38 IndexEntrySupplier_Common::~IndexEntrySupplier_Common()
42 Sequence
< lang::Locale
> SAL_CALL
IndexEntrySupplier_Common::getLocaleList()
44 throw RuntimeException();
47 Sequence
< OUString
> SAL_CALL
IndexEntrySupplier_Common::getAlgorithmList( const lang::Locale
& )
49 throw RuntimeException();
52 OUString SAL_CALL
IndexEntrySupplier_Common::getPhoneticCandidate( const OUString
&,
58 sal_Bool SAL_CALL
IndexEntrySupplier_Common::usePhoneticEntry( const lang::Locale
& )
60 throw RuntimeException();
63 sal_Bool SAL_CALL
IndexEntrySupplier_Common::loadAlgorithm( const lang::Locale
& rLocale
,
64 const OUString
& rAlgorithm
, sal_Int32 collatorOptions
)
66 usePhonetic
= LocaleDataImpl::get()->isPhonetic(rLocale
, rAlgorithm
);
67 collator
->loadCollatorAlgorithm(rAlgorithm
, rLocale
, collatorOptions
);
69 aAlgorithm
= rAlgorithm
;
73 OUString SAL_CALL
IndexEntrySupplier_Common::getIndexKey( const OUString
& rIndexEntry
,
74 const OUString
&, const lang::Locale
& )
76 sal_uInt32 indexChar
=rIndexEntry
.iterateCodePoints(&o3tl::temporary(sal_Int32(0)), 0);
77 return OUString(&indexChar
, 1);
80 sal_Int16 SAL_CALL
IndexEntrySupplier_Common::compareIndexEntry(
81 const OUString
& rIndexEntry1
, const OUString
&, const lang::Locale
&,
82 const OUString
& rIndexEntry2
, const OUString
&, const lang::Locale
& )
84 return sal::static_int_cast
< sal_Int16
>(
85 collator
->compareString(rIndexEntry1
, rIndexEntry2
));
86 // return value of compareString in { -1, 0, 1 }
89 OUString SAL_CALL
IndexEntrySupplier_Common::getIndexCharacter( const OUString
& rIndexEntry
,
90 const lang::Locale
& rLocale
, const OUString
& )
92 return getIndexKey(rIndexEntry
, rIndexEntry
, rLocale
);
95 OUString SAL_CALL
IndexEntrySupplier_Common::getIndexFollowPageWord( sal_Bool
,
98 throw RuntimeException();
102 IndexEntrySupplier_Common::getEntry( const OUString
& IndexEntry
,
103 const OUString
& PhoneticEntry
, const lang::Locale
& rLocale
) const
105 // The condition for using phonetic entry is:
106 // usePhonetic is set for the algorithm;
107 // rLocale for phonetic entry is same as aLocale for algorithm,
108 // which means Chinese phonetic will not be used for Japanese algorithm;
109 // phonetic entry is not blank.
110 if (usePhonetic
&& !PhoneticEntry
.isEmpty() && rLocale
.Language
== aLocale
.Language
&&
111 rLocale
.Country
== aLocale
.Country
&& rLocale
.Variant
== aLocale
.Variant
)
112 return PhoneticEntry
;
118 IndexEntrySupplier_Common::getImplementationName()
120 return OUString::createFromAscii( implementationName
);
124 IndexEntrySupplier_Common::supportsService(const OUString
& rServiceName
)
126 return cppu::supportsService(this, rServiceName
);
129 Sequence
< OUString
> SAL_CALL
130 IndexEntrySupplier_Common::getSupportedServiceNames()
132 Sequence
< OUString
> aRet
{ OUString::createFromAscii( implementationName
) };
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */