xref: /trunk/main/l10ntools/inc/wtratree.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1983d4c8aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3983d4c8aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4983d4c8aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5983d4c8aSAndrew Rist  * distributed with this work for additional information
6983d4c8aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7983d4c8aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8983d4c8aSAndrew Rist  * "License"); you may not use this file except in compliance
9983d4c8aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11983d4c8aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13983d4c8aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14983d4c8aSAndrew Rist  * software distributed under the License is distributed on an
15983d4c8aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16983d4c8aSAndrew Rist  * KIND, either express or implied.  See the License for the
17983d4c8aSAndrew Rist  * specific language governing permissions and limitations
18983d4c8aSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20983d4c8aSAndrew Rist  *************************************************************/
21983d4c8aSAndrew Rist 
22983d4c8aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #ifndef TX3_WTRATREE_HXX
26cdf0e10cSrcweir #define TX3_WTRATREE_HXX
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // USED
29cdf0e10cSrcweir     // Base Classes
30cdf0e10cSrcweir     // Components
31cdf0e10cSrcweir     // Parameters
32cdf0e10cSrcweir #include <tools/string.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir const INT16     C_NR_OF_WTT_RESULTS = 5;
35cdf0e10cSrcweir const INT16     C_NR_OF_POSSIBLE_CHARS = 256;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
38cdf0e10cSrcweir typedef unsigned char u_char;
39cdf0e10cSrcweir typedef const char * constr;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir class WTT_Node;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir /** @task
46cdf0e10cSrcweir     This class implements the functionality, that class WordTransformer
47cdf0e10cSrcweir     offers.
48a893be29SPedro Giffuni     WordTransformer is dependent of this class, but NOT the other way!
49cdf0e10cSrcweir **/
50cdf0e10cSrcweir class WordTransTree
51cdf0e10cSrcweir {
52cdf0e10cSrcweir   public:
53cdf0e10cSrcweir     enum E_Result
54cdf0e10cSrcweir     {
55cdf0e10cSrcweir         OK = 0,
56cdf0e10cSrcweir         HOTKEY_LOST,
57cdf0e10cSrcweir         OUTPUT_OVERFLOW
58cdf0e10cSrcweir     };
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     //  LIFECYCLE
62cdf0e10cSrcweir                         WordTransTree(
63cdf0e10cSrcweir                             CharSet             i_nWorkingCharSet = RTL_TEXTENCODING_MS_1252);
64cdf0e10cSrcweir     void                SetCharSet(
65cdf0e10cSrcweir                             CharSet             i_nWorkingCharSet);
66cdf0e10cSrcweir                         ~WordTransTree();
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     void                AddWordPair(
69cdf0e10cSrcweir                             const ByteString &      i_sOldString,
70cdf0e10cSrcweir                             const ByteString &      i_sReplaceString );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     // OPERATIONS
73cdf0e10cSrcweir     void                InitTransformation(
74cdf0e10cSrcweir                             const char *        i_sInput,               /// [!=0], a range of i_nInputLength must be valid memory for read.
75cdf0e10cSrcweir                             UINT32              i_nInputLength,
76cdf0e10cSrcweir                             UINT32              i_nOutputMaxLength = STRING_MAXLEN - 12 );
77cdf0e10cSrcweir     E_Result            TransformNextToken();
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     // INQUIRY
80cdf0e10cSrcweir     sal_Bool                TextEndReached() const;
81cdf0e10cSrcweir     const char *        Output() const;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         // These 3 functions are valid between two calls of
84cdf0e10cSrcweir         //   TransformNextToken():
85cdf0e10cSrcweir     E_Result            CurResult() const;
86cdf0e10cSrcweir     ByteString          CurReplacedString() const;
87cdf0e10cSrcweir     ByteString          CurReplacingString() const;
88cdf0e10cSrcweir     char                CurHotkey() const;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir   private:
91*67f7bfb1SJohn Bampton     // SERVICE FUNCTIONS
92cdf0e10cSrcweir     UINT8               CalculateBranch(
93cdf0e10cSrcweir                             u_char              i_cInputChar ) const;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     void                Handle_Hotkey();
96cdf0e10cSrcweir     void                Handle_TokenToKeep();
97cdf0e10cSrcweir     void                Handle_TokenToTransform();
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     // DATA
100cdf0e10cSrcweir         // Fixed data
101cdf0e10cSrcweir     const u_char *      sInput;
102cdf0e10cSrcweir     UINT32              nInputLength;
103cdf0e10cSrcweir     const u_char *      pInputEnd;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     u_char *            sOutput;                // DYN
106cdf0e10cSrcweir     UINT32              nOutputMaxLength;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     WTT_Node *          dpParsingTreeTop;       // DYN
109cdf0e10cSrcweir     WTT_Node *          pUnknownAlpha;
110cdf0e10cSrcweir     u_char              cChar2Branch[C_NR_OF_POSSIBLE_CHARS];
111cdf0e10cSrcweir     u_char              c_AE, c_OE, c_UE, c_ae, c_oe, c_ue;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         // Working data
114cdf0e10cSrcweir     const u_char *      pInputCurTokenStart;
115cdf0e10cSrcweir     const u_char *      pInputPosition;
116cdf0e10cSrcweir     u_char *            pOutputPosition;
117cdf0e10cSrcweir     WTT_Node *          pCurParseNode;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         // Data which are valid only after a completed call to TransformNextToken()
120cdf0e10cSrcweir     E_Result            eCurResult;
121a893be29SPedro Giffuni     u_char              cCurHotkey;             // Letter which is used as hotkey
122cdf0e10cSrcweir     u_char              cCurHotkeySign;         // Letter which is used to assign hotkey ('~'or '&') .
123cdf0e10cSrcweir };
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 
131cdf0e10cSrcweir inline sal_Bool
TextEndReached() const132cdf0e10cSrcweir WordTransTree::TextEndReached() const
133cdf0e10cSrcweir     { return pInputPosition == pInputEnd; }
134cdf0e10cSrcweir inline const char *
Output() const135cdf0e10cSrcweir WordTransTree::Output() const
136cdf0e10cSrcweir     { return TextEndReached() ? (constr) sOutput : ""; }
137cdf0e10cSrcweir inline WordTransTree::E_Result
CurResult() const138cdf0e10cSrcweir WordTransTree::CurResult() const
139cdf0e10cSrcweir     { return eCurResult; }
140cdf0e10cSrcweir inline ByteString
CurReplacedString() const141cdf0e10cSrcweir WordTransTree::CurReplacedString() const
142cdf0e10cSrcweir     { return ByteString((constr) pInputCurTokenStart,pInputPosition-pInputCurTokenStart); }
143cdf0e10cSrcweir inline char
CurHotkey() const144cdf0e10cSrcweir WordTransTree::CurHotkey() const
145cdf0e10cSrcweir     { return cCurHotkey; }
146cdf0e10cSrcweir inline UINT8
CalculateBranch(u_char i_cInputChar) const147cdf0e10cSrcweir WordTransTree::CalculateBranch(u_char i_cInputChar) const
148cdf0e10cSrcweir     { return cChar2Branch[i_cInputChar]; }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 
152cdf0e10cSrcweir #endif
153