loplugin:constmethod in editeng
[LibreOffice.git] / i18npool / inc / cclass_unicode.hxx
blob3a702ca9d9092edc04baad611add744e80742e01
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 .
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>
27 #include <memory>
29 namespace com { namespace sun { namespace star { namespace uno {
30 class XComponentContext;
31 } } } }
32 namespace com::sun::star::i18n { class XNativeNumberSupplier; }
33 namespace com::sun::star::i18n { class XLocaleData5; }
34 namespace i18npool { class Transliteration_casemapping; }
37 /// Flag values of table.
38 enum class ParserFlags : sal_uInt32 {
39 ILLEGAL = 0x00000000,
40 CHAR = 0x00000001,
41 CHAR_BOOL = 0x00000002,
42 CHAR_WORD = 0x00000004,
43 CHAR_VALUE = 0x00000008,
44 CHAR_STRING = 0x00000010,
45 CHAR_DONTCARE = 0x00000020,
46 BOOL = 0x00000040,
47 WORD = 0x00000080,
48 WORD_SEP = 0x00000100,
49 VALUE = 0x00000200,
50 VALUE_SEP = 0x00000400,
51 VALUE_EXP = 0x00000800,
52 VALUE_SIGN = 0x00001000,
53 VALUE_EXP_VALUE = 0x00002000,
54 VALUE_DIGIT = 0x00004000,
55 NAME_SEP = 0x20000000,
56 STRING_SEP = 0x40000000,
57 EXCLUDED = 0x80000000,
59 namespace o3tl {
60 template<> struct typed_flags<ParserFlags> : is_typed_flags<ParserFlags, 0xe0007fff> {};
64 namespace i18npool {
66 class cclass_Unicode : public cppu::WeakImplHelper < css::i18n::XCharacterClassification, css::lang::XServiceInfo >
68 public:
69 cclass_Unicode(const css::uno::Reference < css::uno::XComponentContext >& rxContext );
70 virtual ~cclass_Unicode() override;
72 virtual OUString SAL_CALL toUpper( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
73 const css::lang::Locale& rLocale ) override;
74 virtual OUString SAL_CALL toLower( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
75 const css::lang::Locale& rLocale ) override;
76 virtual OUString SAL_CALL toTitle( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
77 const css::lang::Locale& rLocale ) override;
78 virtual sal_Int16 SAL_CALL getType( const OUString& Text, sal_Int32 nPos ) override;
79 virtual sal_Int16 SAL_CALL getCharacterDirection( const OUString& Text, sal_Int32 nPos ) override;
80 virtual sal_Int16 SAL_CALL getScript( const OUString& Text, sal_Int32 nPos ) override;
81 virtual sal_Int32 SAL_CALL getCharacterType( const OUString& text, sal_Int32 nPos,
82 const css::lang::Locale& rLocale ) override;
83 virtual sal_Int32 SAL_CALL getStringType( const OUString& text, sal_Int32 nPos, sal_Int32 nCount,
84 const css::lang::Locale& rLocale ) override;
85 virtual css::i18n::ParseResult SAL_CALL parseAnyToken( const OUString& Text, sal_Int32 nPos,
86 const css::lang::Locale& rLocale, sal_Int32 nStartCharFlags, const OUString& userDefinedCharactersStart,
87 sal_Int32 nContCharFlags, const OUString& userDefinedCharactersCont ) override;
88 virtual css::i18n::ParseResult SAL_CALL parsePredefinedToken( sal_Int32 nTokenType, const OUString& Text,
89 sal_Int32 nPos, const css::lang::Locale& rLocale, sal_Int32 nStartCharFlags,
90 const OUString& userDefinedCharactersStart, sal_Int32 nContCharFlags,
91 const OUString& userDefinedCharactersCont ) override;
93 //XServiceInfo
94 virtual OUString SAL_CALL getImplementationName() override;
95 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
96 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
98 private:
99 std::unique_ptr<Transliteration_casemapping> trans;
101 // --- parser specific (implemented in cclass_unicode_parser.cxx) ---
103 enum ScanState
105 ssGetChar, // initial state; -> ssBounce, ssGetValue, ssRewindFromValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop
106 ssGetValue, // -> ssBounce, ssRewindFromValue, ssStopBack, ssGetWord
107 ssGetWord, // -> ssBounce, ssStop, ssStopBack
108 ssGetWordFirstChar, // -> ssBounce, ssGetWord, ssStop, ssStopBack
109 ssGetString, // -> ssBounce, ssStop
110 ssGetBool, // -> ssBounce, ssStop, ssStopBack
111 ssRewindFromValue, // -> ssBounce, ssGetValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop, ssIgnoreLeadingInRewind
112 ssIgnoreLeadingInRewind, // -> ssBounce, ssGetValue, ssRewindFromValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop
113 ssStopBack, // -> ssStop
114 ssBounce, // -> ssStopBack
115 ssStop
118 static const sal_uInt8 nDefCnt;
119 static const ParserFlags pDefaultParserTable[];
120 static const sal_Int32 pParseTokensType[];
122 /// If and where c occurs in pStr
123 static const sal_Unicode* StrChr( const sal_Unicode* pStr, sal_uInt32 c );
126 css::uno::Reference < css::uno::XComponentContext > m_xContext;
128 /// used for parser only
129 css::lang::Locale aParserLocale;
130 css::uno::Reference < css::i18n::XLocaleData5 > mxLocaleData;
131 css::uno::Reference < css::i18n::XNativeNumberSupplier > xNatNumSup;
132 OUString aStartChars;
133 OUString aContChars;
134 std::unique_ptr<ParserFlags[]> pTable;
135 std::unique_ptr<ParserFlags[]> pStart;
136 std::unique_ptr<ParserFlags[]> pCont;
137 sal_Int32 nStartTypes;
138 sal_Int32 nContTypes;
139 ScanState eState;
140 sal_Unicode cGroupSep;
141 sal_Unicode cDecimalSep;
142 sal_Unicode cDecimalSepAlt;
144 /// Get corresponding KParseTokens flag for a character
145 static sal_Int32 getParseTokensType(sal_uInt32 c, bool isFirst);
147 /// Access parser table flags.
148 ParserFlags getFlags(sal_uInt32 c);
150 /// Access parser flags via International and special definitions.
151 ParserFlags getFlagsExtended(sal_uInt32 c);
153 /// Access parser table flags for user defined start characters.
154 ParserFlags getStartCharsFlags( sal_uInt32 c );
156 /// Access parser table flags for user defined continuation characters.
157 ParserFlags getContCharsFlags( sal_Unicode c );
159 /// Setup parser table. Calls initParserTable() only if needed.
160 void setupParserTable( const css::lang::Locale& rLocale, sal_Int32 startCharTokenType,
161 const OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType,
162 const OUString& userDefinedCharactersCont );
164 /// Init parser table.
165 void initParserTable( const css::lang::Locale& rLocale, sal_Int32 startCharTokenType,
166 const OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType,
167 const OUString& userDefinedCharactersCont );
169 /// Destroy parser table.
170 void destroyParserTable();
172 /// Parse a text.
173 void parseText( css::i18n::ParseResult& r, const OUString& rText, sal_Int32 nPos,
174 sal_Int32 nTokenType = 0xffffffff );
176 /// Setup International class, new'ed only if different from existing.
177 void setupInternational( const css::lang::Locale& rLocale );
179 /// Implementation of getCharacterType() for one single character
180 static sal_Int32 getCharType( const OUString& Text, sal_Int32 *nPos, sal_Int32 increment);
186 #endif
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */