Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / i18npool / inc / cclass_unicode.hxx
blobcbcb6f9baaa7646033cb54b1f62c605956df99bc
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/XNativeNumberSupplier.hpp>
23 #include <com/sun/star/i18n/XCharacterClassification.hpp>
24 #include <com/sun/star/i18n/XLocaleData4.hpp>
25 #include <cppuhelper/implbase.hxx>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <transliteration_body.hxx>
30 namespace com { namespace sun { namespace star { namespace uno {
31 class XComponentContext;
32 } } } }
34 namespace com { namespace sun { namespace star { namespace i18n {
36 typedef sal_uInt32 UPT_FLAG_TYPE;
38 class cclass_Unicode : public cppu::WeakImplHelper < XCharacterClassification, css::lang::XServiceInfo >
40 public:
41 cclass_Unicode(const css::uno::Reference < css::uno::XComponentContext >& rxContext );
42 virtual ~cclass_Unicode();
44 virtual OUString SAL_CALL toUpper( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
45 const css::lang::Locale& rLocale ) throw(css::uno::RuntimeException, std::exception) override;
46 virtual OUString SAL_CALL toLower( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
47 const css::lang::Locale& rLocale ) throw(css::uno::RuntimeException, std::exception) override;
48 virtual OUString SAL_CALL toTitle( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
49 const css::lang::Locale& rLocale ) throw(css::uno::RuntimeException, std::exception) override;
50 virtual sal_Int16 SAL_CALL getType( const OUString& Text, sal_Int32 nPos ) throw(css::uno::RuntimeException, std::exception) override;
51 virtual sal_Int16 SAL_CALL getCharacterDirection( const OUString& Text, sal_Int32 nPos )
52 throw(css::uno::RuntimeException, std::exception) override;
53 virtual sal_Int16 SAL_CALL getScript( const OUString& Text, sal_Int32 nPos ) throw(css::uno::RuntimeException, std::exception) override;
54 virtual sal_Int32 SAL_CALL getCharacterType( const OUString& text, sal_Int32 nPos,
55 const css::lang::Locale& rLocale ) throw(css::uno::RuntimeException, std::exception) override;
56 virtual sal_Int32 SAL_CALL getStringType( const OUString& text, sal_Int32 nPos, sal_Int32 nCount,
57 const css::lang::Locale& rLocale ) throw(css::uno::RuntimeException, std::exception) override;
58 virtual ParseResult SAL_CALL parseAnyToken( const OUString& Text, sal_Int32 nPos,
59 const css::lang::Locale& rLocale, sal_Int32 nStartCharFlags, const OUString& userDefinedCharactersStart,
60 sal_Int32 nContCharFlags, const OUString& userDefinedCharactersCont ) throw(css::uno::RuntimeException, std::exception) override;
61 virtual ParseResult SAL_CALL parsePredefinedToken( sal_Int32 nTokenType, const OUString& Text,
62 sal_Int32 nPos, const css::lang::Locale& rLocale, sal_Int32 nStartCharFlags,
63 const OUString& userDefinedCharactersStart, sal_Int32 nContCharFlags,
64 const OUString& userDefinedCharactersCont ) throw(css::uno::RuntimeException, std::exception) override;
66 //XServiceInfo
67 virtual OUString SAL_CALL getImplementationName() throw( css::uno::RuntimeException, std::exception ) override;
68 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw( css::uno::RuntimeException, std::exception ) override;
69 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( css::uno::RuntimeException, std::exception ) override;
71 private:
72 Transliteration_casemapping *trans;
74 // --- parser specific (implemented in cclass_unicode_parser.cxx) ---
76 enum ScanState
78 ssGetChar, // initial state; -> ssBounce, ssGetValue, ssRewindFromValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop
79 ssGetValue, // -> ssBounce, ssRewindFromValue, ssStopBack, ssGetWord
80 ssGetWord, // -> ssBounce, ssStop, ssStopBack
81 ssGetWordFirstChar, // -> ssBounce, ssGetWord, ssStop, ssStopBack
82 ssGetString, // -> ssBounce, ssStop
83 ssGetBool, // -> ssBounce, ssStop, ssStopBack
84 ssRewindFromValue, // -> ssBounce, ssGetValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop, ssIgnoreLeadingInRewind
85 ssIgnoreLeadingInRewind, // -> ssBounce, ssGetValue, ssRewindFromValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop
86 ssStopBack, // -> ssStop
87 ssBounce, // -> ssStopBack
88 ssStop
91 static const sal_uInt8 nDefCnt;
92 static const UPT_FLAG_TYPE pDefaultParserTable[];
93 static const sal_Int32 pParseTokensType[];
95 /// Flag values of table.
96 static const UPT_FLAG_TYPE TOKEN_ILLEGAL;
97 static const UPT_FLAG_TYPE TOKEN_CHAR;
98 static const UPT_FLAG_TYPE TOKEN_CHAR_BOOL;
99 static const UPT_FLAG_TYPE TOKEN_CHAR_WORD;
100 static const UPT_FLAG_TYPE TOKEN_CHAR_VALUE;
101 static const UPT_FLAG_TYPE TOKEN_CHAR_STRING;
102 static const UPT_FLAG_TYPE TOKEN_CHAR_DONTCARE;
103 static const UPT_FLAG_TYPE TOKEN_BOOL;
104 static const UPT_FLAG_TYPE TOKEN_WORD;
105 static const UPT_FLAG_TYPE TOKEN_WORD_SEP;
106 static const UPT_FLAG_TYPE TOKEN_VALUE;
107 static const UPT_FLAG_TYPE TOKEN_VALUE_SEP;
108 static const UPT_FLAG_TYPE TOKEN_VALUE_EXP;
109 static const UPT_FLAG_TYPE TOKEN_VALUE_SIGN;
110 static const UPT_FLAG_TYPE TOKEN_VALUE_EXP_VALUE;
111 static const UPT_FLAG_TYPE TOKEN_VALUE_DIGIT;
112 static const UPT_FLAG_TYPE TOKEN_NAME_SEP;
113 static const UPT_FLAG_TYPE TOKEN_STRING_SEP;
114 static const UPT_FLAG_TYPE TOKEN_EXCLUDED;
116 /// If and where c occurs in pStr
117 static const sal_Unicode* StrChr( const sal_Unicode* pStr, sal_Unicode c );
120 css::uno::Reference < css::uno::XComponentContext > m_xContext;
122 /// used for parser only
123 css::lang::Locale aParserLocale;
124 css::uno::Reference < XLocaleData4 > mxLocaleData;
125 css::uno::Reference < css::i18n::XNativeNumberSupplier > xNatNumSup;
126 OUString aStartChars;
127 OUString aContChars;
128 UPT_FLAG_TYPE* pTable;
129 UPT_FLAG_TYPE* pStart;
130 UPT_FLAG_TYPE* pCont;
131 sal_Int32 nStartTypes;
132 sal_Int32 nContTypes;
133 ScanState eState;
134 sal_Unicode cGroupSep;
135 sal_Unicode cDecimalSep;
137 /// Get corresponding KParseTokens flag for a character
138 static sal_Int32 getParseTokensType(sal_uInt32 c, bool isFirst);
140 /// Access parser table flags.
141 UPT_FLAG_TYPE getFlags(sal_uInt32 c);
143 /// Access parser flags via International and special definitions.
144 UPT_FLAG_TYPE getFlagsExtended(sal_uInt32 c);
146 /// Access parser table flags for user defined start characters.
147 UPT_FLAG_TYPE getStartCharsFlags( sal_Unicode c );
149 /// Access parser table flags for user defined continuation characters.
150 UPT_FLAG_TYPE getContCharsFlags( sal_Unicode c );
152 /// Setup parser table. Calls initParserTable() only if needed.
153 void setupParserTable( const css::lang::Locale& rLocale, sal_Int32 startCharTokenType,
154 const OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType,
155 const OUString& userDefinedCharactersCont );
157 /// Init parser table.
158 void initParserTable( const css::lang::Locale& rLocale, sal_Int32 startCharTokenType,
159 const OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType,
160 const OUString& userDefinedCharactersCont );
162 /// Destroy parser table.
163 void destroyParserTable();
165 /// Parse a text.
166 void parseText( ParseResult& r, const OUString& rText, sal_Int32 nPos,
167 sal_Int32 nTokenType = 0xffffffff );
169 /// Setup International class, new'ed only if different from existing.
170 bool setupInternational( const css::lang::Locale& rLocale );
172 /// Implementation of getCharacterType() for one single character
173 static sal_Int32 SAL_CALL getCharType( const OUString& Text, sal_Int32 *nPos, sal_Int32 increment);
177 } } } }
179 #endif
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */