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 <indexentrysupplier_common.hxx>
21 #include <com/sun/star/i18n/CollatorOptions.hpp>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <localedata.hxx>
25 using namespace ::com::sun::star::uno
;
26 using namespace ::com::sun::star
;
28 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
30 IndexEntrySupplier_Common::IndexEntrySupplier_Common(const Reference
< uno::XComponentContext
>& rxContext
)
32 implementationName
= "com.sun.star.i18n.IndexEntrySupplier_Common";
33 collator
= new CollatorImpl(rxContext
);
37 IndexEntrySupplier_Common::~IndexEntrySupplier_Common()
42 Sequence
< lang::Locale
> SAL_CALL
IndexEntrySupplier_Common::getLocaleList() throw (RuntimeException
, std::exception
)
44 throw RuntimeException();
47 Sequence
< OUString
> SAL_CALL
IndexEntrySupplier_Common::getAlgorithmList( const lang::Locale
& ) throw (RuntimeException
, std::exception
)
49 throw RuntimeException();
52 OUString SAL_CALL
IndexEntrySupplier_Common::getPhoneticCandidate( const OUString
&,
53 const lang::Locale
& ) throw (RuntimeException
, std::exception
)
58 sal_Bool SAL_CALL
IndexEntrySupplier_Common::usePhoneticEntry( const lang::Locale
& ) throw (RuntimeException
, std::exception
)
60 throw RuntimeException();
63 sal_Bool SAL_CALL
IndexEntrySupplier_Common::loadAlgorithm( const lang::Locale
& rLocale
,
64 const OUString
& rAlgorithm
, sal_Int32 collatorOptions
) throw (RuntimeException
, std::exception
)
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
& ) throw (RuntimeException
, std::exception
)
77 sal_uInt32 indexChar
=rIndexEntry
.iterateCodePoints(&nPos
, 0);
78 return OUString(&indexChar
, 1);
81 sal_Int16 SAL_CALL
IndexEntrySupplier_Common::compareIndexEntry(
82 const OUString
& rIndexEntry1
, const OUString
&, const lang::Locale
&,
83 const OUString
& rIndexEntry2
, const OUString
&, const lang::Locale
& )
84 throw (RuntimeException
, std::exception
)
86 return sal::static_int_cast
< sal_Int16
>(
87 collator
->compareString(rIndexEntry1
, rIndexEntry2
));
88 // return value of compareString in { -1, 0, 1 }
91 OUString SAL_CALL
IndexEntrySupplier_Common::getIndexCharacter( const OUString
& rIndexEntry
,
92 const lang::Locale
& rLocale
, const OUString
& ) throw (RuntimeException
, std::exception
)
94 return getIndexKey(rIndexEntry
, rIndexEntry
, rLocale
);
97 OUString SAL_CALL
IndexEntrySupplier_Common::getIndexFollowPageWord( sal_Bool
,
98 const lang::Locale
& ) throw (RuntimeException
, std::exception
)
100 throw RuntimeException();
103 const OUString
& SAL_CALL
104 IndexEntrySupplier_Common::getEntry( const OUString
& IndexEntry
,
105 const OUString
& PhoneticEntry
, const lang::Locale
& rLocale
) throw (RuntimeException
)
107 // The condition for using phonetic entry is:
108 // usePhonetic is set for the algorithm;
109 // rLocale for phonetic entry is same as aLocale for algorithm,
110 // which means Chinese phonetic will not be used for Japanese algorithm;
111 // phonetic entry is not blank.
112 if (usePhonetic
&& !PhoneticEntry
.isEmpty() && rLocale
.Language
== aLocale
.Language
&&
113 rLocale
.Country
== aLocale
.Country
&& rLocale
.Variant
== aLocale
.Variant
)
114 return PhoneticEntry
;
120 IndexEntrySupplier_Common::getImplementationName() throw( RuntimeException
, std::exception
)
122 return OUString::createFromAscii( implementationName
);
126 IndexEntrySupplier_Common::supportsService(const OUString
& rServiceName
) throw( RuntimeException
, std::exception
)
128 return cppu::supportsService(this, rServiceName
);
131 Sequence
< OUString
> SAL_CALL
132 IndexEntrySupplier_Common::getSupportedServiceNames() throw( RuntimeException
, std::exception
)
134 Sequence
< OUString
> aRet
{ OUString::createFromAscii( implementationName
) };
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */