LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / include / unotools / charclass.hxx
blobf3c81a18e51baafc254fc27b2100cd0b7a3e18fc
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>
30 #include <mutex>
32 namespace com::sun::star::uno { class XComponentContext; }
33 namespace com::sun::star::i18n { class XCharacterClassification; }
35 const sal_Int32 nCharClassAlphaType =
36 css::i18n::KCharacterType::UPPER |
37 css::i18n::KCharacterType::LOWER |
38 css::i18n::KCharacterType::TITLE_CASE;
40 const sal_Int32 nCharClassAlphaTypeMask =
41 nCharClassAlphaType |
42 css::i18n::KCharacterType::PRINTABLE |
43 css::i18n::KCharacterType::BASE_FORM;
45 const sal_Int32 nCharClassLetterType =
46 nCharClassAlphaType |
47 css::i18n::KCharacterType::LETTER;
49 const sal_Int32 nCharClassLetterTypeMask =
50 nCharClassAlphaTypeMask |
51 css::i18n::KCharacterType::LETTER;
53 const sal_Int32 nCharClassNumericType =
54 css::i18n::KCharacterType::DIGIT;
56 const sal_Int32 nCharClassNumericTypeMask =
57 nCharClassNumericType |
58 css::i18n::KCharacterType::PRINTABLE |
59 css::i18n::KCharacterType::BASE_FORM;
61 class UNOTOOLS_DLLPUBLIC CharClass
63 LanguageTag maLanguageTag;
64 css::uno::Reference< css::i18n::XCharacterClassification > xCC;
66 CharClass(const CharClass&) = delete;
67 CharClass& operator=(const CharClass&) = delete;
69 public:
70 /// Preferred ctor with service manager specified
71 CharClass(
72 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
73 const LanguageTag& rLanguageTag );
75 /// Deprecated ctor, tries to get a process service manager or to load the
76 /// library directly.
77 CharClass( const LanguageTag& rLanguageTag );
79 ~CharClass();
81 /// get current Locale
82 const LanguageTag& getLanguageTag() const;
84 /// isdigit() on ascii values of entire string
85 static bool isAsciiNumeric( const OUString& rStr );
87 /// isalpha() on ascii values of entire string
88 static bool isAsciiAlpha( const OUString& rStr );
90 /// whether type is pure numeric or not, e.g. return of getStringType
91 static bool isNumericType( sal_Int32 nType )
93 return ((nType & nCharClassNumericType) != 0) &&
94 ((nType & ~nCharClassNumericTypeMask) == 0);
97 /// whether type is pure alphanumeric or not, e.g. return of getStringType
98 static bool isAlphaNumericType( sal_Int32 nType )
100 return ((nType & (nCharClassAlphaType |
101 nCharClassNumericType)) != 0) &&
102 ((nType & ~(nCharClassAlphaTypeMask |
103 nCharClassNumericTypeMask)) == 0);
106 /// whether type is pure letter or not, e.g. return of getStringType
107 static bool isLetterType( sal_Int32 nType )
109 return ((nType & nCharClassLetterType) != 0) &&
110 ((nType & ~nCharClassLetterTypeMask) == 0);
113 /// whether type is pure letternumeric or not, e.g. return of getStringType
114 static bool isLetterNumericType( sal_Int32 nType )
116 return ((nType & (nCharClassLetterType |
117 nCharClassNumericType)) != 0) &&
118 ((nType & ~(nCharClassLetterTypeMask |
119 nCharClassNumericTypeMask)) == 0);
122 // Wrapper implementations of class CharacterClassification
124 OUString uppercase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
125 OUString lowercase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
126 OUString titlecase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
128 OUString uppercase( const OUString& _rStr ) const
130 return uppercase(_rStr, 0, _rStr.getLength());
132 OUString lowercase( const OUString& _rStr ) const
134 return lowercase(_rStr, 0, _rStr.getLength());
136 OUString titlecase( const OUString& _rStr ) const
138 return titlecase(_rStr, 0, _rStr.getLength());
141 sal_Int16 getType( const OUString& rStr, sal_Int32 nPos ) const;
142 css::i18n::DirectionProperty getCharacterDirection( const OUString& rStr, sal_Int32 nPos ) const;
143 css::i18n::UnicodeScript getScript( const OUString& rStr, sal_Int32 nPos ) const;
144 sal_Int32 getCharacterType( const OUString& rStr, sal_Int32 nPos ) const;
145 sal_Int32 getStringType( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
147 css::i18n::ParseResult parseAnyToken(
148 const OUString& rStr,
149 sal_Int32 nPos,
150 sal_Int32 nStartCharFlags,
151 const OUString& userDefinedCharactersStart,
152 sal_Int32 nContCharFlags,
153 const OUString& userDefinedCharactersCont ) const;
155 css::i18n::ParseResult parsePredefinedToken(
156 sal_Int32 nTokenType,
157 const OUString& rStr,
158 sal_Int32 nPos,
159 sal_Int32 nStartCharFlags,
160 const OUString& userDefinedCharactersStart,
161 sal_Int32 nContCharFlags,
162 const OUString& userDefinedCharactersCont ) const;
164 // Functionality of class International methods
166 bool isAlpha( const OUString& rStr, sal_Int32 nPos ) const;
167 bool isLetter( const OUString& rStr, sal_Int32 nPos ) const;
168 bool isDigit( const OUString& rStr, sal_Int32 nPos ) const;
169 bool isAlphaNumeric( const OUString& rStr, sal_Int32 nPos ) const;
170 bool isLetterNumeric( const OUString& rStr, sal_Int32 nPos ) const;
171 bool isLetter( const OUString& rStr ) const;
172 bool isNumeric( const OUString& rStr ) const;
173 bool isLetterNumeric( const OUString& rStr ) const;
175 private:
177 const css::lang::Locale & getMyLocale() const;
180 #endif // INCLUDED_UNOTOOLS_CHARCLASS_HXX
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */