LibreOffice Module i18npool (master) 1
collatorImpl.hxx
Go to the documentation of this file.
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#pragma once
20
21#include <com/sun/star/uno/Reference.h>
22#include <com/sun/star/i18n/XCollator.hpp>
23#include <com/sun/star/lang/Locale.hpp>
25#include <com/sun/star/lang/XServiceInfo.hpp>
26
27#include <utility>
28#include <vector>
29#include <optional>
30
31namespace com::sun::star::i18n { class XLocaleData5; }
32namespace com::sun::star::uno { class XComponentContext; }
33
34namespace i18npool {
35
36// ----------------------------------------------------
37// class CollatorImpl
38// ----------------------------------------------------
39class CollatorImpl : public cppu::WeakImplHelper
40<
41 css::i18n::XCollator,
42 css::lang::XServiceInfo
43>
44{
45public:
46
47 // Constructors
48 CollatorImpl( const css::uno::Reference < css::uno::XComponentContext >& rxContext );
49 // Destructor
50 virtual ~CollatorImpl() override;
51
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;
54
55 virtual sal_Int32 SAL_CALL compareString( const OUString& s1,
56 const OUString& s2) override;
57
58 virtual sal_Int32 SAL_CALL loadDefaultCollator( const css::lang::Locale& rLocale, sal_Int32 collatorOptions) override;
59
60 virtual sal_Int32 SAL_CALL loadCollatorAlgorithm( const OUString& impl, const css::lang::Locale& rLocale,
61 sal_Int32 collatorOptions) override;
62
63 virtual void SAL_CALL loadCollatorAlgorithmWithEndUserOption( const OUString& impl, const css::lang::Locale& rLocale,
64 const css::uno::Sequence< sal_Int32 >& collatorOptions) override;
65
66 virtual css::uno::Sequence< OUString > SAL_CALL listCollatorAlgorithms( const css::lang::Locale& rLocale ) override;
67
68 virtual css::uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions( const OUString& collatorAlgorithmName ) override;
69
70 //XServiceInfo
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;
74
75protected:
76 css::lang::Locale nLocale;
77private:
79 css::lang::Locale aLocale;
80 OUString algorithm;
81 OUString service;
82 css::uno::Reference < XCollator > xC;
83 lookupTableItem(css::lang::Locale _aLocale, OUString _algorithm, OUString _service,
84 css::uno::Reference < XCollator > _xC) : aLocale(std::move(_aLocale)), algorithm(std::move(_algorithm)), service(std::move(_service)), xC(std::move(_xC)) {}
85 bool equals(const css::lang::Locale& rLocale, std::u16string_view _algorithm) {
86 return aLocale.Language == rLocale.Language &&
87 aLocale.Country == rLocale.Country &&
88 aLocale.Variant == rLocale.Variant &&
89 algorithm == _algorithm;
90 }
91 };
92 std::vector<lookupTableItem> lookupTable;
93 std::optional<lookupTableItem> cachedItem;
94
95 // Service Factory
96 css::uno::Reference < css::uno::XComponentContext > m_xContext;
97 // lang::Locale Data
98 css::uno::Reference < css::i18n::XLocaleData5 > mxLocaleData;
99
101 bool createCollator(const css::lang::Locale& rLocale, const OUString& serviceName,
102 const OUString& rSortAlgorithm);
104 void loadCachedCollator(const css::lang::Locale& rLocale, const OUString& rSortAlgorithm);
105};
106
107}
108
109/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual ~CollatorImpl() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::i18n::XLocaleData5 > mxLocaleData
virtual sal_Int32 SAL_CALL loadDefaultCollator(const css::lang::Locale &rLocale, sal_Int32 collatorOptions) override
virtual sal_Int32 SAL_CALL compareSubstring(const OUString &s1, sal_Int32 off1, sal_Int32 len1, const OUString &s2, sal_Int32 off2, sal_Int32 len2) override
virtual sal_Int32 SAL_CALL loadCollatorAlgorithm(const OUString &impl, const css::lang::Locale &rLocale, sal_Int32 collatorOptions) override
std::optional< lookupTableItem > cachedItem
virtual OUString SAL_CALL getImplementationName() override
css::lang::Locale nLocale
std::vector< lookupTableItem > lookupTable
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual css::uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions(const OUString &collatorAlgorithmName) override
virtual void SAL_CALL loadCollatorAlgorithmWithEndUserOption(const OUString &impl, const css::lang::Locale &rLocale, const css::uno::Sequence< sal_Int32 > &collatorOptions) override
void loadCachedCollator(const css::lang::Locale &rLocale, const OUString &rSortAlgorithm)
virtual css::uno::Sequence< OUString > SAL_CALL listCollatorAlgorithms(const css::lang::Locale &rLocale) override
bool createCollator(const css::lang::Locale &rLocale, const OUString &serviceName, const OUString &rSortAlgorithm)
CollatorImpl(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual sal_Int32 SAL_CALL compareString(const OUString &s1, const OUString &s2) override
Constant values shared between i18npool and, for example, the number formatter.
css::uno::Reference< XCollator > xC
bool equals(const css::lang::Locale &rLocale, std::u16string_view _algorithm)
lookupTableItem(css::lang::Locale _aLocale, OUString _algorithm, OUString _service, css::uno::Reference< XCollator > _xC)
unsigned char sal_Bool