LibreOffice Module i18npool (master)  1
characterclassificationImpl.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/i18n/XCharacterClassification.hpp>
22 #include <cppuhelper/implbase.hxx>
23 #include <vector>
24 #include <memory>
25 #include <optional>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 
28 namespace com::sun::star::uno { class XComponentContext; }
29 
30 namespace i18npool {
31 
32 class CharacterClassificationImpl final : public cppu::WeakImplHelper
33 <
34  css::i18n::XCharacterClassification,
35  css::lang::XServiceInfo
36 >
37 {
38 public:
39 
40  CharacterClassificationImpl( const css::uno::Reference < css::uno::XComponentContext >& rxContext );
41  virtual ~CharacterClassificationImpl() override;
42 
43  virtual OUString SAL_CALL toUpper( const OUString& Text,
44  sal_Int32 nPos, sal_Int32 nCount, const css::lang::Locale& rLocale ) override;
45  virtual OUString SAL_CALL toLower( const OUString& Text,
46  sal_Int32 nPos, sal_Int32 nCount, const css::lang::Locale& rLocale ) override;
47  virtual OUString SAL_CALL toTitle( const OUString& Text, sal_Int32 nPos,
48  sal_Int32 nCount, const css::lang::Locale& rLocale ) override;
49  virtual sal_Int16 SAL_CALL getType( const OUString& Text, sal_Int32 nPos ) override;
50  virtual sal_Int16 SAL_CALL getCharacterDirection( const OUString& Text, sal_Int32 nPos ) override;
51  virtual sal_Int16 SAL_CALL getScript( const OUString& Text, sal_Int32 nPos ) override;
52  virtual sal_Int32 SAL_CALL getCharacterType( const OUString& text, sal_Int32 nPos,
53  const css::lang::Locale& rLocale ) override;
54  virtual sal_Int32 SAL_CALL getStringType( const OUString& text, sal_Int32 nPos,
55  sal_Int32 nCount, const css::lang::Locale& rLocale ) override;
56  virtual css::i18n::ParseResult SAL_CALL parseAnyToken( const OUString& Text, sal_Int32 nPos,
57  const css::lang::Locale& rLocale, sal_Int32 nStartCharFlags,
58  const OUString& userDefinedCharactersStart, sal_Int32 nContCharFlags,
59  const OUString& userDefinedCharactersCont ) override;
60  virtual css::i18n::ParseResult SAL_CALL parsePredefinedToken( sal_Int32 nTokenType,
61  const OUString& Text, sal_Int32 nPos, const css::lang::Locale& rLocale,
62  sal_Int32 nStartCharFlags, const OUString& userDefinedCharactersStart,
63  sal_Int32 nContCharFlags, const OUString& userDefinedCharactersCont ) override;
64 
65  //XServiceInfo
66  virtual OUString SAL_CALL getImplementationName() override;
67  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
68  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
69 
70 private:
71  struct lookupTableItem {
72  lookupTableItem(const css::lang::Locale& rLocale, const OUString& rName,
73  css::uno::Reference < XCharacterClassification > const & rxCI) :
74  aLocale(rLocale), aName(rName), xCI(rxCI) {};
75  css::lang::Locale aLocale;
76  OUString aName;
77  css::uno::Reference < XCharacterClassification > xCI;
78  bool equals(const css::lang::Locale& rLocale) const {
79  return aLocale.Language == rLocale.Language &&
80  aLocale.Country == rLocale.Country &&
81  aLocale.Variant == rLocale.Variant;
82  };
83  };
84  std::vector<lookupTableItem> lookupTable;
85  std::optional<lookupTableItem> cachedItem;
86 
87  css::uno::Reference < css::uno::XComponentContext > m_xContext;
88  css::uno::Reference < XCharacterClassification > xUCI;
89 
91  css::uno::Reference < XCharacterClassification > const & getLocaleSpecificCharacterClassification(const css::lang::Locale& rLocale);
92  bool createLocaleSpecificCharacterClassification(const OUString& serviceName, const css::lang::Locale& rLocale);
93 
94 };
95 
96 }
97 
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< XCharacterClassification > xCI
virtual OUString SAL_CALL toTitle(const OUString &Text, sal_Int32 nPos, sal_Int32 nCount, const css::lang::Locale &rLocale) override
virtual OUString SAL_CALL toUpper(const OUString &Text, sal_Int32 nPos, sal_Int32 nCount, const css::lang::Locale &rLocale) override
virtual sal_Int16 SAL_CALL getCharacterDirection(const OUString &Text, sal_Int32 nPos) override
virtual sal_Int16 SAL_CALL getScript(const OUString &Text, sal_Int32 nPos) override
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual sal_Int16 SAL_CALL getType(const OUString &Text, sal_Int32 nPos) override
int nCount
css::uno::Reference< css::uno::XComponentContext > m_xContext
css::uno::Reference< XCharacterClassification > const & getLocaleSpecificCharacterClassification(const css::lang::Locale &rLocale)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
exports com.sun.star. text
unsigned char sal_Bool
Constant values shared between i18npool and, for example, the number formatter.
virtual css::i18n::ParseResult SAL_CALL parsePredefinedToken(sal_Int32 nTokenType, const OUString &Text, sal_Int32 nPos, const css::lang::Locale &rLocale, sal_Int32 nStartCharFlags, const OUString &userDefinedCharactersStart, sal_Int32 nContCharFlags, const OUString &userDefinedCharactersCont) override
bool equals(const css::lang::Locale &rLocale) const
virtual css::i18n::ParseResult SAL_CALL parseAnyToken(const OUString &Text, sal_Int32 nPos, const css::lang::Locale &rLocale, sal_Int32 nStartCharFlags, const OUString &userDefinedCharactersStart, sal_Int32 nContCharFlags, const OUString &userDefinedCharactersCont) override
virtual OUString SAL_CALL toLower(const OUString &Text, sal_Int32 nPos, sal_Int32 nCount, const css::lang::Locale &rLocale) override
virtual sal_Int32 SAL_CALL getCharacterType(const OUString &text, sal_Int32 nPos, const css::lang::Locale &rLocale) override
CharacterClassificationImpl(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
bool createLocaleSpecificCharacterClassification(const OUString &serviceName, const css::lang::Locale &rLocale)
virtual sal_Int32 SAL_CALL getStringType(const OUString &text, sal_Int32 nPos, sal_Int32 nCount, const css::lang::Locale &rLocale) override
lookupTableItem(const css::lang::Locale &rLocale, const OUString &rName, css::uno::Reference< XCharacterClassification > const &rxCI)
sal_uInt16 nPos
css::uno::Reference< XCharacterClassification > xUCI