xref: /aoo42x/main/i18npool/inc/cclass_unicode.hxx (revision f7bd9df4)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _I18N_CCLASS_UNICODE_HXX_
24 #define _I18N_CCLASS_UNICODE_HXX_
25 
26 #include <com/sun/star/i18n/XNativeNumberSupplier.hpp>
27 #include <com/sun/star/i18n/XCharacterClassification.hpp>
28 #include <com/sun/star/i18n/XLocaleData.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <cppuhelper/implbase1.hxx> // helper for implementations
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 
33 #define TRANSLITERATION_casemapping
34 #include <transliteration_body.hxx>
35 
36 namespace com { namespace sun { namespace star { namespace i18n {
37 
38 typedef sal_uInt32 UPT_FLAG_TYPE;
39 
40 class cclass_Unicode : public cppu::WeakImplHelper1 < XCharacterClassification >
41 {
42 public:
43 	cclass_Unicode(com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xSMgr );
44 	~cclass_Unicode();
45 
46 	virtual rtl::OUString SAL_CALL toUpper( const rtl::OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
47 		const com::sun::star::lang::Locale& rLocale ) throw(com::sun::star::uno::RuntimeException);
48 	virtual rtl::OUString SAL_CALL toLower( const rtl::OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
49 		const com::sun::star::lang::Locale& rLocale ) throw(com::sun::star::uno::RuntimeException);
50 	virtual rtl::OUString SAL_CALL toTitle( const rtl::OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
51 		const com::sun::star::lang::Locale& rLocale ) throw(com::sun::star::uno::RuntimeException);
52 	virtual sal_Int16 SAL_CALL getType( const rtl::OUString& Text, sal_Int32 nPos )  throw(com::sun::star::uno::RuntimeException);
53 	virtual sal_Int16 SAL_CALL getCharacterDirection( const rtl::OUString& Text, sal_Int32 nPos )
54 		throw(com::sun::star::uno::RuntimeException);
55 	virtual sal_Int16 SAL_CALL getScript( const rtl::OUString& Text, sal_Int32 nPos ) throw(com::sun::star::uno::RuntimeException);
56 	virtual sal_Int32 SAL_CALL getCharacterType( const rtl::OUString& text, sal_Int32 nPos,
57 		const com::sun::star::lang::Locale& rLocale ) throw(com::sun::star::uno::RuntimeException);
58 	virtual sal_Int32 SAL_CALL getStringType( const rtl::OUString& text, sal_Int32 nPos, sal_Int32 nCount,
59 		const com::sun::star::lang::Locale& rLocale ) throw(com::sun::star::uno::RuntimeException);
60 	virtual ParseResult SAL_CALL parseAnyToken( const rtl::OUString& Text, sal_Int32 nPos,
61 		const com::sun::star::lang::Locale& rLocale, sal_Int32 nStartCharFlags, const rtl::OUString& userDefinedCharactersStart,
62 		sal_Int32 nContCharFlags, const rtl::OUString& userDefinedCharactersCont ) throw(com::sun::star::uno::RuntimeException);
63 	virtual ParseResult SAL_CALL parsePredefinedToken( sal_Int32 nTokenType, const rtl::OUString& Text,
64 		sal_Int32 nPos, const com::sun::star::lang::Locale& rLocale, sal_Int32 nStartCharFlags,
65 		const rtl::OUString& userDefinedCharactersStart, sal_Int32 nContCharFlags,
66 		const rtl::OUString& userDefinedCharactersCont ) throw(com::sun::star::uno::RuntimeException);
67 
68 	//XServiceInfo
69 	virtual rtl::OUString SAL_CALL getImplementationName() throw( com::sun::star::uno::RuntimeException );
70 	virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( com::sun::star::uno::RuntimeException );
71 	virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw( com::sun::star::uno::RuntimeException );
72 
73 protected:
74 	const sal_Char *cClass;
75 
76 private:
77 	Transliteration_casemapping *trans;
78 
79 // --- parser specific (implemented in cclass_unicode_parser.cxx) ---
80 
81 	enum ScanState
82 	{
83 		ssGetChar,
84 		ssGetValue,
85 		ssGetWord,
86 		ssGetWordFirstChar,
87 		ssGetString,
88 		ssGetBool,
89         ssRewindFromValue,
90         ssIgnoreLeadingInRewind,
91 		ssStopBack,
92 		ssBounce,
93 		ssStop
94 	};
95 
96 	static const sal_uInt8		nDefCnt;
97 	static const UPT_FLAG_TYPE	pDefaultParserTable[];
98 	static const sal_Int32		pParseTokensType[];
99 
100 	/// Flag values of table.
101 	static const UPT_FLAG_TYPE	TOKEN_ILLEGAL;
102 	static const UPT_FLAG_TYPE	TOKEN_CHAR;
103 	static const UPT_FLAG_TYPE	TOKEN_CHAR_BOOL;
104 	static const UPT_FLAG_TYPE	TOKEN_CHAR_WORD;
105 	static const UPT_FLAG_TYPE	TOKEN_CHAR_VALUE;
106 	static const UPT_FLAG_TYPE	TOKEN_CHAR_STRING;
107 	static const UPT_FLAG_TYPE	TOKEN_CHAR_DONTCARE;
108 	static const UPT_FLAG_TYPE	TOKEN_BOOL;
109 	static const UPT_FLAG_TYPE	TOKEN_WORD;
110 	static const UPT_FLAG_TYPE	TOKEN_WORD_SEP;
111 	static const UPT_FLAG_TYPE	TOKEN_VALUE;
112 	static const UPT_FLAG_TYPE	TOKEN_VALUE_SEP;
113 	static const UPT_FLAG_TYPE	TOKEN_VALUE_EXP;
114 	static const UPT_FLAG_TYPE	TOKEN_VALUE_SIGN;
115 	static const UPT_FLAG_TYPE	TOKEN_VALUE_EXP_VALUE;
116 	static const UPT_FLAG_TYPE	TOKEN_VALUE_DIGIT;
117 	static const UPT_FLAG_TYPE	TOKEN_NAME_SEP;
118 	static const UPT_FLAG_TYPE	TOKEN_STRING_SEP;
119 	static const UPT_FLAG_TYPE	TOKEN_EXCLUDED;
120 
121 	/// If and where c occurs in pStr
122 	static	const sal_Unicode*	StrChr( const sal_Unicode* pStr, sal_Unicode c );
123 
124 
125 	com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xMSF;
126 
127 	/// used for parser only
128 	com::sun::star::lang::Locale	aParserLocale;
129 	com::sun::star::uno::Reference < XLocaleData > xLocaleData;
130 	com::sun::star::uno::Reference < com::sun::star::i18n::XNativeNumberSupplier > xNatNumSup;
131 	rtl::OUString             aStartChars;
132 	rtl::OUString             aContChars;
133 	UPT_FLAG_TYPE*				pTable;
134 	UPT_FLAG_TYPE*				pStart;
135 	UPT_FLAG_TYPE*				pCont;
136 	sal_Int32					nStartTypes;
137 	sal_Int32					nContTypes;
138 	ScanState					eState;
139 	sal_Unicode					cGroupSep;
140 	sal_Unicode					cDecimalSep;
141 
142 	/// Get corresponding KParseTokens flag for a character
143 	sal_Int32 getParseTokensType( const sal_Unicode* aStr, sal_Int32 nPos );
144 
145 	/// Access parser table flags.
146 	UPT_FLAG_TYPE getFlags( const sal_Unicode* aStr, sal_Int32 nPos );
147 
148 	/// Access parser flags via International and special definitions.
149 	UPT_FLAG_TYPE getFlagsExtended( const sal_Unicode* aStr, sal_Int32 nPos );
150 
151 	/// Access parser table flags for user defined start characters.
152 	UPT_FLAG_TYPE getStartCharsFlags( sal_Unicode c );
153 
154 	/// Access parser table flags for user defined continuation characters.
155 	UPT_FLAG_TYPE getContCharsFlags( sal_Unicode c );
156 
157 	/// Setup parser table. Calls initParserTable() only if needed.
158 	void setupParserTable( const com::sun::star::lang::Locale& rLocale, sal_Int32 startCharTokenType,
159 		const rtl::OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType,
160 		const rtl::OUString& userDefinedCharactersCont );
161 
162 	/// Init parser table.
163 	void initParserTable( const com::sun::star::lang::Locale& rLocale, sal_Int32 startCharTokenType,
164 		const rtl::OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType,
165 		const rtl::OUString& userDefinedCharactersCont );
166 
167 	/// Destroy parser table.
168 	void destroyParserTable();
169 
170 	/// Parse a text.
171 	void parseText( ParseResult& r, const rtl::OUString& rText, sal_Int32 nPos,
172 		sal_Int32 nTokenType = 0xffffffff );
173 
174 	/// Setup International class, new'ed only if different from existing.
175 	sal_Bool setupInternational( const com::sun::star::lang::Locale& rLocale );
176 
177 	/// Implementation of getCharacterType() for one single character
178     sal_Int32 SAL_CALL getCharType( const rtl::OUString& Text, sal_Int32 *nPos, sal_Int32 increment);
179 
180 };
181 
182 } } } }
183 
184 #endif
185