xref: /trunk/main/i18npool/inc/breakiteratorImpl.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_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 );
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 );
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);
66     virtual Boundary SAL_CALL nextWord( const rtl::OUString& Text, sal_Int32 nStartPos,
67         const com::sun::star::lang::Locale& nLocale, sal_Int16 WordType);
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 
71     virtual sal_Bool SAL_CALL isBeginWord( const rtl::OUString& Text, sal_Int32 nPos,
72         const com::sun::star::lang::Locale& nLocale, sal_Int16 WordType );
73     virtual sal_Bool SAL_CALL isEndWord( const rtl::OUString& Text, sal_Int32 nPos,
74         const com::sun::star::lang::Locale& nLocale, sal_Int16 WordType );
75     virtual sal_Int16 SAL_CALL getWordType( const rtl::OUString& Text, sal_Int32 nPos,
76         const com::sun::star::lang::Locale& nLocale );
77 
78     virtual sal_Int32 SAL_CALL beginOfSentence( const rtl::OUString& Text, sal_Int32 nStartPos,
79         const com::sun::star::lang::Locale& nLocale );
80     virtual sal_Int32 SAL_CALL endOfSentence( const rtl::OUString& Text, sal_Int32 nStartPos,
81         const com::sun::star::lang::Locale& nLocale );
82 
83     virtual LineBreakResults SAL_CALL getLineBreak( const rtl::OUString& Text, sal_Int32 nStartPos,
84         const com::sun::star::lang::Locale& nLocale, sal_Int32 nMinBreakPos,
85         const LineBreakHyphenationOptions& hOptions, const LineBreakUserOptions& bOptions );
86 
87     virtual sal_Int16 SAL_CALL getScriptType( const rtl::OUString& Text, sal_Int32 nPos );
88     virtual sal_Int32 SAL_CALL beginOfScript( const rtl::OUString& Text, sal_Int32 nStartPos,
89         sal_Int16 ScriptType );
90     virtual sal_Int32 SAL_CALL endOfScript( const rtl::OUString& Text, sal_Int32 nStartPos,
91         sal_Int16 ScriptType );
92     virtual sal_Int32 SAL_CALL previousScript( const rtl::OUString& Text, sal_Int32 nStartPos,
93         sal_Int16 ScriptType );
94     virtual sal_Int32 SAL_CALL nextScript( const rtl::OUString& Text, sal_Int32 nStartPos,
95         sal_Int16 ScriptType );
96 
97     virtual sal_Int32 SAL_CALL beginOfCharBlock( const rtl::OUString& Text, sal_Int32 nStartPos,
98         const com::sun::star::lang::Locale& nLocale, sal_Int16 CharType );
99     virtual sal_Int32 SAL_CALL endOfCharBlock( const rtl::OUString& Text, sal_Int32 nStartPos,
100         const com::sun::star::lang::Locale& nLocale, sal_Int16 CharType );
101     virtual sal_Int32 SAL_CALL previousCharBlock( const rtl::OUString& Text, sal_Int32 nStartPos,
102         const com::sun::star::lang::Locale& nLocale, sal_Int16 CharType );
103     virtual sal_Int32 SAL_CALL nextCharBlock( const rtl::OUString& Text, sal_Int32 nStartPos,
104         const com::sun::star::lang::Locale& nLocale, sal_Int16 CharType );
105 
106     //XServiceInfo
107     virtual rtl::OUString SAL_CALL getImplementationName();
108     virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName);
109     virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames();
110 
111     static sal_Int16 SAL_CALL getScriptClass(sal_uInt32 currentChar);
112 protected:
113     Boundary result; // for word break iterator
114 
115 private :
116 
117     struct lookupTableItem {
lookupTableItemcom::sun::star::i18n::BreakIteratorImpl::lookupTableItem118         lookupTableItem(const com::sun::star::lang::Locale& _aLocale, com::sun::star::uno::Reference < XBreakIterator >& _xBI) : aLocale(_aLocale), xBI(_xBI) {};
119         com::sun::star::lang::Locale aLocale;
120         com::sun::star::uno::Reference < XBreakIterator > xBI;
121     };
122     std::vector<lookupTableItem*> lookupTable;
123     com::sun::star::lang::Locale aLocale;
124     com::sun::star::uno::Reference < XBreakIterator > xBI;
125 
126     com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xMSF;
127     sal_Bool SAL_CALL createLocaleSpecificBreakIterator( const rtl::OUString& aLocaleName );
128     com::sun::star::uno::Reference < XBreakIterator > SAL_CALL getLocaleSpecificBreakIterator( const com::sun::star::lang::Locale& rLocale );
129     const com::sun::star::lang::Locale& SAL_CALL getLocaleByScriptType(const com::sun::star::lang::Locale& rLocale, const rtl::OUString& Text,
130         sal_Int32 nStartPos, sal_Bool forward, sal_Bool skipWhiteSpace);
131 
132 };
133 
134 } // i18n
135 } // star
136 } // sun
137 } // com
138 
139 
140 #endif // _I18N_BREAKITERATOR_HXX_
141