xref: /trunk/main/i18npool/inc/cclass_unicode.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 );
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 );
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 );
52     virtual sal_Int16 SAL_CALL getType( const rtl::OUString& Text, sal_Int32 nPos );
53     virtual sal_Int16 SAL_CALL getCharacterDirection( const rtl::OUString& Text, sal_Int32 nPos );
54     virtual sal_Int16 SAL_CALL getScript( const rtl::OUString& Text, sal_Int32 nPos );
55     virtual sal_Int32 SAL_CALL getCharacterType( const rtl::OUString& text, sal_Int32 nPos,
56         const com::sun::star::lang::Locale& rLocale );
57     virtual sal_Int32 SAL_CALL getStringType( const rtl::OUString& text, sal_Int32 nPos, sal_Int32 nCount,
58         const com::sun::star::lang::Locale& rLocale );
59     virtual ParseResult SAL_CALL parseAnyToken( const rtl::OUString& Text, sal_Int32 nPos,
60         const com::sun::star::lang::Locale& rLocale, sal_Int32 nStartCharFlags, const rtl::OUString& userDefinedCharactersStart,
61         sal_Int32 nContCharFlags, const rtl::OUString& userDefinedCharactersCont );
62     virtual ParseResult SAL_CALL parsePredefinedToken( sal_Int32 nTokenType, const rtl::OUString& Text,
63         sal_Int32 nPos, const com::sun::star::lang::Locale& rLocale, sal_Int32 nStartCharFlags,
64         const rtl::OUString& userDefinedCharactersStart, sal_Int32 nContCharFlags,
65         const rtl::OUString& userDefinedCharactersCont );
66 
67     //XServiceInfo
68     virtual rtl::OUString SAL_CALL getImplementationName();
69     virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName);
70     virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames();
71 
72 protected:
73     const sal_Char *cClass;
74 
75 private:
76     Transliteration_casemapping *trans;
77 
78 // --- parser specific (implemented in cclass_unicode_parser.cxx) ---
79 
80     enum ScanState
81     {
82         ssGetChar,
83         ssGetValue,
84         ssGetWord,
85         ssGetWordFirstChar,
86         ssGetString,
87         ssGetBool,
88         ssRewindFromValue,
89         ssIgnoreLeadingInRewind,
90         ssStopBack,
91         ssBounce,
92         ssStop
93     };
94 
95     static const sal_uInt8      nDefCnt;
96     static const UPT_FLAG_TYPE  pDefaultParserTable[];
97     static const sal_Int32      pParseTokensType[];
98 
99     /// Flag values of table.
100     static const UPT_FLAG_TYPE  TOKEN_ILLEGAL;
101     static const UPT_FLAG_TYPE  TOKEN_CHAR;
102     static const UPT_FLAG_TYPE  TOKEN_CHAR_BOOL;
103     static const UPT_FLAG_TYPE  TOKEN_CHAR_WORD;
104     static const UPT_FLAG_TYPE  TOKEN_CHAR_VALUE;
105     static const UPT_FLAG_TYPE  TOKEN_CHAR_STRING;
106     static const UPT_FLAG_TYPE  TOKEN_CHAR_DONTCARE;
107     static const UPT_FLAG_TYPE  TOKEN_BOOL;
108     static const UPT_FLAG_TYPE  TOKEN_WORD;
109     static const UPT_FLAG_TYPE  TOKEN_WORD_SEP;
110     static const UPT_FLAG_TYPE  TOKEN_VALUE;
111     static const UPT_FLAG_TYPE  TOKEN_VALUE_SEP;
112     static const UPT_FLAG_TYPE  TOKEN_VALUE_EXP;
113     static const UPT_FLAG_TYPE  TOKEN_VALUE_SIGN;
114     static const UPT_FLAG_TYPE  TOKEN_VALUE_EXP_VALUE;
115     static const UPT_FLAG_TYPE  TOKEN_VALUE_DIGIT;
116     static const UPT_FLAG_TYPE  TOKEN_NAME_SEP;
117     static const UPT_FLAG_TYPE  TOKEN_STRING_SEP;
118     static const UPT_FLAG_TYPE  TOKEN_EXCLUDED;
119 
120     /// If and where c occurs in pStr
121     static  const sal_Unicode*  StrChr( const sal_Unicode* pStr, sal_Unicode c );
122 
123 
124     com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xMSF;
125 
126     /// used for parser only
127     com::sun::star::lang::Locale    aParserLocale;
128     com::sun::star::uno::Reference < XLocaleData > xLocaleData;
129     com::sun::star::uno::Reference < com::sun::star::i18n::XNativeNumberSupplier > xNatNumSup;
130     rtl::OUString             aStartChars;
131     rtl::OUString             aContChars;
132     UPT_FLAG_TYPE*              pTable;
133     UPT_FLAG_TYPE*              pStart;
134     UPT_FLAG_TYPE*              pCont;
135     sal_Int32                   nStartTypes;
136     sal_Int32                   nContTypes;
137     ScanState                   eState;
138     sal_Unicode                 cGroupSep;
139     sal_Unicode                 cDecimalSep;
140 
141     /// Get corresponding KParseTokens flag for a character
142     sal_Int32 getParseTokensType( const sal_Unicode* aStr, sal_Int32 nPos );
143 
144     /// Access parser table flags.
145     UPT_FLAG_TYPE getFlags( const sal_Unicode* aStr, sal_Int32 nPos );
146 
147     /// Access parser flags via International and special definitions.
148     UPT_FLAG_TYPE getFlagsExtended( const sal_Unicode* aStr, sal_Int32 nPos );
149 
150     /// Access parser table flags for user defined start characters.
151     UPT_FLAG_TYPE getStartCharsFlags( sal_Unicode c );
152 
153     /// Access parser table flags for user defined continuation characters.
154     UPT_FLAG_TYPE getContCharsFlags( sal_Unicode c );
155 
156     /// Setup parser table. Calls initParserTable() only if needed.
157     void setupParserTable( const com::sun::star::lang::Locale& rLocale, sal_Int32 startCharTokenType,
158         const rtl::OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType,
159         const rtl::OUString& userDefinedCharactersCont );
160 
161     /// Init parser table.
162     void initParserTable( 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     /// Destroy parser table.
167     void destroyParserTable();
168 
169     /// Parse a text.
170     void parseText( ParseResult& r, const rtl::OUString& rText, sal_Int32 nPos,
171         sal_Int32 nTokenType = 0xffffffff );
172 
173     /// Setup International class, new'ed only if different from existing.
174     sal_Bool setupInternational( const com::sun::star::lang::Locale& rLocale );
175 
176     /// Implementation of getCharacterType() for one single character
177     sal_Int32 SAL_CALL getCharType( const rtl::OUString& Text, sal_Int32 *nPos, sal_Int32 increment);
178 
179 };
180 
181 } } } }
182 
183 #endif
184