Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / i18npool / source / indexentry / indexentrysupplier_common.cxx
blobbd647b2b24767293e7e547cdee4a097863c058c7
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 .
21 #include <indexentrysupplier_common.hxx>
22 #include <com/sun/star/i18n/CollatorOptions.hpp>
23 #include <localedata.hxx>
25 using namespace ::com::sun::star::uno;
26 using namespace ::com::sun::star;
27 using namespace ::rtl;
29 namespace com { namespace sun { namespace star { namespace i18n {
31 IndexEntrySupplier_Common::IndexEntrySupplier_Common(const Reference < uno::XComponentContext >& rxContext)
33 implementationName = "com.sun.star.i18n.IndexEntrySupplier_Common";
34 collator = new CollatorImpl(rxContext);
35 usePhonetic = sal_False;
38 IndexEntrySupplier_Common::~IndexEntrySupplier_Common()
40 delete collator;
43 Sequence < lang::Locale > SAL_CALL IndexEntrySupplier_Common::getLocaleList() throw (RuntimeException)
45 throw RuntimeException();
48 Sequence < OUString > SAL_CALL IndexEntrySupplier_Common::getAlgorithmList( const lang::Locale& ) throw (RuntimeException)
50 throw RuntimeException();
53 OUString SAL_CALL IndexEntrySupplier_Common::getPhoneticCandidate( const OUString&,
54 const lang::Locale& ) throw (RuntimeException)
56 return OUString();
59 sal_Bool SAL_CALL IndexEntrySupplier_Common::usePhoneticEntry( const lang::Locale& ) throw (RuntimeException)
61 throw RuntimeException();
64 sal_Bool SAL_CALL IndexEntrySupplier_Common::loadAlgorithm( const lang::Locale& rLocale,
65 const OUString& rAlgorithm, sal_Int32 collatorOptions ) throw (RuntimeException)
67 usePhonetic = LocaleData().isPhonetic(rLocale, rAlgorithm);
68 collator->loadCollatorAlgorithm(rAlgorithm, rLocale, collatorOptions);
69 aLocale = rLocale;
70 aAlgorithm = rAlgorithm;
71 return sal_True;
74 OUString SAL_CALL IndexEntrySupplier_Common::getIndexKey( const OUString& rIndexEntry,
75 const OUString&, const lang::Locale& ) throw (RuntimeException)
77 sal_Int32 nPos=0;
78 sal_uInt32 indexChar=rIndexEntry.iterateCodePoints(&nPos, 0);
79 return OUString(&indexChar, 1);
82 sal_Int16 SAL_CALL IndexEntrySupplier_Common::compareIndexEntry(
83 const OUString& rIndexEntry1, const OUString&, const lang::Locale&,
84 const OUString& rIndexEntry2, const OUString&, const lang::Locale& )
85 throw (RuntimeException)
87 return sal::static_int_cast< sal_Int16 >(
88 collator->compareString(rIndexEntry1, rIndexEntry2));
89 // return value of compareString in { -1, 0, 1 }
92 OUString SAL_CALL IndexEntrySupplier_Common::getIndexCharacter( const OUString& rIndexEntry,
93 const lang::Locale& rLocale, const OUString& ) throw (RuntimeException)
95 return getIndexKey(rIndexEntry, rIndexEntry, rLocale);
98 OUString SAL_CALL IndexEntrySupplier_Common::getIndexFollowPageWord( sal_Bool,
99 const lang::Locale& ) throw (RuntimeException)
101 throw RuntimeException();
104 const OUString& SAL_CALL
105 IndexEntrySupplier_Common::getEntry( const OUString& IndexEntry,
106 const OUString& PhoneticEntry, const lang::Locale& rLocale ) throw (RuntimeException)
108 // The condition for using phonetic entry is:
109 // usePhonetic is set for the algorithm;
110 // rLocale for phonetic entry is same as aLocale for algorithm,
111 // which means Chinese phonetic will not be used for Japanese algorithm;
112 // phonetic entry is not blank.
113 if (usePhonetic && !PhoneticEntry.isEmpty() && rLocale.Language == aLocale.Language &&
114 rLocale.Country == aLocale.Country && rLocale.Variant == aLocale.Variant)
115 return PhoneticEntry;
116 else
117 return IndexEntry;
120 OUString SAL_CALL
121 IndexEntrySupplier_Common::getImplementationName() throw( RuntimeException )
123 return OUString::createFromAscii( implementationName );
126 sal_Bool SAL_CALL
127 IndexEntrySupplier_Common::supportsService(const OUString& rServiceName) throw( RuntimeException )
129 return rServiceName.compareToAscii(implementationName) == 0;
132 Sequence< OUString > SAL_CALL
133 IndexEntrySupplier_Common::getSupportedServiceNames() throw( RuntimeException )
135 Sequence< OUString > aRet(1);
136 aRet[0] = OUString::createFromAscii( implementationName );
137 return aRet;
140 } } } }
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */