merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / parser_i / tokens / tkpstam2.cxx
blob297b06625a8bae3c7167a3ee23ae111113e910a7
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: tkpstam2.cxx,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 #include <precomp.h>
32 #include <tokens/tkpstam2.hxx>
34 // NOT FULLY DECLARED SERVICES
35 #include <tokens/stmstar2.hxx>
36 #include <tools/tkpchars.hxx>
39 const intt C_nStatuslistResizeValue = 32;
40 const intt C_nTopStatus = 0;
42 StateMachin2::StateMachin2( intt in_nStatusSize,
43 intt in_nInitial_StatusListSize )
44 : pStati(new StmStatu2*[in_nInitial_StatusListSize]),
45 nCurrentStatus(C_nTopStatus),
46 nPeekedStatus(C_nTopStatus),
47 nStatusSize(in_nStatusSize),
48 nNrofStati(0),
49 nStatiSpace(in_nInitial_StatusListSize)
51 csv_assert(in_nStatusSize > 0);
52 csv_assert(in_nInitial_StatusListSize > 0);
54 memset(pStati, 0, sizeof(StmStatu2*) * nStatiSpace);
57 intt
58 StateMachin2::AddStatus(StmStatu2 * let_dpStatus)
60 if (nNrofStati == nStatiSpace)
62 ResizeStati();
64 pStati[nNrofStati] = let_dpStatus;
65 return nNrofStati++;
68 void
69 StateMachin2::AddToken( const char * in_sToken,
70 UINT16 in_nTokenId,
71 const INT16 * in_aBranches,
72 INT16 in_nBoundsStatus )
74 if (csv::no_str(in_sToken))
75 return;
77 // Durch existierende Stati durchhangeln:
78 nCurrentStatus = 0;
79 nPeekedStatus = 0;
81 for ( const char * pChar = in_sToken;
82 *pChar != NULCH;
83 ++pChar )
85 Peek(*pChar);
86 StmStatu2 & rPst = Status(nPeekedStatus);
87 if ( rPst.IsADefault() OR rPst.AsBounds() != 0 )
89 nPeekedStatus = AddStatus( new StmArrayStatu2(nStatusSize, in_aBranches, 0, false ) );
90 CurrentStatus().SetBranch( *pChar, nPeekedStatus );
92 nCurrentStatus = nPeekedStatus;
93 } // end for
94 StmArrayStatu2 & rLastStatus = CurrentStatus();
95 rLastStatus.SetTokenId(in_nTokenId);
96 for (intt i = 0; i < nStatusSize; i++)
98 if (Status(rLastStatus.NextBy(i)).AsBounds() != 0)
99 rLastStatus.SetBranch(i,in_nBoundsStatus);
100 } // end for
103 StateMachin2::~StateMachin2()
105 for (intt i = 0; i < nNrofStati; i++)
107 delete pStati[i];
109 delete [] pStati;
112 StmBoundsStatu2 &
113 StateMachin2::GetCharChain( UINT16 & o_nTokenId,
114 CharacterSource & io_rText )
116 nCurrentStatus = C_nTopStatus;
117 Peek(io_rText.CurChar());
118 while (BoundsStatus() == 0)
120 nCurrentStatus = nPeekedStatus;
121 Peek(io_rText.MoveOn());
123 o_nTokenId = CurrentStatus().TokenId();
125 return *BoundsStatus();
128 void
129 StateMachin2::ResizeStati()
131 intt nNewSize = nStatiSpace + C_nStatuslistResizeValue;
132 intt i = 0;
133 StatusList pNewStati = new StmStatu2*[nNewSize];
135 for ( ; i < nNrofStati; i++)
137 pNewStati[i] = pStati[i];
139 memset( pNewStati+i,
141 (nNewSize-i) * sizeof(StmStatu2*) );
143 delete [] pStati;
144 pStati = pNewStati;
145 nStatiSpace = nNewSize;
148 StmStatu2 &
149 StateMachin2::Status(intt in_nStatusNr) const
151 csv_assert( csv::in_range(intt(0), in_nStatusNr, intt(nNrofStati)) );
152 return *pStati[in_nStatusNr];
155 StmArrayStatu2 &
156 StateMachin2::CurrentStatus() const
158 StmArrayStatu2 * pCurSt = Status(nCurrentStatus).AsArray();
159 if (pCurSt == 0)
161 csv_assert(false);
163 return *pCurSt;
166 StmBoundsStatu2 *
167 StateMachin2::BoundsStatus() const
169 return Status(nPeekedStatus).AsBounds();
172 void
173 StateMachin2::Peek(intt in_nBranch)
175 StmArrayStatu2 & rSt = CurrentStatus();
176 nPeekedStatus = rSt.NextBy(in_nBranch);