/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/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 | | |
31 | | namespace com::sun::star::uno { class XComponentContext; } |
32 | | namespace com::sun::star::i18n { class XCharacterClassification; } |
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 alphanumeric or not, e.g. return of getCharacterType() |
101 | | static bool isAlphaNumericType( sal_Int32 nType ) |
102 | 0 | { |
103 | 0 | return ((nType & (nCharClassAlphaType | |
104 | 0 | nCharClassNumericType)) != 0) && |
105 | 0 | ((nType & ~(nCharClassAlphaTypeMask | |
106 | 0 | nCharClassNumericTypeMask)) == 0); |
107 | 0 | } |
108 | | |
109 | | /// whether type is pure letter or not, e.g. return of getCharacterType() |
110 | | static bool isLetterType( sal_Int32 nType ) |
111 | 0 | { |
112 | 0 | return ((nType & nCharClassLetterType) != 0) && |
113 | 0 | ((nType & ~nCharClassLetterTypeMask) == 0); |
114 | 0 | } |
115 | | |
116 | | /// whether type is pure letternumeric or not, e.g. return of getCharacterType() |
117 | | static bool isLetterNumericType( sal_Int32 nType ) |
118 | 0 | { |
119 | 0 | return ((nType & (nCharClassLetterType | |
120 | 0 | nCharClassNumericType)) != 0) && |
121 | 0 | ((nType & ~(nCharClassLetterTypeMask | |
122 | 0 | nCharClassNumericTypeMask)) == 0); |
123 | 0 | } |
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 | 66.9M | { |
133 | 66.9M | return uppercase(_rStr, 0, _rStr.getLength()); |
134 | 66.9M | } |
135 | | OUString lowercase( const OUString& _rStr ) const |
136 | 2.58M | { |
137 | 2.58M | return lowercase(_rStr, 0, _rStr.getLength()); |
138 | 2.58M | } |
139 | | OUString titlecase( const OUString& _rStr ) const |
140 | 0 | { |
141 | 0 | return titlecase(_rStr, 0, _rStr.getLength()); |
142 | 0 | } |
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 | | private: |
180 | | |
181 | | const css::lang::Locale & getMyLocale() const; |
182 | | }; |
183 | | |
184 | | #endif // INCLUDED_UNOTOOLS_CHARCLASS_HXX |
185 | | |
186 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |