Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / unotools / charclass.hxx
blobbc91aca63631e9b18a16c2464820958da818d5b6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_UNOTOOLS_CHARCLASS_HXX
21 #define INCLUDED_UNOTOOLS_CHARCLASS_HXX
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>
31 namespace com::sun::star::uno { class XComponentContext; }
32 namespace com::sun::star::i18n { class XCharacterClassification; }
34 inline constexpr sal_Int32 nCharClassAlphaType =
35 css::i18n::KCharacterType::UPPER |
36 css::i18n::KCharacterType::LOWER |
37 css::i18n::KCharacterType::TITLE_CASE;
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;
45 inline constexpr sal_Int32 nCharClassLetterType =
46 nCharClassAlphaType |
47 css::i18n::KCharacterType::LETTER;
49 inline constexpr sal_Int32 nCharClassLetterTypeMask =
50 nCharClassAlphaTypeMask |
51 css::i18n::KCharacterType::LETTER;
53 inline constexpr sal_Int32 nCharClassNumericType =
54 css::i18n::KCharacterType::DIGIT;
56 inline constexpr sal_Int32 nCharClassNumericTypeMask =
57 nCharClassNumericType |
58 css::i18n::KCharacterType::PRINTABLE |
59 css::i18n::KCharacterType::BASE_FORM;
61 inline constexpr sal_Int32 nCharClassBaseType =
62 css::i18n::KCharacterType::BASE_FORM;
64 class UNOTOOLS_DLLPUBLIC CharClass
66 LanguageTag maLanguageTag;
67 css::uno::Reference< css::i18n::XCharacterClassification > xCC;
69 CharClass(const CharClass&) = delete;
70 CharClass& operator=(const CharClass&) = delete;
72 public:
73 /// Preferred ctor with service manager specified
74 CharClass(
75 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
76 LanguageTag aLanguageTag );
78 /// Deprecated ctor, tries to get a process service manager or to load the
79 /// library directly.
80 CharClass( LanguageTag aLanguageTag );
82 ~CharClass();
84 /// get current Locale
85 const LanguageTag& getLanguageTag() const;
87 /// isdigit() on ascii values of entire string
88 static bool isAsciiNumeric( std::u16string_view rStr );
90 /// isalpha() on ascii values of entire string
91 static bool isAsciiAlpha( std::u16string_view rStr );
93 /// whether type is pure numeric or not, e.g. return of getCharacterType()
94 static bool isNumericType( sal_Int32 nType )
96 return ((nType & nCharClassNumericType) != 0) &&
97 ((nType & ~nCharClassNumericTypeMask) == 0);
100 /// whether type is pure alphanumeric or not, e.g. return of getCharacterType()
101 static bool isAlphaNumericType( sal_Int32 nType )
103 return ((nType & (nCharClassAlphaType |
104 nCharClassNumericType)) != 0) &&
105 ((nType & ~(nCharClassAlphaTypeMask |
106 nCharClassNumericTypeMask)) == 0);
109 /// whether type is pure letter or not, e.g. return of getCharacterType()
110 static bool isLetterType( sal_Int32 nType )
112 return ((nType & nCharClassLetterType) != 0) &&
113 ((nType & ~nCharClassLetterTypeMask) == 0);
116 /// whether type is pure letternumeric or not, e.g. return of getCharacterType()
117 static bool isLetterNumericType( sal_Int32 nType )
119 return ((nType & (nCharClassLetterType |
120 nCharClassNumericType)) != 0) &&
121 ((nType & ~(nCharClassLetterTypeMask |
122 nCharClassNumericTypeMask)) == 0);
125 // Wrapper implementations of class CharacterClassification
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;
131 OUString uppercase( const OUString& _rStr ) const
133 return uppercase(_rStr, 0, _rStr.getLength());
135 OUString lowercase( const OUString& _rStr ) const
137 return lowercase(_rStr, 0, _rStr.getLength());
139 OUString titlecase( const OUString& _rStr ) const
141 return titlecase(_rStr, 0, _rStr.getLength());
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;
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;
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;
166 // Functionality of class International methods
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;
179 bool isUpper( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
181 private:
183 const css::lang::Locale & getMyLocale() const;
186 #endif // INCLUDED_UNOTOOLS_CHARCLASS_HXX
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */