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