LibreOffice Module i18npool (master) 1
indexentrysupplier_common.cxx
Go to the documentation of this file.
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#include <collatorImpl.hxx>
23#include <localedata.hxx>
24#include <o3tl/temporary.hxx>
25
26using namespace ::com::sun::star::uno;
27using namespace ::com::sun::star;
28
29namespace i18npool {
30
31IndexEntrySupplier_Common::IndexEntrySupplier_Common(const Reference < uno::XComponentContext >& rxContext)
32{
33 implementationName = "com.sun.star.i18n.IndexEntrySupplier_Common";
34 collator = new CollatorImpl(rxContext);
35 usePhonetic = false;
36}
37
39{
40}
41
42Sequence < lang::Locale > SAL_CALL IndexEntrySupplier_Common::getLocaleList()
43{
44 throw RuntimeException();
45}
46
47Sequence < OUString > SAL_CALL IndexEntrySupplier_Common::getAlgorithmList( const lang::Locale& )
48{
49 throw RuntimeException();
50}
51
52OUString SAL_CALL IndexEntrySupplier_Common::getPhoneticCandidate( const OUString&,
53 const lang::Locale& )
54{
55 return OUString();
56}
57
59{
60 throw RuntimeException();
61}
62
63sal_Bool SAL_CALL IndexEntrySupplier_Common::loadAlgorithm( const lang::Locale& rLocale,
64 const OUString& rAlgorithm, sal_Int32 collatorOptions )
65{
66 usePhonetic = LocaleDataImpl::get()->isPhonetic(rLocale, rAlgorithm);
67 collator->loadCollatorAlgorithm(rAlgorithm, rLocale, collatorOptions);
68 aLocale = rLocale;
69 aAlgorithm = rAlgorithm;
70 return true;
71}
72
73OUString SAL_CALL IndexEntrySupplier_Common::getIndexKey( const OUString& rIndexEntry,
74 const OUString&, const lang::Locale& )
75{
76 sal_uInt32 indexChar=rIndexEntry.iterateCodePoints(&o3tl::temporary(sal_Int32(0)), 0);
77 return OUString(&indexChar, 1);
78}
79
81 const OUString& rIndexEntry1, const OUString&, const lang::Locale&,
82 const OUString& rIndexEntry2, const OUString&, const lang::Locale& )
83{
84 return sal::static_int_cast< sal_Int16 >(
85 collator->compareString(rIndexEntry1, rIndexEntry2));
86 // return value of compareString in { -1, 0, 1 }
87}
88
89OUString SAL_CALL IndexEntrySupplier_Common::getIndexCharacter( const OUString& rIndexEntry,
90 const lang::Locale& rLocale, const OUString& )
91{
92 return getIndexKey(rIndexEntry, rIndexEntry, rLocale);
93}
94
96 const lang::Locale& )
97{
98 throw RuntimeException();
99}
100
101const OUString&
102IndexEntrySupplier_Common::getEntry( const OUString& IndexEntry,
103 const OUString& PhoneticEntry, const lang::Locale& rLocale ) const
104{
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;
113 else
114 return IndexEntry;
115}
116
117OUString SAL_CALL
119{
120 return OUString::createFromAscii( implementationName );
121}
122
123sal_Bool SAL_CALL
125{
126 return cppu::supportsService(this, rServiceName);
127}
128
129Sequence< OUString > SAL_CALL
131{
132 Sequence< OUString > aRet { OUString::createFromAscii( implementationName ) };
133 return aRet;
134}
135
136}
137
138/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Bool SAL_CALL usePhoneticEntry(const css::lang::Locale &rLocale) override
IndexEntrySupplier_Common(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual css::uno::Sequence< OUString > SAL_CALL getAlgorithmList(const css::lang::Locale &rLocale) override
virtual OUString SAL_CALL getPhoneticCandidate(const OUString &IndexEntry, const css::lang::Locale &rLocale) override
virtual sal_Int16 SAL_CALL compareIndexEntry(const OUString &IndexEntry1, const OUString &PhoneticEntry1, const css::lang::Locale &rLocale1, const OUString &IndexEntry2, const OUString &PhoneticEntry2, const css::lang::Locale &rLocale2) override
virtual OUString SAL_CALL getIndexKey(const OUString &IndexEntry, const OUString &PhoneticEntry, const css::lang::Locale &rLocale) override
virtual sal_Bool SAL_CALL loadAlgorithm(const css::lang::Locale &rLocale, const OUString &SortAlgorithm, sal_Int32 collatorOptions) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getIndexCharacter(const OUString &rIndexEntry, const css::lang::Locale &rLocale, const OUString &rSortAlgorithm) override
virtual OUString SAL_CALL getIndexFollowPageWord(sal_Bool MorePages, const css::lang::Locale &rLocale) override
const OUString & getEntry(const OUString &IndexEntry, const OUString &PhoneticEntry, const css::lang::Locale &rLocale) const
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Sequence< css::lang::Locale > SAL_CALL getLocaleList() override
static rtl::Reference< LocaleDataImpl > get()
Definition: localedata.hxx:77
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Constant values shared between i18npool and, for example, the number formatter.
constexpr T & temporary(T &&x)
unsigned char sal_Bool