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_BREAKITERATOR_HXX_
24 #define _I18N_BREAKITERATOR_HXX_
25 
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <comphelper/processfactory.hxx>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/beans/PropertyValues.hpp>
30 #include <com/sun/star/i18n/XBreakIterator.hpp>
31 #include <com/sun/star/i18n/WordType.hpp>
32 #include <com/sun/star/i18n/BreakType.hpp>
33 #include <com/sun/star/i18n/ScriptType.hpp>
34 #include <com/sun/star/i18n/CharacterIteratorMode.hpp>
35 #include <com/sun/star/i18n/CharType.hpp>
36 #include <com/sun/star/i18n/XLocaleData.hpp>
37 #include <cppuhelper/implbase2.hxx> // helper for implementations
38 
39 #include <vector>
40 
41 namespace com { namespace sun { namespace star { namespace i18n {
42 
43 //	----------------------------------------------------
44 //	class BreakIterator
45 //	----------------------------------------------------
46 class BreakIteratorImpl : public cppu::WeakImplHelper2
47 <
48 	XBreakIterator,
49 	com::sun::star::lang::XServiceInfo
50 >
51 {
52 public:
53 	BreakIteratorImpl( const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rxMSF );
54 	BreakIteratorImpl();
55 	~BreakIteratorImpl();
56 
57 	virtual sal_Int32 SAL_CALL nextCharacters( const rtl::OUString& Text, sal_Int32 nStartPos,
58 		const com::sun::star::lang::Locale& rLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount,
59 		sal_Int32& nDone ) throw(com::sun::star::uno::RuntimeException);
60 	virtual sal_Int32 SAL_CALL previousCharacters( const rtl::OUString& Text, sal_Int32 nStartPos,
61 		const com::sun::star::lang::Locale& nLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount,
62 		sal_Int32& nDone ) throw(com::sun::star::uno::RuntimeException);
63 
64 	virtual Boundary SAL_CALL previousWord( const rtl::OUString& Text, sal_Int32 nStartPos,
65 		const com::sun::star::lang::Locale& nLocale, sal_Int16 WordType) throw(com::sun::star::uno::RuntimeException);
66 	virtual Boundary SAL_CALL nextWord( const rtl::OUString& Text, sal_Int32 nStartPos,
67 		const com::sun::star::lang::Locale& nLocale, sal_Int16 WordType) throw(com::sun::star::uno::RuntimeException);
68 	virtual Boundary SAL_CALL getWordBoundary( const rtl::OUString& Text, sal_Int32 nPos,
69 		const com::sun::star::lang::Locale& nLocale, sal_Int16 WordType, sal_Bool bDirection )
70 		throw(com::sun::star::uno::RuntimeException);
71 
72 	virtual sal_Bool SAL_CALL isBeginWord( const rtl::OUString& Text, sal_Int32 nPos,
73 		const com::sun::star::lang::Locale& nLocale, sal_Int16 WordType ) throw(com::sun::star::uno::RuntimeException);
74 	virtual sal_Bool SAL_CALL isEndWord( const rtl::OUString& Text, sal_Int32 nPos,
75 		const com::sun::star::lang::Locale& nLocale, sal_Int16 WordType ) throw(com::sun::star::uno::RuntimeException);
76 	virtual sal_Int16 SAL_CALL getWordType( const rtl::OUString& Text, sal_Int32 nPos,
77 		const com::sun::star::lang::Locale& nLocale ) throw(com::sun::star::uno::RuntimeException);
78 
79 	virtual sal_Int32 SAL_CALL beginOfSentence( const rtl::OUString& Text, sal_Int32 nStartPos,
80 		const com::sun::star::lang::Locale& nLocale ) throw(com::sun::star::uno::RuntimeException);
81 	virtual sal_Int32 SAL_CALL endOfSentence( const rtl::OUString& Text, sal_Int32 nStartPos,
82 		const com::sun::star::lang::Locale& nLocale ) throw(com::sun::star::uno::RuntimeException);
83 
84 	virtual LineBreakResults SAL_CALL getLineBreak( const rtl::OUString& Text, sal_Int32 nStartPos,
85 		const com::sun::star::lang::Locale& nLocale, sal_Int32 nMinBreakPos,
86 		const LineBreakHyphenationOptions& hOptions, const LineBreakUserOptions& bOptions )
87 		throw(com::sun::star::uno::RuntimeException);
88 
89 	virtual sal_Int16 SAL_CALL getScriptType( const rtl::OUString& Text, sal_Int32 nPos )
90 		throw(com::sun::star::uno::RuntimeException);
91 	virtual sal_Int32 SAL_CALL beginOfScript( const rtl::OUString& Text, sal_Int32 nStartPos,
92 		sal_Int16 ScriptType ) throw(com::sun::star::uno::RuntimeException);
93 	virtual sal_Int32 SAL_CALL endOfScript( const rtl::OUString& Text, sal_Int32 nStartPos,
94 		sal_Int16 ScriptType ) throw(com::sun::star::uno::RuntimeException);
95 	virtual sal_Int32 SAL_CALL previousScript( const rtl::OUString& Text, sal_Int32 nStartPos,
96 		sal_Int16 ScriptType ) throw(com::sun::star::uno::RuntimeException);
97 	virtual sal_Int32 SAL_CALL nextScript( const rtl::OUString& Text, sal_Int32 nStartPos,
98 		sal_Int16 ScriptType ) throw(com::sun::star::uno::RuntimeException);
99 
100 	virtual sal_Int32 SAL_CALL beginOfCharBlock( const rtl::OUString& Text, sal_Int32 nStartPos,
101 		const com::sun::star::lang::Locale& nLocale, sal_Int16 CharType ) throw(com::sun::star::uno::RuntimeException);
102 	virtual sal_Int32 SAL_CALL endOfCharBlock( const rtl::OUString& Text, sal_Int32 nStartPos,
103 		const com::sun::star::lang::Locale& nLocale, sal_Int16 CharType ) throw(com::sun::star::uno::RuntimeException);
104 	virtual sal_Int32 SAL_CALL previousCharBlock( const rtl::OUString& Text, sal_Int32 nStartPos,
105 		const com::sun::star::lang::Locale& nLocale, sal_Int16 CharType ) throw(com::sun::star::uno::RuntimeException);
106 	virtual sal_Int32 SAL_CALL nextCharBlock( const rtl::OUString& Text, sal_Int32 nStartPos,
107 		const com::sun::star::lang::Locale& nLocale, sal_Int16 CharType ) throw(com::sun::star::uno::RuntimeException);
108 
109 	//XServiceInfo
110 	virtual rtl::OUString SAL_CALL getImplementationName() throw( com::sun::star::uno::RuntimeException );
111 	virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName)
112 		throw( com::sun::star::uno::RuntimeException );
113 	virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames()
114 		throw( com::sun::star::uno::RuntimeException );
115 
116 	static sal_Int16 SAL_CALL getScriptClass(sal_uInt32 currentChar);
117 protected:
118 	Boundary result; // for word break iterator
119 
120 private :
121 
122 	struct lookupTableItem {
lookupTableItemcom::sun::star::i18n::BreakIteratorImpl::lookupTableItem123 	    lookupTableItem(const com::sun::star::lang::Locale& _aLocale, com::sun::star::uno::Reference < XBreakIterator >& _xBI) : aLocale(_aLocale), xBI(_xBI) {};
124 	    com::sun::star::lang::Locale aLocale;
125 	    com::sun::star::uno::Reference < XBreakIterator > xBI;
126 	};
127 	std::vector<lookupTableItem*> lookupTable;
128 	com::sun::star::lang::Locale aLocale;
129 	com::sun::star::uno::Reference < XBreakIterator > xBI;
130 
131 	com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xMSF;
132 	sal_Bool SAL_CALL createLocaleSpecificBreakIterator( const rtl::OUString& aLocaleName )
133 		throw( com::sun::star::uno::RuntimeException );
134 	com::sun::star::uno::Reference < XBreakIterator > SAL_CALL getLocaleSpecificBreakIterator( const com::sun::star::lang::Locale& rLocale )
135 		throw( com::sun::star::uno::RuntimeException );
136 	const com::sun::star::lang::Locale& SAL_CALL getLocaleByScriptType(const com::sun::star::lang::Locale& rLocale, const rtl::OUString& Text,
137 		sal_Int32 nStartPos, sal_Bool forward, sal_Bool skipWhiteSpace)
138 		throw(com::sun::star::uno::RuntimeException);
139 
140 };
141 
142 } // i18n
143 } // star
144 } // sun
145 } // com
146 
147 
148 #endif // _I18N_BREAKITERATOR_HXX_
149