1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #ifndef INCLUDED_I18NPOOL_INC_COLLATORIMPL_HXX
20 #define INCLUDED_I18NPOOL_INC_COLLATORIMPL_HXX
22 #include <com/sun/star/uno/Reference.h>
23 #include <com/sun/star/i18n/XCollator.hpp>
24 #include <com/sun/star/lang/Locale.hpp>
25 #include <cppuhelper/implbase.hxx>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
31 namespace com::sun::star::i18n
{ class XLocaleData5
; }
32 namespace com::sun::star::uno
{ class XComponentContext
; }
36 // ----------------------------------------------------
38 // ----------------------------------------------------
39 class CollatorImpl
: public cppu::WeakImplHelper
42 css::lang::XServiceInfo
48 CollatorImpl( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
50 virtual ~CollatorImpl() override
;
52 virtual sal_Int32 SAL_CALL
compareSubstring(const OUString
& s1
, sal_Int32 off1
, sal_Int32 len1
,
53 const OUString
& s2
, sal_Int32 off2
, sal_Int32 len2
) override
;
55 virtual sal_Int32 SAL_CALL
compareString( const OUString
& s1
,
56 const OUString
& s2
) override
;
58 virtual sal_Int32 SAL_CALL
loadDefaultCollator( const css::lang::Locale
& rLocale
, sal_Int32 collatorOptions
) override
;
60 virtual sal_Int32 SAL_CALL
loadCollatorAlgorithm( const OUString
& impl
, const css::lang::Locale
& rLocale
,
61 sal_Int32 collatorOptions
) override
;
63 virtual void SAL_CALL
loadCollatorAlgorithmWithEndUserOption( const OUString
& impl
, const css::lang::Locale
& rLocale
,
64 const css::uno::Sequence
< sal_Int32
>& collatorOptions
) override
;
66 virtual css::uno::Sequence
< OUString
> SAL_CALL
listCollatorAlgorithms( const css::lang::Locale
& rLocale
) override
;
68 virtual css::uno::Sequence
< sal_Int32
> SAL_CALL
listCollatorOptions( const OUString
& collatorAlgorithmName
) override
;
71 virtual OUString SAL_CALL
getImplementationName() override
;
72 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
73 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
76 css::lang::Locale nLocale
;
78 struct lookupTableItem
{
79 css::lang::Locale aLocale
;
82 css::uno::Reference
< XCollator
> xC
;
83 lookupTableItem(const css::lang::Locale
& rLocale
, const OUString
& _algorithm
, const OUString
& _service
,
84 css::uno::Reference
< XCollator
> const & _xC
) : aLocale(rLocale
), algorithm(_algorithm
), service(_service
), xC(_xC
) {}
85 bool equals(const css::lang::Locale
& rLocale
, const OUString
& _algorithm
) {
86 return aLocale
.Language
== rLocale
.Language
&&
87 aLocale
.Country
== rLocale
.Country
&&
88 aLocale
.Variant
== rLocale
.Variant
&&
89 algorithm
== _algorithm
;
92 std::vector
<std::unique_ptr
<lookupTableItem
>> lookupTable
;
93 lookupTableItem
* cachedItem
;
96 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
98 css::uno::Reference
< css::i18n::XLocaleData5
> mxLocaleData
;
100 /// @throws css::uno::RuntimeException
101 bool createCollator(const css::lang::Locale
& rLocale
, const OUString
& serviceName
,
102 const OUString
& rSortAlgorithm
);
103 /// @throws css::uno::RuntimeException
104 void loadCachedCollator(const css::lang::Locale
& rLocale
, const OUString
& rSortAlgorithm
);
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */