Line data Source code
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 <indexentrysupplier_common.hxx>
21 : #include <com/sun/star/i18n/CollatorOptions.hpp>
22 : #include <cppuhelper/supportsservice.hxx>
23 : #include <localedata.hxx>
24 :
25 : using namespace ::com::sun::star::uno;
26 : using namespace ::com::sun::star;
27 :
28 : namespace com { namespace sun { namespace star { namespace i18n {
29 :
30 10 : IndexEntrySupplier_Common::IndexEntrySupplier_Common(const Reference < uno::XComponentContext >& rxContext)
31 : {
32 10 : implementationName = "com.sun.star.i18n.IndexEntrySupplier_Common";
33 10 : collator = new CollatorImpl(rxContext);
34 10 : usePhonetic = false;
35 10 : }
36 :
37 20 : IndexEntrySupplier_Common::~IndexEntrySupplier_Common()
38 : {
39 10 : delete collator;
40 10 : }
41 :
42 0 : Sequence < lang::Locale > SAL_CALL IndexEntrySupplier_Common::getLocaleList() throw (RuntimeException, std::exception)
43 : {
44 0 : throw RuntimeException();
45 : }
46 :
47 0 : Sequence < OUString > SAL_CALL IndexEntrySupplier_Common::getAlgorithmList( const lang::Locale& ) throw (RuntimeException, std::exception)
48 : {
49 0 : throw RuntimeException();
50 : }
51 :
52 0 : OUString SAL_CALL IndexEntrySupplier_Common::getPhoneticCandidate( const OUString&,
53 : const lang::Locale& ) throw (RuntimeException, std::exception)
54 : {
55 0 : return OUString();
56 : }
57 :
58 0 : sal_Bool SAL_CALL IndexEntrySupplier_Common::usePhoneticEntry( const lang::Locale& ) throw (RuntimeException, std::exception)
59 : {
60 0 : throw RuntimeException();
61 : }
62 :
63 10 : sal_Bool SAL_CALL IndexEntrySupplier_Common::loadAlgorithm( const lang::Locale& rLocale,
64 : const OUString& rAlgorithm, sal_Int32 collatorOptions ) throw (RuntimeException, std::exception)
65 : {
66 10 : usePhonetic = LocaleDataImpl().isPhonetic(rLocale, rAlgorithm);
67 10 : collator->loadCollatorAlgorithm(rAlgorithm, rLocale, collatorOptions);
68 10 : aLocale = rLocale;
69 10 : aAlgorithm = rAlgorithm;
70 10 : return sal_True;
71 : }
72 :
73 0 : OUString SAL_CALL IndexEntrySupplier_Common::getIndexKey( const OUString& rIndexEntry,
74 : const OUString&, const lang::Locale& ) throw (RuntimeException, std::exception)
75 : {
76 0 : sal_Int32 nPos=0;
77 0 : sal_uInt32 indexChar=rIndexEntry.iterateCodePoints(&nPos, 0);
78 0 : return OUString(&indexChar, 1);
79 : }
80 :
81 0 : 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)
85 : {
86 : return sal::static_int_cast< sal_Int16 >(
87 0 : collator->compareString(rIndexEntry1, rIndexEntry2));
88 : // return value of compareString in { -1, 0, 1 }
89 : }
90 :
91 0 : OUString SAL_CALL IndexEntrySupplier_Common::getIndexCharacter( const OUString& rIndexEntry,
92 : const lang::Locale& rLocale, const OUString& ) throw (RuntimeException, std::exception)
93 : {
94 0 : return getIndexKey(rIndexEntry, rIndexEntry, rLocale);
95 : }
96 :
97 0 : OUString SAL_CALL IndexEntrySupplier_Common::getIndexFollowPageWord( sal_Bool,
98 : const lang::Locale& ) throw (RuntimeException, std::exception)
99 : {
100 0 : throw RuntimeException();
101 : }
102 :
103 : const OUString& SAL_CALL
104 0 : IndexEntrySupplier_Common::getEntry( const OUString& IndexEntry,
105 : const OUString& PhoneticEntry, const lang::Locale& rLocale ) throw (RuntimeException)
106 : {
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 0 : if (usePhonetic && !PhoneticEntry.isEmpty() && rLocale.Language == aLocale.Language &&
113 0 : rLocale.Country == aLocale.Country && rLocale.Variant == aLocale.Variant)
114 0 : return PhoneticEntry;
115 : else
116 0 : return IndexEntry;
117 : }
118 :
119 : OUString SAL_CALL
120 0 : IndexEntrySupplier_Common::getImplementationName() throw( RuntimeException, std::exception )
121 : {
122 0 : return OUString::createFromAscii( implementationName );
123 : }
124 :
125 : sal_Bool SAL_CALL
126 0 : IndexEntrySupplier_Common::supportsService(const OUString& rServiceName) throw( RuntimeException, std::exception )
127 : {
128 0 : return cppu::supportsService(this, rServiceName);
129 : }
130 :
131 : Sequence< OUString > SAL_CALL
132 0 : IndexEntrySupplier_Common::getSupportedServiceNames() throw( RuntimeException, std::exception )
133 : {
134 0 : Sequence< OUString > aRet(1);
135 0 : aRet[0] = OUString::createFromAscii( implementationName );
136 0 : return aRet;
137 : }
138 :
139 : } } } }
140 :
141 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|