Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/unotools/intlwrapper.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
20
#ifndef INCLUDED_UNOTOOLS_INTLWRAPPER_HXX
21
#define INCLUDED_UNOTOOLS_INTLWRAPPER_HXX
22
23
#include <unotools/unotoolsdllapi.h>
24
#include <unotools/collatorwrapper.hxx>
25
#include <com/sun/star/uno/Reference.h>
26
27
#include <i18nlangtag/languagetag.hxx>
28
#include <optional>
29
30
namespace com::sun::star::uno { class XComponentContext; }
31
32
class LocaleDataWrapper;
33
34
/**
35
    A wrapper of I18N wrappers. Using this is more expensive than using some
36
    single wrapper classes so use it only if you must pass a single pointer
37
    without knowing in advance what is needed, e.g. for
38
    SfxPoolItem::GetPresentation(). Remember that this wrapper was only created
39
    for convenience to bypass some oddities, if possible don't use it. <p>
40
41
    Implemented are only the const get...() methods of the wrappers, which are
42
    loaded on demand, for consistency reasons no change of locale is possible.
43
    Only default calendar and default collator are supported. <p>
44
45
    One exception though is the calendar wrapper: to be able to set a value and
46
    retrieve calendar values it is not const, so methods using this should
47
    reset the calendar to the previous value if it isn't sure where the
48
    IntlWrapper did come from. <p>
49
 */
50
class UNOTOOLS_DLLPUBLIC IntlWrapper
51
{
52
private:
53
    LanguageTag         maLanguageTag;
54
    css::uno::Reference< css::uno::XComponentContext > m_xContext;
55
56
    const LocaleDataWrapper*  pLocaleData { nullptr };
57
    std::optional<CollatorWrapper>    moCollator;
58
    std::optional<CollatorWrapper>    moCaseCollator;
59
60
    void                ImplNewLocaleData() const;
61
    void                ImplNewCollator( bool bCaseSensitive ) const;
62
63
public:
64
    IntlWrapper(LanguageTag aLanguageTag);
65
    ~IntlWrapper();
66
67
    const LocaleDataWrapper*    getLocaleData() const
68
0
                                    {
69
0
                                        if ( !pLocaleData )
70
0
                                            ImplNewLocaleData();
71
0
                                        return pLocaleData;
72
0
                                    }
73
    /// case insensitive collator, simple IGNORE_CASE
74
    const CollatorWrapper*      getCollator() const
75
0
                                    {
76
0
                                        if ( !moCollator )
77
0
                                            ImplNewCollator( false );
78
0
                                        return &*moCollator;
79
0
                                    }
80
    /// case sensitive collator
81
    const CollatorWrapper*      getCaseCollator() const
82
0
                                    {
83
0
                                        if ( !moCaseCollator )
84
0
                                            ImplNewCollator( true );
85
0
                                        return &*moCaseCollator;
86
0
                                    }
87
};
88
89
#endif // INCLUDED_UNOTOOLS_INTLWRAPPER_HXX
90
91
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */