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