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 .
19 #ifndef INCLUDED_I18NPOOL_INC_CCLASS_UNICODE_HXX
20 #define INCLUDED_I18NPOOL_INC_CCLASS_UNICODE_HXX
22 #include <com/sun/star/i18n/XCharacterClassification.hpp>
23 #include <cppuhelper/implbase.hxx>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <o3tl/typed_flags_set.hxx>
29 namespace com::sun::star::uno
{ class XComponentContext
; }
30 namespace com::sun::star::i18n
{ class XNativeNumberSupplier
; }
31 namespace com::sun::star::i18n
{ class XLocaleData5
; }
32 namespace i18npool
{ class Transliteration_casemapping
; }
35 /// Flag values of table.
36 enum class ParserFlags
: sal_uInt32
{
39 CHAR_BOOL
= 0x00000002,
40 CHAR_WORD
= 0x00000004,
41 CHAR_VALUE
= 0x00000008,
42 CHAR_STRING
= 0x00000010,
43 CHAR_DONTCARE
= 0x00000020,
46 WORD_SEP
= 0x00000100,
48 VALUE_SEP
= 0x00000400,
49 VALUE_EXP
= 0x00000800,
50 VALUE_SIGN
= 0x00001000,
51 VALUE_EXP_VALUE
= 0x00002000,
52 VALUE_DIGIT
= 0x00004000,
53 NAME_SEP
= 0x20000000,
54 STRING_SEP
= 0x40000000,
55 EXCLUDED
= 0x80000000,
58 template<> struct typed_flags
<ParserFlags
> : is_typed_flags
<ParserFlags
, 0xe0007fff> {};
64 class cclass_Unicode final
: public cppu::WeakImplHelper
< css::i18n::XCharacterClassification
, css::lang::XServiceInfo
>
67 cclass_Unicode(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
68 virtual ~cclass_Unicode() override
;
70 virtual OUString SAL_CALL
toUpper( const OUString
& Text
, sal_Int32 nPos
, sal_Int32 nCount
,
71 const css::lang::Locale
& rLocale
) override
;
72 virtual OUString SAL_CALL
toLower( const OUString
& Text
, sal_Int32 nPos
, sal_Int32 nCount
,
73 const css::lang::Locale
& rLocale
) override
;
74 virtual OUString SAL_CALL
toTitle( const OUString
& Text
, sal_Int32 nPos
, sal_Int32 nCount
,
75 const css::lang::Locale
& rLocale
) override
;
76 virtual sal_Int16 SAL_CALL
getType( const OUString
& Text
, sal_Int32 nPos
) override
;
77 virtual sal_Int16 SAL_CALL
getCharacterDirection( const OUString
& Text
, sal_Int32 nPos
) override
;
78 virtual sal_Int16 SAL_CALL
getScript( const OUString
& Text
, sal_Int32 nPos
) override
;
79 virtual sal_Int32 SAL_CALL
getCharacterType( const OUString
& text
, sal_Int32 nPos
,
80 const css::lang::Locale
& rLocale
) override
;
81 virtual sal_Int32 SAL_CALL
getStringType( const OUString
& text
, sal_Int32 nPos
, sal_Int32 nCount
,
82 const css::lang::Locale
& rLocale
) override
;
83 virtual css::i18n::ParseResult SAL_CALL
parseAnyToken( const OUString
& Text
, sal_Int32 nPos
,
84 const css::lang::Locale
& rLocale
, sal_Int32 nStartCharFlags
, const OUString
& userDefinedCharactersStart
,
85 sal_Int32 nContCharFlags
, const OUString
& userDefinedCharactersCont
) override
;
86 virtual css::i18n::ParseResult SAL_CALL
parsePredefinedToken( sal_Int32 nTokenType
, const OUString
& Text
,
87 sal_Int32 nPos
, const css::lang::Locale
& rLocale
, sal_Int32 nStartCharFlags
,
88 const OUString
& userDefinedCharactersStart
, sal_Int32 nContCharFlags
,
89 const OUString
& userDefinedCharactersCont
) override
;
92 virtual OUString SAL_CALL
getImplementationName() override
;
93 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
94 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
97 std::unique_ptr
<Transliteration_casemapping
> trans
;
99 // --- parser specific (implemented in cclass_unicode_parser.cxx) ---
103 ssGetChar
, // initial state; -> ssBounce, ssGetValue, ssRewindFromValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop
104 ssGetValue
, // -> ssBounce, ssRewindFromValue, ssStopBack, ssGetWord
105 ssGetWord
, // -> ssBounce, ssStop, ssStopBack
106 ssGetWordFirstChar
, // -> ssBounce, ssGetWord, ssStop, ssStopBack
107 ssGetString
, // -> ssBounce, ssStop
108 ssGetBool
, // -> ssBounce, ssStop, ssStopBack
109 ssRewindFromValue
, // -> ssBounce, ssGetValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop, ssIgnoreLeadingInRewind
110 ssIgnoreLeadingInRewind
, // -> ssBounce, ssGetValue, ssRewindFromValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop
111 ssStopBack
, // -> ssStop
112 ssBounce
, // -> ssStopBack
116 static const sal_uInt8 nDefCnt
;
117 static const ParserFlags pDefaultParserTable
[];
118 static const sal_Int32 pParseTokensType
[];
120 /// If and where c occurs in pStr
121 static const sal_Unicode
* StrChr( const sal_Unicode
* pStr
, sal_uInt32 c
);
124 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
126 /// used for parser only
127 css::lang::Locale aParserLocale
;
128 css::uno::Reference
< css::i18n::XLocaleData5
> mxLocaleData
;
129 css::uno::Reference
< css::i18n::XNativeNumberSupplier
> xNatNumSup
;
130 OUString aStartChars
;
132 std::unique_ptr
<ParserFlags
[]> pTable
;
133 std::unique_ptr
<ParserFlags
[]> pStart
;
134 std::unique_ptr
<ParserFlags
[]> pCont
;
135 sal_Int32 nStartTypes
;
136 sal_Int32 nContTypes
;
138 sal_Unicode cGroupSep
;
139 sal_Unicode cDecimalSep
;
140 sal_Unicode cDecimalSepAlt
;
142 /// Get corresponding KParseTokens flag for a character
143 static sal_Int32
getParseTokensType(sal_uInt32 c
, bool isFirst
);
145 /// Access parser table flags.
146 ParserFlags
getFlags(sal_uInt32 c
);
148 /// Access parser flags via International and special definitions.
149 ParserFlags
getFlagsExtended(sal_uInt32 c
);
151 /// Access parser table flags for user defined start characters.
152 ParserFlags
getStartCharsFlags( sal_uInt32 c
);
154 /// Access parser table flags for user defined continuation characters.
155 ParserFlags
getContCharsFlags( sal_Unicode c
);
157 /// Setup parser table. Calls initParserTable() only if needed.
158 void setupParserTable( const css::lang::Locale
& rLocale
, sal_Int32 startCharTokenType
,
159 const OUString
& userDefinedCharactersStart
, sal_Int32 contCharTokenType
,
160 const OUString
& userDefinedCharactersCont
);
162 /// Init parser table.
163 void initParserTable( const css::lang::Locale
& rLocale
, sal_Int32 startCharTokenType
,
164 const OUString
& userDefinedCharactersStart
, sal_Int32 contCharTokenType
,
165 const OUString
& userDefinedCharactersCont
);
167 /// Destroy parser table.
168 void destroyParserTable();
171 void parseText( css::i18n::ParseResult
& r
, const OUString
& rText
, sal_Int32 nPos
,
172 sal_Int32 nTokenType
= 0xffffffff );
174 /// Setup International class, new'ed only if different from existing.
175 void setupInternational( const css::lang::Locale
& rLocale
);
177 /// Implementation of getCharacterType() for one single character
178 static sal_Int32
getCharType( const OUString
& Text
, sal_Int32
*nPos
, sal_Int32 increment
);
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */