1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
27 #ifndef _I18N_CCLASS_UNICODE_HXX_
28 #define _I18N_CCLASS_UNICODE_HXX_
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>
37 #define TRANSLITERATION_casemapping
38 #include <transliteration_body.hxx>
40 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
42 typedef sal_uInt32 UPT_FLAG_TYPE
;
44 class cclass_Unicode
: public cppu::WeakImplHelper1
< XCharacterClassification
>
47 cclass_Unicode(com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> xSMgr
);
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
);
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
);
78 const sal_Char
*cClass
;
81 Transliteration_casemapping
*trans
;
83 // --- parser specific (implemented in cclass_unicode_parser.cxx) ---
94 ssIgnoreLeadingInRewind
,
100 static const sal_uInt8 nDefCnt
;
101 static const UPT_FLAG_TYPE pDefaultParserTable
[];
102 static const sal_Int32 pParseTokensType
[];
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
;
125 /// If and where c occurs in pStr
126 static const sal_Unicode
* StrChr( const sal_Unicode
* pStr
, sal_Unicode c
);
129 com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> xMSF
;
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
;
143 sal_Unicode cGroupSep
;
144 sal_Unicode cDecimalSep
;
146 /// Get corresponding KParseTokens flag for a character
147 sal_Int32
getParseTokensType( const sal_Unicode
* aStr
, sal_Int32 nPos
);
149 /// Access parser table flags.
150 UPT_FLAG_TYPE
getFlags( const sal_Unicode
* aStr
, sal_Int32 nPos
);
152 /// Access parser flags via International and special definitions.
153 UPT_FLAG_TYPE
getFlagsExtended( const sal_Unicode
* aStr
, sal_Int32 nPos
);
155 /// Access parser table flags for user defined start characters.
156 UPT_FLAG_TYPE
getStartCharsFlags( sal_Unicode c
);
158 /// Access parser table flags for user defined continuation characters.
159 UPT_FLAG_TYPE
getContCharsFlags( sal_Unicode c
);
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
);
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
);
171 /// Destroy parser table.
172 void destroyParserTable();
175 void parseText( ParseResult
& r
, const rtl::OUString
& rText
, sal_Int32 nPos
,
176 sal_Int32 nTokenType
= 0xffffffff );
178 /// Setup International class, new'ed only if different from existing.
179 sal_Bool
setupInternational( const com::sun::star::lang::Locale
& rLocale
);
181 /// Implementation of getCharacterType() for one single character
182 sal_Int32 SAL_CALL
getCharType( const rtl::OUString
& Text
, sal_Int32
*nPos
, sal_Int32 increment
);