bump product version to 6.3.0.0.beta1
[LibreOffice.git] / i18npool / source / indexentry / indexentrysupplier_common.cxx
blob3d11a4ac2836e8386c9fad75d6eaacd9dff1c9a6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 using namespace ::com::sun::star::uno;
26 using namespace ::com::sun::star;
28 namespace i18npool {
30 IndexEntrySupplier_Common::IndexEntrySupplier_Common(const Reference < uno::XComponentContext >& rxContext)
32 implementationName = "com.sun.star.i18n.IndexEntrySupplier_Common";
33 collator = new CollatorImpl(rxContext);
34 usePhonetic = false;
37 IndexEntrySupplier_Common::~IndexEntrySupplier_Common()
41 Sequence < lang::Locale > SAL_CALL IndexEntrySupplier_Common::getLocaleList()
43 throw RuntimeException();
46 Sequence < OUString > SAL_CALL IndexEntrySupplier_Common::getAlgorithmList( const lang::Locale& )
48 throw RuntimeException();
51 OUString SAL_CALL IndexEntrySupplier_Common::getPhoneticCandidate( const OUString&,
52 const lang::Locale& )
54 return OUString();
57 sal_Bool SAL_CALL IndexEntrySupplier_Common::usePhoneticEntry( const lang::Locale& )
59 throw RuntimeException();
62 sal_Bool SAL_CALL IndexEntrySupplier_Common::loadAlgorithm( const lang::Locale& rLocale,
63 const OUString& rAlgorithm, sal_Int32 collatorOptions )
65 usePhonetic = LocaleDataImpl::get()->isPhonetic(rLocale, rAlgorithm);
66 collator->loadCollatorAlgorithm(rAlgorithm, rLocale, collatorOptions);
67 aLocale = rLocale;
68 aAlgorithm = rAlgorithm;
69 return true;
72 OUString SAL_CALL IndexEntrySupplier_Common::getIndexKey( const OUString& rIndexEntry,
73 const OUString&, const lang::Locale& )
75 sal_Int32 nPos=0;
76 sal_uInt32 indexChar=rIndexEntry.iterateCodePoints(&nPos, 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,
96 const lang::Locale& )
98 throw RuntimeException();
101 const OUString&
102 IndexEntrySupplier_Common::getEntry( const OUString& IndexEntry,
103 const OUString& PhoneticEntry, const lang::Locale& rLocale )
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;
117 OUString SAL_CALL
118 IndexEntrySupplier_Common::getImplementationName()
120 return OUString::createFromAscii( implementationName );
123 sal_Bool SAL_CALL
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 ) };
133 return aRet;
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */