Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/i18npool/inc/characterclassificationImpl.hxx
Line
Count
Source
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 <utility>
24
#include <vector>
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(css::lang::Locale _aLocale, OUString _aName,
73
                        css::uno::Reference < XCharacterClassification > _xCI) :
74
1.12M
            aLocale(std::move(_aLocale)), aName(std::move(_aName)), xCI(std::move(_xCI)) {};
75
        css::lang::Locale aLocale;
76
        OUString aName;
77
        css::uno::Reference < XCharacterClassification > xCI;
78
130M
        bool equals(const css::lang::Locale& rLocale) const {
79
130M
            return aLocale.Language == rLocale.Language &&
80
129M
                aLocale.Country == rLocale.Country &&
81
129M
                aLocale.Variant == rLocale.Variant;
82
130M
        };
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
90
    /// @throws css::uno::RuntimeException
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: */