Update ooo320-m1
[ooovba.git] / transex3 / inc / wtratree.hxx
blobbacabeb161961f4a7f756a9480aef289278a6b1a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: wtratree.hxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #ifndef TX3_WTRATREE_HXX
33 #define TX3_WTRATREE_HXX
35 // USED
36 // Base Classes
37 // Components
38 // Parameters
39 #include <tools/string.hxx>
41 const INT16 C_NR_OF_WTT_RESULTS = 5;
42 const INT16 C_NR_OF_POSSIBLE_CHARS = 256;
45 typedef unsigned char u_char;
46 typedef const char * constr;
49 class WTT_Node;
52 /** @task
53 This class implements the functionality, that class WordTransformer
54 offers.
55 WordTransformer is dependant of this class, but NOT the other way!
56 **/
57 class WordTransTree
59 public:
60 enum E_Result
62 OK = 0,
63 HOTKEY_LOST,
64 OUTPUT_OVERFLOW
68 // LIFECYCLE
69 WordTransTree(
70 CharSet i_nWorkingCharSet = RTL_TEXTENCODING_MS_1252);
71 void SetCharSet(
72 CharSet i_nWorkingCharSet);
73 ~WordTransTree();
75 void AddWordPair(
76 const ByteString & i_sOldString,
77 const ByteString & i_sReplaceString );
79 // OPERATIONS
80 void InitTransformation(
81 const char * i_sInput, /// [!=0], a range of i_nInputLength must be valid memory for read.
82 UINT32 i_nInputLength,
83 UINT32 i_nOutputMaxLength = STRING_MAXLEN - 12 );
84 E_Result TransformNextToken();
86 // INQUIRY
87 BOOL TextEndReached() const;
88 const char * Output() const;
90 // These 3 functions are valid between two calls of
91 // TransformNextToken():
92 E_Result CurResult() const;
93 ByteString CurReplacedString() const;
94 ByteString CurReplacingString() const;
95 char CurHotkey() const;
97 private:
98 // SERVICE FUNCTONS
99 UINT8 CalculateBranch(
100 u_char i_cInputChar ) const;
102 void Handle_Hotkey();
103 void Handle_TokenToKeep();
104 void Handle_TokenToTransform();
106 // DATA
107 // Fixed data
108 const u_char * sInput;
109 UINT32 nInputLength;
110 const u_char * pInputEnd;
112 u_char * sOutput; // DYN
113 UINT32 nOutputMaxLength;
115 WTT_Node * dpParsingTreeTop; // DYN
116 WTT_Node * pUnknownAlpha;
117 u_char cChar2Branch[C_NR_OF_POSSIBLE_CHARS];
118 u_char c_AE, c_OE, c_UE, c_ae, c_oe, c_ue;
120 // Working data
121 const u_char * pInputCurTokenStart;
122 const u_char * pInputPosition;
123 u_char * pOutputPosition;
124 WTT_Node * pCurParseNode;
126 // Data which are valid only after a completed call to TransformNextToken()
127 E_Result eCurResult;
128 u_char cCurHotkey; // Letter wich is used as hotkey
129 u_char cCurHotkeySign; // Letter which is used to assign hotkey ('~'or '&') .
138 inline BOOL
139 WordTransTree::TextEndReached() const
140 { return pInputPosition == pInputEnd; }
141 inline const char *
142 WordTransTree::Output() const
143 { return TextEndReached() ? (constr) sOutput : ""; }
144 inline WordTransTree::E_Result
145 WordTransTree::CurResult() const
146 { return eCurResult; }
147 inline ByteString
148 WordTransTree::CurReplacedString() const
149 { return ByteString((constr) pInputCurTokenStart,pInputPosition-pInputCurTokenStart); }
150 inline char
151 WordTransTree::CurHotkey() const
152 { return cCurHotkey; }
153 inline UINT8
154 WordTransTree::CalculateBranch(u_char i_cInputChar) const
155 { return cChar2Branch[i_cInputChar]; }
159 #endif