1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <osl/mutex.hxx>
30 #include <com/sun/star/uno/Reference.hxx>
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
=
42 css::i18n::KCharacterType::PRINTABLE
|
43 css::i18n::KCharacterType::BASE_FORM
;
45 const sal_Int32 nCharClassLetterType
=
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
;
65 mutable ::osl::Mutex aMutex
;
67 CharClass(const CharClass
&) = delete;
68 CharClass
& operator=(const CharClass
&) = delete;
71 /// Preferred ctor with service manager specified
73 const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
74 const LanguageTag
& rLanguageTag
);
76 /// Deprecated ctor, tries to get a process service manager or to load the
78 CharClass( const LanguageTag
& rLanguageTag
);
83 void setLanguageTag( const LanguageTag
& rLanguageTag
);
85 /// get current Locale
86 const LanguageTag
& getLanguageTag() const;
88 /// isdigit() on ascii values of entire string
89 static bool isAsciiNumeric( const OUString
& rStr
);
91 /// isalpha() on ascii values of entire string
92 static bool isAsciiAlpha( const OUString
& rStr
);
94 /// whether type is pure numeric or not, e.g. return of getStringType
95 static bool isNumericType( sal_Int32 nType
)
97 return ((nType
& nCharClassNumericType
) != 0) &&
98 ((nType
& ~nCharClassNumericTypeMask
) == 0);
101 /// whether type is pure alphanumeric or not, e.g. return of getStringType
102 static bool isAlphaNumericType( sal_Int32 nType
)
104 return ((nType
& (nCharClassAlphaType
|
105 nCharClassNumericType
)) != 0) &&
106 ((nType
& ~(nCharClassAlphaTypeMask
|
107 nCharClassNumericTypeMask
)) == 0);
110 /// whether type is pure letter or not, e.g. return of getStringType
111 static bool isLetterType( sal_Int32 nType
)
113 return ((nType
& nCharClassLetterType
) != 0) &&
114 ((nType
& ~nCharClassLetterTypeMask
) == 0);
117 /// whether type is pure letternumeric or not, e.g. return of getStringType
118 static bool isLetterNumericType( sal_Int32 nType
)
120 return ((nType
& (nCharClassLetterType
|
121 nCharClassNumericType
)) != 0) &&
122 ((nType
& ~(nCharClassLetterTypeMask
|
123 nCharClassNumericTypeMask
)) == 0);
126 // Wrapper implementations of class CharacterClassification
128 OUString
uppercase( const OUString
& rStr
, sal_Int32 nPos
, sal_Int32 nCount
) const;
129 OUString
lowercase( const OUString
& rStr
, sal_Int32 nPos
, sal_Int32 nCount
) const;
130 OUString
titlecase( const OUString
& rStr
, sal_Int32 nPos
, sal_Int32 nCount
) const;
132 OUString
uppercase( const OUString
& _rStr
) const
134 return uppercase(_rStr
, 0, _rStr
.getLength());
136 OUString
lowercase( const OUString
& _rStr
) const
138 return lowercase(_rStr
, 0, _rStr
.getLength());
140 OUString
titlecase( const OUString
& _rStr
) const
142 return titlecase(_rStr
, 0, _rStr
.getLength());
145 sal_Int16
getType( const OUString
& rStr
, sal_Int32 nPos
) const;
146 css::i18n::DirectionProperty
getCharacterDirection( const OUString
& rStr
, sal_Int32 nPos
) const;
147 css::i18n::UnicodeScript
getScript( const OUString
& rStr
, sal_Int32 nPos
) const;
148 sal_Int32
getCharacterType( const OUString
& rStr
, sal_Int32 nPos
) const;
149 sal_Int32
getStringType( const OUString
& rStr
, sal_Int32 nPos
, sal_Int32 nCount
) const;
151 css::i18n::ParseResult
parseAnyToken(
152 const OUString
& rStr
,
154 sal_Int32 nStartCharFlags
,
155 const OUString
& userDefinedCharactersStart
,
156 sal_Int32 nContCharFlags
,
157 const OUString
& userDefinedCharactersCont
) const;
159 css::i18n::ParseResult
parsePredefinedToken(
160 sal_Int32 nTokenType
,
161 const OUString
& rStr
,
163 sal_Int32 nStartCharFlags
,
164 const OUString
& userDefinedCharactersStart
,
165 sal_Int32 nContCharFlags
,
166 const OUString
& userDefinedCharactersCont
) const;
168 // Functionality of class International methods
170 bool isAlpha( const OUString
& rStr
, sal_Int32 nPos
) const;
171 bool isLetter( const OUString
& rStr
, sal_Int32 nPos
) const;
172 bool isDigit( const OUString
& rStr
, sal_Int32 nPos
) const;
173 bool isAlphaNumeric( const OUString
& rStr
, sal_Int32 nPos
) const;
174 bool isLetterNumeric( 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;
181 const css::lang::Locale
& getMyLocale() const;
184 #endif // INCLUDED_UNOTOOLS_CHARCLASS_HXX
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */