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