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
{ namespace sun
{ namespace star
{
34 class XComponentContext
;
38 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{ class XCharacterClassification
; } } } }
40 const sal_Int32 nCharClassAlphaType
=
41 css::i18n::KCharacterType::UPPER
|
42 css::i18n::KCharacterType::LOWER
|
43 css::i18n::KCharacterType::TITLE_CASE
;
45 const sal_Int32 nCharClassAlphaTypeMask
=
47 css::i18n::KCharacterType::PRINTABLE
|
48 css::i18n::KCharacterType::BASE_FORM
;
50 const sal_Int32 nCharClassLetterType
=
52 css::i18n::KCharacterType::LETTER
;
54 const sal_Int32 nCharClassLetterTypeMask
=
55 nCharClassAlphaTypeMask
|
56 css::i18n::KCharacterType::LETTER
;
58 const sal_Int32 nCharClassNumericType
=
59 css::i18n::KCharacterType::DIGIT
;
61 const sal_Int32 nCharClassNumericTypeMask
=
62 nCharClassNumericType
|
63 css::i18n::KCharacterType::PRINTABLE
|
64 css::i18n::KCharacterType::BASE_FORM
;
66 class UNOTOOLS_DLLPUBLIC CharClass
68 LanguageTag maLanguageTag
;
69 css::uno::Reference
< css::i18n::XCharacterClassification
> xCC
;
70 mutable ::osl::Mutex aMutex
;
72 CharClass(const CharClass
&) = delete;
73 CharClass
& operator=(const CharClass
&) = delete;
76 /// Preferred ctor with service manager specified
78 const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
79 const LanguageTag
& rLanguageTag
);
81 /// Deprecated ctor, tries to get a process service manager or to load the
83 CharClass( const LanguageTag
& rLanguageTag
);
88 void setLanguageTag( const LanguageTag
& rLanguageTag
);
90 /// get current Locale
91 const LanguageTag
& getLanguageTag() const;
93 /// isdigit() on ascii values of entire string
94 static bool isAsciiNumeric( const OUString
& rStr
);
96 /// isalpha() on ascii values of entire string
97 static bool isAsciiAlpha( const OUString
& rStr
);
99 /// whether type is pure numeric or not, e.g. return of getStringType
100 static bool isNumericType( sal_Int32 nType
)
102 return ((nType
& nCharClassNumericType
) != 0) &&
103 ((nType
& ~nCharClassNumericTypeMask
) == 0);
106 /// whether type is pure alphanumeric or not, e.g. return of getStringType
107 static bool isAlphaNumericType( sal_Int32 nType
)
109 return ((nType
& (nCharClassAlphaType
|
110 nCharClassNumericType
)) != 0) &&
111 ((nType
& ~(nCharClassAlphaTypeMask
|
112 nCharClassNumericTypeMask
)) == 0);
115 /// whether type is pure letter or not, e.g. return of getStringType
116 static bool isLetterType( sal_Int32 nType
)
118 return ((nType
& nCharClassLetterType
) != 0) &&
119 ((nType
& ~nCharClassLetterTypeMask
) == 0);
122 /// whether type is pure letternumeric or not, e.g. return of getStringType
123 static bool isLetterNumericType( sal_Int32 nType
)
125 return ((nType
& (nCharClassLetterType
|
126 nCharClassNumericType
)) != 0) &&
127 ((nType
& ~(nCharClassLetterTypeMask
|
128 nCharClassNumericTypeMask
)) == 0);
131 // Wrapper implementations of class CharacterClassification
133 OUString
uppercase( const OUString
& rStr
, sal_Int32 nPos
, sal_Int32 nCount
) const;
134 OUString
lowercase( const OUString
& rStr
, sal_Int32 nPos
, sal_Int32 nCount
) const;
135 OUString
titlecase( const OUString
& rStr
, sal_Int32 nPos
, sal_Int32 nCount
) const;
137 OUString
uppercase( const OUString
& _rStr
) const
139 return uppercase(_rStr
, 0, _rStr
.getLength());
141 OUString
lowercase( const OUString
& _rStr
) const
143 return lowercase(_rStr
, 0, _rStr
.getLength());
145 OUString
titlecase( const OUString
& _rStr
) const
147 return titlecase(_rStr
, 0, _rStr
.getLength());
150 sal_Int16
getType( const OUString
& rStr
, sal_Int32 nPos
) const;
151 css::i18n::DirectionProperty
getCharacterDirection( const OUString
& rStr
, sal_Int32 nPos
) const;
152 css::i18n::UnicodeScript
getScript( const OUString
& rStr
, sal_Int32 nPos
) const;
153 sal_Int32
getCharacterType( const OUString
& rStr
, sal_Int32 nPos
) const;
154 sal_Int32
getStringType( const OUString
& rStr
, sal_Int32 nPos
, sal_Int32 nCount
) const;
156 css::i18n::ParseResult
parseAnyToken(
157 const OUString
& rStr
,
159 sal_Int32 nStartCharFlags
,
160 const OUString
& userDefinedCharactersStart
,
161 sal_Int32 nContCharFlags
,
162 const OUString
& userDefinedCharactersCont
) const;
164 css::i18n::ParseResult
parsePredefinedToken(
165 sal_Int32 nTokenType
,
166 const OUString
& rStr
,
168 sal_Int32 nStartCharFlags
,
169 const OUString
& userDefinedCharactersStart
,
170 sal_Int32 nContCharFlags
,
171 const OUString
& userDefinedCharactersCont
) const;
173 // Functionality of class International methods
175 bool isAlpha( const OUString
& rStr
, sal_Int32 nPos
) const;
176 bool isLetter( const OUString
& rStr
, sal_Int32 nPos
) const;
177 bool isDigit( const OUString
& rStr
, sal_Int32 nPos
) const;
178 bool isAlphaNumeric( const OUString
& rStr
, sal_Int32 nPos
) const;
179 bool isLetterNumeric( const OUString
& rStr
, sal_Int32 nPos
) const;
180 bool isLetter( const OUString
& rStr
) const;
181 bool isNumeric( const OUString
& rStr
) const;
182 bool isLetterNumeric( const OUString
& rStr
) const;
186 const css::lang::Locale
& getMyLocale() const;
189 #endif // INCLUDED_UNOTOOLS_CHARCLASS_HXX
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */