xref: /trunk/main/i18npool/inc/xdictionary.hxx (revision a893be29)
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 _XDICTIONARY_H_
24 #define _XDICTIONARY_H_
25 
26 #include <sal/types.h>
27 #include <osl/module.h>
28 
29 #include <com/sun/star/i18n/Boundary.hpp>
30 
31 namespace com { namespace sun { namespace star { namespace i18n {
32 
33 // Whether to use cell boundary code, currently unused but prepared.
34 #define USE_CELL_BOUNDARY_CODE 0
35 
36 #define CACHE_MAX 32		// max cache structure number
37 #define DEFAULT_SIZE 256	// for boundary size, to avoid alloc and release memory
38 
39 // cache structure.
40 struct WordBreakCache {
41 	sal_Int32 length;		// contents length saved here.
42 	sal_Unicode *contents;		// separated segment contents.
43 	sal_Int32* wordboundary;     	// word boundaries in segments.
44 	sal_Int32 size;			// size of wordboundary
45 
46     WordBreakCache();
47     sal_Bool equals(const sal_Unicode *str, Boundary& boundary);    // checking cached string
48 };
49 
50 class xdictionary
51 {
52 private:
53 	const sal_uInt8  * existMark;
54 	const sal_Int16  * index1;
55 	const sal_Int32 * index2;
56 	const sal_Int32 * lenArray;
57 	const sal_Unicode* dataArea;
58 	oslModule hModule;
59 	Boundary boundary;
60     sal_Bool japaneseWordBreak;
61 
62 #if USE_CELL_BOUNDARY_CODE
63     // For CTL breakiterator, where the word boundary should not be inside cell.
64 	sal_Bool useCellBoundary;
65 	sal_Int32* cellBoundary;
66 #endif
67 
68 public:
69 	xdictionary(const sal_Char *lang);
70 	~xdictionary();
71 	Boundary nextWord( const rtl::OUString& rText, sal_Int32 nPos, sal_Int16 wordType);
72 	Boundary previousWord( const rtl::OUString& rText, sal_Int32 nPos, sal_Int16 wordType);
73 	Boundary getWordBoundary( const rtl::OUString& rText, sal_Int32 nPos, sal_Int16 wordType, sal_Bool bDirection );
74     void setJapaneseWordBreak();
75 
76 #if USE_CELL_BOUNDARY_CODE
77     void setCellBoundary(sal_Int32* cellArray);
78 #endif
79 
80 private:
81 	WordBreakCache cache[CACHE_MAX];
82 
83 	sal_Bool        seekSegment(const rtl::OUString& rText, sal_Int32 pos, Boundary& boundary);
84 	WordBreakCache& getCache(const sal_Unicode *text, Boundary& boundary);
85 	sal_Bool        exists(const sal_uInt32 u);
86 	sal_Int32       getLongestMatch(const sal_Unicode *text, sal_Int32 len);
87 };
88 
89 } } } }
90 
91 #endif
92 
93