xref: /aoo41x/main/l10ntools/inc/wtratree.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 
29 #ifndef TX3_WTRATREE_HXX
30 #define TX3_WTRATREE_HXX
31 
32 // USED
33 	// Base Classes
34 	// Components
35 	// Parameters
36 #include <tools/string.hxx>
37 
38 const INT16		C_NR_OF_WTT_RESULTS = 5;
39 const INT16    	C_NR_OF_POSSIBLE_CHARS = 256;
40 
41 
42 typedef unsigned char u_char;
43 typedef const char * constr;
44 
45 
46 class WTT_Node;
47 
48 
49 /**	@task
50 	This class implements the functionality, that class WordTransformer
51 	offers.
52 	WordTransformer is dependant of this class, but NOT the other way!
53 **/
54 class WordTransTree
55 {
56   public:
57 	enum E_Result
58 	{
59 		OK = 0,
60 		HOTKEY_LOST,
61 		OUTPUT_OVERFLOW
62 	};
63 
64 
65 	//	LIFECYCLE
66 						WordTransTree(
67 							CharSet				i_nWorkingCharSet = RTL_TEXTENCODING_MS_1252);
68 	void				SetCharSet(
69 							CharSet				i_nWorkingCharSet);
70 						~WordTransTree();
71 
72 	void				AddWordPair(
73 							const ByteString &		i_sOldString,
74 							const ByteString &		i_sReplaceString );
75 
76 	// OPERATIONS
77 	void				InitTransformation(
78 							const char *		i_sInput,               /// [!=0], a range of i_nInputLength must be valid memory for read.
79 							UINT32				i_nInputLength,
80 							UINT32				i_nOutputMaxLength = STRING_MAXLEN - 12 );
81 	E_Result			TransformNextToken();
82 
83 	// INQUIRY
84 	sal_Bool				TextEndReached() const;
85 	const char *		Output() const;
86 
87 		// These 3 functions are valid between two calls of
88 		//   TransformNextToken():
89 	E_Result			CurResult() const;
90 	ByteString 			CurReplacedString() const;
91 	ByteString	 		CurReplacingString() const;
92 	char 				CurHotkey() const;
93 
94   private:
95 	// SERVICE FUNCTONS
96 	UINT8	  			CalculateBranch(
97 							u_char 				i_cInputChar ) const;
98 
99 	void				Handle_Hotkey();
100 	void				Handle_TokenToKeep();
101 	void				Handle_TokenToTransform();
102 
103 	// DATA
104 		// Fixed data
105 	const u_char *		sInput;
106 	UINT32              nInputLength;
107 	const u_char *		pInputEnd;
108 
109 	u_char *			sOutput;				// DYN
110 	UINT32				nOutputMaxLength;
111 
112 	WTT_Node *			dpParsingTreeTop;		// DYN
113 	WTT_Node *			pUnknownAlpha;
114 	u_char		 		cChar2Branch[C_NR_OF_POSSIBLE_CHARS];
115 	u_char		 		c_AE, c_OE, c_UE, c_ae, c_oe, c_ue;
116 
117 		// Working data
118 	const u_char *		pInputCurTokenStart;
119 	const u_char *		pInputPosition;
120 	u_char *			pOutputPosition;
121 	WTT_Node *			pCurParseNode;
122 
123 		// Data which are valid only after a completed call to TransformNextToken()
124 	E_Result			eCurResult;
125 	u_char				cCurHotkey;            	// Letter wich is used as hotkey
126 	u_char				cCurHotkeySign;       	// Letter which is used to assign hotkey ('~'or '&') .
127 };
128 
129 
130 
131 
132 
133 
134 
135 inline sal_Bool
136 WordTransTree::TextEndReached() const
137 	{ return pInputPosition == pInputEnd; }
138 inline const char *
139 WordTransTree::Output() const
140 	{ return TextEndReached() ? (constr) sOutput : ""; }
141 inline WordTransTree::E_Result
142 WordTransTree::CurResult() const
143 	{ return eCurResult; }
144 inline ByteString
145 WordTransTree::CurReplacedString() const
146 	{ return ByteString((constr) pInputCurTokenStart,pInputPosition-pInputCurTokenStart); }
147 inline char
148 WordTransTree::CurHotkey() const
149 	{ return cCurHotkey; }
150 inline UINT8
151 WordTransTree::CalculateBranch(u_char i_cInputChar) const
152 	{ return cChar2Branch[i_cInputChar]; }
153 
154 
155 
156 #endif
157 
158 
159 
160