Version 3.4.2.3, tag libreoffice-3.4.2.3 (3.4.2-rc3)
[LibreOffice.git] / l10ntools / inc / wtratree.hxx
blobc06be49b183cd326b96cabdb58995df2aa011cf6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #ifndef TX3_WTRATREE_HXX
31 #define TX3_WTRATREE_HXX
33 // USED
34 // Base Classes
35 // Components
36 // Parameters
37 #include <tools/string.hxx>
39 const INT16 C_NR_OF_WTT_RESULTS = 5;
40 const INT16 C_NR_OF_POSSIBLE_CHARS = 256;
43 typedef unsigned char u_char;
44 typedef const char * constr;
47 class WTT_Node;
50 /** @task
51 This class implements the functionality, that class WordTransformer
52 offers.
53 WordTransformer is dependant of this class, but NOT the other way!
54 **/
55 class WordTransTree
57 public:
58 enum E_Result
60 OK = 0,
61 HOTKEY_LOST,
62 OUTPUT_OVERFLOW
66 // LIFECYCLE
67 WordTransTree(
68 CharSet i_nWorkingCharSet = RTL_TEXTENCODING_MS_1252);
69 void SetCharSet(
70 CharSet i_nWorkingCharSet);
71 ~WordTransTree();
73 void AddWordPair(
74 const ByteString & i_sOldString,
75 const ByteString & i_sReplaceString );
77 // OPERATIONS
78 void InitTransformation(
79 const char * i_sInput, /// [!=0], a range of i_nInputLength must be valid memory for read.
80 UINT32 i_nInputLength,
81 UINT32 i_nOutputMaxLength = STRING_MAXLEN - 12 );
82 E_Result TransformNextToken();
84 // INQUIRY
85 sal_Bool TextEndReached() const;
86 const char * Output() const;
88 // These 3 functions are valid between two calls of
89 // TransformNextToken():
90 E_Result CurResult() const;
91 ByteString CurReplacedString() const;
92 ByteString CurReplacingString() const;
93 char CurHotkey() const;
95 private:
96 // SERVICE FUNCTONS
97 UINT8 CalculateBranch(
98 u_char i_cInputChar ) const;
100 void Handle_Hotkey();
101 void Handle_TokenToKeep();
102 void Handle_TokenToTransform();
104 // DATA
105 // Fixed data
106 const u_char * sInput;
107 UINT32 nInputLength;
108 const u_char * pInputEnd;
110 u_char * sOutput; // DYN
111 UINT32 nOutputMaxLength;
113 WTT_Node * dpParsingTreeTop; // DYN
114 WTT_Node * pUnknownAlpha;
115 u_char cChar2Branch[C_NR_OF_POSSIBLE_CHARS];
116 u_char c_AE, c_OE, c_UE, c_ae, c_oe, c_ue;
118 // Working data
119 const u_char * pInputCurTokenStart;
120 const u_char * pInputPosition;
121 u_char * pOutputPosition;
122 WTT_Node * pCurParseNode;
124 // Data which are valid only after a completed call to TransformNextToken()
125 E_Result eCurResult;
126 u_char cCurHotkey; // Letter wich is used as hotkey
127 u_char cCurHotkeySign; // Letter which is used to assign hotkey ('~'or '&') .
136 inline sal_Bool
137 WordTransTree::TextEndReached() const
138 { return pInputPosition == pInputEnd; }
139 inline const char *
140 WordTransTree::Output() const
141 { return TextEndReached() ? (constr) sOutput : ""; }
142 inline WordTransTree::E_Result
143 WordTransTree::CurResult() const
144 { return eCurResult; }
145 inline ByteString
146 WordTransTree::CurReplacedString() const
147 { return ByteString((constr) pInputCurTokenStart,pInputPosition-pInputCurTokenStart); }
148 inline char
149 WordTransTree::CurHotkey() const
150 { return cCurHotkey; }
151 inline UINT8
152 WordTransTree::CalculateBranch(u_char i_cInputChar) const
153 { return cChar2Branch[i_cInputChar]; }
157 #endif
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */