LibreOffice Module unotools (master) 1
charclass.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
20#ifndef INCLUDED_UNOTOOLS_CHARCLASS_HXX
21#define INCLUDED_UNOTOOLS_CHARCLASS_HXX
22
25#include <com/sun/star/i18n/DirectionProperty.hpp>
26#include <com/sun/star/i18n/KCharacterType.hpp>
27#include <com/sun/star/i18n/ParseResult.hpp>
28#include <com/sun/star/i18n/UnicodeScript.hpp>
29#include <com/sun/star/uno/Reference.hxx>
30
31namespace com::sun::star::uno { class XComponentContext; }
32namespace com::sun::star::i18n { class XCharacterClassification; }
33
34inline constexpr sal_Int32 nCharClassAlphaType =
35 css::i18n::KCharacterType::UPPER |
36 css::i18n::KCharacterType::LOWER |
37 css::i18n::KCharacterType::TITLE_CASE;
38
39inline constexpr sal_Int32 nCharClassAlphaTypeMask =
41 css::i18n::KCharacterType::LETTER | // Alpha is also always a LETTER
42 css::i18n::KCharacterType::PRINTABLE |
43 css::i18n::KCharacterType::BASE_FORM;
44
45inline constexpr sal_Int32 nCharClassLetterType =
47 css::i18n::KCharacterType::LETTER;
48
49inline constexpr sal_Int32 nCharClassLetterTypeMask =
51 css::i18n::KCharacterType::LETTER;
52
53inline constexpr sal_Int32 nCharClassNumericType =
54 css::i18n::KCharacterType::DIGIT;
55
56inline constexpr sal_Int32 nCharClassNumericTypeMask =
58 css::i18n::KCharacterType::PRINTABLE |
59 css::i18n::KCharacterType::BASE_FORM;
60
61inline constexpr sal_Int32 nCharClassBaseType =
62 css::i18n::KCharacterType::BASE_FORM;
63
65{
67 css::uno::Reference< css::i18n::XCharacterClassification > xCC;
68
69 CharClass(const CharClass&) = delete;
70 CharClass& operator=(const CharClass&) = delete;
71
72public:
75 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
76 LanguageTag aLanguageTag );
77
80 CharClass( LanguageTag aLanguageTag );
81
82 ~CharClass();
83
85 const LanguageTag& getLanguageTag() const;
86
88 static bool isAsciiNumeric( std::u16string_view rStr );
89
91 static bool isAsciiAlpha( std::u16string_view rStr );
92
94 static bool isNumericType( sal_Int32 nType )
95 {
96 return ((nType & nCharClassNumericType) != 0) &&
97 ((nType & ~nCharClassNumericTypeMask) == 0);
98 }
99
101 static bool isAlphaNumericType( sal_Int32 nType )
102 {
103 return ((nType & (nCharClassAlphaType |
104 nCharClassNumericType)) != 0) &&
107 }
108
110 static bool isLetterType( sal_Int32 nType )
111 {
112 return ((nType & nCharClassLetterType) != 0) &&
113 ((nType & ~nCharClassLetterTypeMask) == 0);
114 }
115
117 static bool isLetterNumericType( sal_Int32 nType )
118 {
119 return ((nType & (nCharClassLetterType |
120 nCharClassNumericType)) != 0) &&
123 }
124
125 // Wrapper implementations of class CharacterClassification
126
127 OUString uppercase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
128 OUString lowercase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
129 OUString titlecase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
130
131 OUString uppercase( const OUString& _rStr ) const
132 {
133 return uppercase(_rStr, 0, _rStr.getLength());
134 }
135 OUString lowercase( const OUString& _rStr ) const
136 {
137 return lowercase(_rStr, 0, _rStr.getLength());
138 }
139 OUString titlecase( const OUString& _rStr ) const
140 {
141 return titlecase(_rStr, 0, _rStr.getLength());
142 }
143
144 sal_Int16 getType( const OUString& rStr, sal_Int32 nPos ) const;
145 css::i18n::DirectionProperty getCharacterDirection( const OUString& rStr, sal_Int32 nPos ) const;
146 css::i18n::UnicodeScript getScript( const OUString& rStr, sal_Int32 nPos ) const;
147 sal_Int32 getCharacterType( const OUString& rStr, sal_Int32 nPos ) const;
148
149 css::i18n::ParseResult parseAnyToken(
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 css::i18n::ParseResult parsePredefinedToken(
158 sal_Int32 nTokenType,
159 const OUString& rStr,
160 sal_Int32 nPos,
161 sal_Int32 nStartCharFlags,
162 const OUString& userDefinedCharactersStart,
163 sal_Int32 nContCharFlags,
164 const OUString& userDefinedCharactersCont ) const;
165
166 // Functionality of class International methods
167
168 bool isAlpha( const OUString& rStr, sal_Int32 nPos ) const;
169 bool isLetter( const OUString& rStr, sal_Int32 nPos ) const;
170 bool isDigit( const OUString& rStr, sal_Int32 nPos ) const;
171 bool isAlphaNumeric( const OUString& rStr, sal_Int32 nPos ) const;
172 bool isLetterNumeric( const OUString& rStr, sal_Int32 nPos ) const;
173 bool isBase( const OUString& rStr, sal_Int32 nPos ) const;
174 bool isUpper( const OUString& rStr, sal_Int32 nPos ) const;
175 bool isLetter( const OUString& rStr ) const;
176 bool isNumeric( const OUString& rStr ) const;
177 bool isLetterNumeric( const OUString& rStr ) const;
178
179 bool isUpper( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
180
181private:
182
183 const css::lang::Locale & getMyLocale() const;
184};
185
186#endif // INCLUDED_UNOTOOLS_CHARCLASS_HXX
187
188/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_Int32 nCharClassBaseType
Definition: charclass.hxx:61
constexpr sal_Int32 nCharClassNumericType
Definition: charclass.hxx:53
constexpr sal_Int32 nCharClassAlphaType
Definition: charclass.hxx:34
constexpr sal_Int32 nCharClassLetterType
Definition: charclass.hxx:45
constexpr sal_Int32 nCharClassAlphaTypeMask
Definition: charclass.hxx:39
constexpr sal_Int32 nCharClassLetterTypeMask
Definition: charclass.hxx:49
constexpr sal_Int32 nCharClassNumericTypeMask
Definition: charclass.hxx:56
CharClass(const css::uno::Reference< css::uno::XComponentContext > &rxContext, LanguageTag aLanguageTag)
Preferred ctor with service manager specified.
static bool isLetterNumericType(sal_Int32 nType)
whether type is pure letternumeric or not, e.g. return of getCharacterType()
Definition: charclass.hxx:117
OUString titlecase(const OUString &_rStr) const
Definition: charclass.hxx:139
OUString lowercase(const OUString &_rStr) const
Definition: charclass.hxx:135
static bool isAlphaNumericType(sal_Int32 nType)
whether type is pure alphanumeric or not, e.g. return of getCharacterType()
Definition: charclass.hxx:101
static bool isLetterType(sal_Int32 nType)
whether type is pure letter or not, e.g. return of getCharacterType()
Definition: charclass.hxx:110
CharClass & operator=(const CharClass &)=delete
css::uno::Reference< css::i18n::XCharacterClassification > xCC
Definition: charclass.hxx:67
OUString uppercase(const OUString &_rStr) const
Definition: charclass.hxx:131
static bool isNumericType(sal_Int32 nType)
whether type is pure numeric or not, e.g. return of getCharacterType()
Definition: charclass.hxx:94
LanguageTag maLanguageTag
Definition: charclass.hxx:66
CharClass(const CharClass &)=delete
bool isAlpha(sal_Unicode c, bool bCompatible)
bool isLetter(sal_Unicode c)
bool isAlphaNumeric(sal_Unicode c, bool bCompatible)
const LanguageTag & getLanguageTag()
bool getType(BSTR name, Type &type)
QPRO_FUNC_TYPE nType
#define UNOTOOLS_DLLPUBLIC