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