Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/unotools/charclass.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_CHARCLASS_HXX
21
#define INCLUDED_UNOTOOLS_CHARCLASS_HXX
22
23
#include <unotools/unotoolsdllapi.h>
24
#include <i18nlangtag/languagetag.hxx>
25
#include <com/sun/star/i18n/KCharacterType.hpp>
26
#include <com/sun/star/uno/Reference.hxx>
27
28
namespace com::sun::star::uno { class XComponentContext; }
29
namespace com::sun::star::i18n { class XCharacterClassification; }
30
namespace com::sun::star::i18n { enum class DirectionProperty; }
31
namespace com::sun::star::i18n { enum class UnicodeScript; }
32
namespace com::sun::star::i18n { struct ParseResult; }
33
34
inline constexpr sal_Int32 nCharClassAlphaType =
35
    css::i18n::KCharacterType::UPPER |
36
    css::i18n::KCharacterType::LOWER |
37
    css::i18n::KCharacterType::TITLE_CASE;
38
39
inline constexpr sal_Int32 nCharClassAlphaTypeMask =
40
    nCharClassAlphaType |
41
    css::i18n::KCharacterType::LETTER |     // Alpha is also always a LETTER
42
    css::i18n::KCharacterType::PRINTABLE |
43
    css::i18n::KCharacterType::BASE_FORM;
44
45
inline constexpr sal_Int32 nCharClassLetterType =
46
    nCharClassAlphaType |
47
    css::i18n::KCharacterType::LETTER;
48
49
inline constexpr sal_Int32 nCharClassLetterTypeMask =
50
    nCharClassAlphaTypeMask |
51
    css::i18n::KCharacterType::LETTER;
52
53
inline constexpr sal_Int32 nCharClassNumericType =
54
    css::i18n::KCharacterType::DIGIT;
55
56
inline constexpr sal_Int32 nCharClassNumericTypeMask =
57
    nCharClassNumericType |
58
    css::i18n::KCharacterType::PRINTABLE |
59
    css::i18n::KCharacterType::BASE_FORM;
60
61
inline constexpr sal_Int32 nCharClassBaseType =
62
    css::i18n::KCharacterType::BASE_FORM;
63
64
class UNOTOOLS_DLLPUBLIC CharClass
65
{
66
    LanguageTag                 maLanguageTag;
67
    css::uno::Reference< css::i18n::XCharacterClassification >    xCC;
68
69
    CharClass(const CharClass&) = delete;
70
    CharClass& operator=(const CharClass&) = delete;
71
72
public:
73
    /// Preferred ctor with service manager specified
74
    CharClass(
75
        const css::uno::Reference< css::uno::XComponentContext > & rxContext,
76
        LanguageTag aLanguageTag );
77
78
    /// Deprecated ctor, tries to get a process service manager or to load the
79
    /// library directly.
80
    CharClass( LanguageTag aLanguageTag );
81
82
    ~CharClass();
83
84
    /// get current Locale
85
    const LanguageTag& getLanguageTag() const;
86
87
    /// isdigit() on ascii values of entire string
88
    static bool isAsciiNumeric( std::u16string_view rStr );
89
90
    /// isalpha() on ascii values of entire string
91
    static bool isAsciiAlpha( std::u16string_view rStr );
92
93
    /// whether type is pure numeric or not, e.g. return of getCharacterType()
94
    static bool isNumericType( sal_Int32 nType )
95
0
    {
96
0
        return ((nType & nCharClassNumericType) != 0) &&
97
0
            ((nType & ~nCharClassNumericTypeMask) == 0);
98
0
    }
99
100
    /// whether type is pure letter or not, e.g. return of getCharacterType()
101
    static bool isLetterType( sal_Int32 nType )
102
0
    {
103
0
        return ((nType & nCharClassLetterType) != 0) &&
104
0
            ((nType & ~nCharClassLetterTypeMask) == 0);
105
0
    }
106
107
    /// whether type is pure letternumeric or not, e.g. return of getCharacterType()
108
    static bool isLetterNumericType( sal_Int32 nType )
109
0
    {
110
0
        return ((nType & (nCharClassLetterType |
111
0
            nCharClassNumericType)) != 0) &&
112
0
            ((nType & ~(nCharClassLetterTypeMask |
113
0
            nCharClassNumericTypeMask)) == 0);
114
0
    }
115
116
    // Wrapper implementations of class CharacterClassification
117
118
    OUString uppercase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
119
    OUString lowercase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
120
    OUString titlecase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
121
122
    OUString uppercase( const OUString& _rStr ) const
123
60.0M
    {
124
60.0M
        return uppercase(_rStr, 0, _rStr.getLength());
125
60.0M
    }
126
    OUString lowercase( const OUString& _rStr ) const
127
1.51M
    {
128
1.51M
        return lowercase(_rStr, 0, _rStr.getLength());
129
1.51M
    }
130
    OUString titlecase( const OUString& _rStr ) const
131
0
    {
132
0
        return titlecase(_rStr, 0, _rStr.getLength());
133
0
    }
134
135
    sal_Int16 getType( const OUString& rStr, sal_Int32 nPos ) const;
136
    css::i18n::DirectionProperty getCharacterDirection( const OUString& rStr, sal_Int32 nPos ) const;
137
    css::i18n::UnicodeScript getScript( const OUString& rStr, sal_Int32 nPos ) const;
138
    sal_Int32 getCharacterType( const OUString& rStr, sal_Int32 nPos ) const;
139
140
    css::i18n::ParseResult parseAnyToken(
141
                                    const OUString& rStr,
142
                                    sal_Int32 nPos,
143
                                    sal_Int32 nStartCharFlags,
144
                                    const OUString& userDefinedCharactersStart,
145
                                    sal_Int32 nContCharFlags,
146
                                    const OUString& userDefinedCharactersCont ) const;
147
148
    css::i18n::ParseResult parsePredefinedToken(
149
                                    sal_Int32 nTokenType,
150
                                    const OUString& rStr,
151
                                    sal_Int32 nPos,
152
                                    sal_Int32 nStartCharFlags,
153
                                    const OUString& userDefinedCharactersStart,
154
                                    sal_Int32 nContCharFlags,
155
                                    const OUString& userDefinedCharactersCont ) const;
156
157
    // Functionality of class International methods
158
159
    bool isAlpha( const OUString& rStr, sal_Int32 nPos ) const;
160
    bool isLetter( const OUString& rStr, sal_Int32 nPos ) const;
161
    bool isDigit( const OUString& rStr, sal_Int32 nPos ) const;
162
    bool isAlphaNumeric( const OUString& rStr, sal_Int32 nPos ) const;
163
    bool isLetterNumeric( const OUString& rStr, sal_Int32 nPos ) const;
164
    bool isBase( const OUString& rStr, sal_Int32 nPos ) const;
165
    bool isUpper( const OUString& rStr, sal_Int32 nPos ) const;
166
    bool isLetter( const OUString& rStr ) const;
167
    bool isNumeric( const OUString& rStr ) const;
168
    bool isLetterNumeric( const OUString& rStr ) const;
169
170
private:
171
172
    const css::lang::Locale &  getMyLocale() const;
173
};
174
175
#endif // INCLUDED_UNOTOOLS_CHARCLASS_HXX
176
177
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */