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