xref: /aoo41x/main/i18npool/inc/cclass_unicode.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _I18N_CCLASS_UNICODE_HXX_
28 #define _I18N_CCLASS_UNICODE_HXX_
29 
30 #include <com/sun/star/i18n/XNativeNumberSupplier.hpp>
31 #include <com/sun/star/i18n/XCharacterClassification.hpp>
32 #include <com/sun/star/i18n/XLocaleData.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <cppuhelper/implbase1.hxx> // helper for implementations
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 
37 #define TRANSLITERATION_casemapping
38 #include <transliteration_body.hxx>
39 
40 namespace com { namespace sun { namespace star { namespace i18n {
41 
42 typedef sal_uInt32 UPT_FLAG_TYPE;
43 
44 class cclass_Unicode : public cppu::WeakImplHelper1 < XCharacterClassification >
45 {
46 public:
47 	cclass_Unicode(com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xSMgr );
48 	~cclass_Unicode();
49 
50 	virtual rtl::OUString SAL_CALL toUpper( 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 rtl::OUString SAL_CALL toLower( const rtl::OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
53 		const com::sun::star::lang::Locale& rLocale ) throw(com::sun::star::uno::RuntimeException);
54 	virtual rtl::OUString SAL_CALL toTitle( const rtl::OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
55 		const com::sun::star::lang::Locale& rLocale ) throw(com::sun::star::uno::RuntimeException);
56 	virtual sal_Int16 SAL_CALL getType( const rtl::OUString& Text, sal_Int32 nPos )  throw(com::sun::star::uno::RuntimeException);
57 	virtual sal_Int16 SAL_CALL getCharacterDirection( const rtl::OUString& Text, sal_Int32 nPos )
58 		throw(com::sun::star::uno::RuntimeException);
59 	virtual sal_Int16 SAL_CALL getScript( const rtl::OUString& Text, sal_Int32 nPos ) throw(com::sun::star::uno::RuntimeException);
60 	virtual sal_Int32 SAL_CALL getCharacterType( const rtl::OUString& text, sal_Int32 nPos,
61 		const com::sun::star::lang::Locale& rLocale ) throw(com::sun::star::uno::RuntimeException);
62 	virtual sal_Int32 SAL_CALL getStringType( const rtl::OUString& text, sal_Int32 nPos, sal_Int32 nCount,
63 		const com::sun::star::lang::Locale& rLocale ) throw(com::sun::star::uno::RuntimeException);
64 	virtual ParseResult SAL_CALL parseAnyToken( const rtl::OUString& Text, sal_Int32 nPos,
65 		const com::sun::star::lang::Locale& rLocale, sal_Int32 nStartCharFlags, const rtl::OUString& userDefinedCharactersStart,
66 		sal_Int32 nContCharFlags, const rtl::OUString& userDefinedCharactersCont ) throw(com::sun::star::uno::RuntimeException);
67 	virtual ParseResult SAL_CALL parsePredefinedToken( sal_Int32 nTokenType, const rtl::OUString& Text,
68 		sal_Int32 nPos, const com::sun::star::lang::Locale& rLocale, sal_Int32 nStartCharFlags,
69 		const rtl::OUString& userDefinedCharactersStart, sal_Int32 nContCharFlags,
70 		const rtl::OUString& userDefinedCharactersCont ) throw(com::sun::star::uno::RuntimeException);
71 
72 	//XServiceInfo
73 	virtual rtl::OUString SAL_CALL getImplementationName() throw( com::sun::star::uno::RuntimeException );
74 	virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( com::sun::star::uno::RuntimeException );
75 	virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw( com::sun::star::uno::RuntimeException );
76 
77 protected:
78 	const sal_Char *cClass;
79 
80 private:
81 	Transliteration_casemapping *trans;
82 
83 // --- parser specific (implemented in cclass_unicode_parser.cxx) ---
84 
85 	enum ScanState
86 	{
87 		ssGetChar,
88 		ssGetValue,
89 		ssGetWord,
90 		ssGetWordFirstChar,
91 		ssGetString,
92 		ssGetBool,
93         ssRewindFromValue,
94         ssIgnoreLeadingInRewind,
95 		ssStopBack,
96 		ssBounce,
97 		ssStop
98 	};
99 
100 	static const sal_uInt8		nDefCnt;
101 	static const UPT_FLAG_TYPE	pDefaultParserTable[];
102 	static const sal_Int32		pParseTokensType[];
103 
104 	/// Flag values of table.
105 	static const UPT_FLAG_TYPE	TOKEN_ILLEGAL;
106 	static const UPT_FLAG_TYPE	TOKEN_CHAR;
107 	static const UPT_FLAG_TYPE	TOKEN_CHAR_BOOL;
108 	static const UPT_FLAG_TYPE	TOKEN_CHAR_WORD;
109 	static const UPT_FLAG_TYPE	TOKEN_CHAR_VALUE;
110 	static const UPT_FLAG_TYPE	TOKEN_CHAR_STRING;
111 	static const UPT_FLAG_TYPE	TOKEN_CHAR_DONTCARE;
112 	static const UPT_FLAG_TYPE	TOKEN_BOOL;
113 	static const UPT_FLAG_TYPE	TOKEN_WORD;
114 	static const UPT_FLAG_TYPE	TOKEN_WORD_SEP;
115 	static const UPT_FLAG_TYPE	TOKEN_VALUE;
116 	static const UPT_FLAG_TYPE	TOKEN_VALUE_SEP;
117 	static const UPT_FLAG_TYPE	TOKEN_VALUE_EXP;
118 	static const UPT_FLAG_TYPE	TOKEN_VALUE_SIGN;
119 	static const UPT_FLAG_TYPE	TOKEN_VALUE_EXP_VALUE;
120 	static const UPT_FLAG_TYPE	TOKEN_VALUE_DIGIT;
121 	static const UPT_FLAG_TYPE	TOKEN_NAME_SEP;
122 	static const UPT_FLAG_TYPE	TOKEN_STRING_SEP;
123 	static const UPT_FLAG_TYPE	TOKEN_EXCLUDED;
124 
125 	/// If and where c occurs in pStr
126 	static	const sal_Unicode*	StrChr( const sal_Unicode* pStr, sal_Unicode c );
127 
128 
129 	com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xMSF;
130 
131 	/// used for parser only
132 	com::sun::star::lang::Locale	aParserLocale;
133 	com::sun::star::uno::Reference < XLocaleData > xLocaleData;
134 	com::sun::star::uno::Reference < com::sun::star::i18n::XNativeNumberSupplier > xNatNumSup;
135 	rtl::OUString             aStartChars;
136 	rtl::OUString             aContChars;
137 	UPT_FLAG_TYPE*				pTable;
138 	UPT_FLAG_TYPE*				pStart;
139 	UPT_FLAG_TYPE*				pCont;
140 	sal_Int32					nStartTypes;
141 	sal_Int32					nContTypes;
142 	ScanState					eState;
143 	sal_Unicode					cGroupSep;
144 	sal_Unicode					cDecimalSep;
145 
146 	/// Get corresponding KParseTokens flag for a character
147 	sal_Int32 getParseTokensType( const sal_Unicode* aStr, sal_Int32 nPos );
148 
149 	/// Access parser table flags.
150 	UPT_FLAG_TYPE getFlags( const sal_Unicode* aStr, sal_Int32 nPos );
151 
152 	/// Access parser flags via International and special definitions.
153 	UPT_FLAG_TYPE getFlagsExtended( const sal_Unicode* aStr, sal_Int32 nPos );
154 
155 	/// Access parser table flags for user defined start characters.
156 	UPT_FLAG_TYPE getStartCharsFlags( sal_Unicode c );
157 
158 	/// Access parser table flags for user defined continuation characters.
159 	UPT_FLAG_TYPE getContCharsFlags( sal_Unicode c );
160 
161 	/// Setup parser table. Calls initParserTable() only if needed.
162 	void setupParserTable( const com::sun::star::lang::Locale& rLocale, sal_Int32 startCharTokenType,
163 		const rtl::OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType,
164 		const rtl::OUString& userDefinedCharactersCont );
165 
166 	/// Init parser table.
167 	void initParserTable( const com::sun::star::lang::Locale& rLocale, sal_Int32 startCharTokenType,
168 		const rtl::OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType,
169 		const rtl::OUString& userDefinedCharactersCont );
170 
171 	/// Destroy parser table.
172 	void destroyParserTable();
173 
174 	/// Parse a text.
175 	void parseText( ParseResult& r, const rtl::OUString& rText, sal_Int32 nPos,
176 		sal_Int32 nTokenType = 0xffffffff );
177 
178 	/// Setup International class, new'ed only if different from existing.
179 	sal_Bool setupInternational( const com::sun::star::lang::Locale& rLocale );
180 
181 	/// Implementation of getCharacterType() for one single character
182     sal_Int32 SAL_CALL getCharType( const rtl::OUString& Text, sal_Int32 *nPos, sal_Int32 increment);
183 
184 };
185 
186 } } } }
187 
188 #endif
189