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