1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tkpstama.cxx,v $
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 #include <tokens/tkpstama.hxx>
34 // NOT FULLY DECLARED SERVICES
35 // #include <srcfind.hxx>
36 #include <tokens/stmstarr.hxx>
37 //#include <parseinc.hxx>
38 #include <tools/tkpchars.hxx>
41 const intt C_nStatuslistResizeValue
= 32;
42 const intt C_nTopStatus
= 0;
44 StateMachine::StateMachine( intt in_nStatusSize
,
45 intt in_nInitial_StatusListSize
)
46 : pStati(new StmStatus
*[in_nInitial_StatusListSize
]),
47 nCurrentStatus(C_nTopStatus
),
48 nPeekedStatus(C_nTopStatus
),
49 nStatusSize(in_nStatusSize
),
51 nStatiSpace(in_nInitial_StatusListSize
)
53 csv_assert(in_nStatusSize
> 0);
54 csv_assert(in_nInitial_StatusListSize
> 0);
56 memset(pStati
, 0, sizeof(StmStatus
*) * nStatiSpace
);
60 StateMachine::AddStatus(StmStatus
* let_dpStatus
)
62 if (nNrofStati
== nStatiSpace
)
66 pStati
[nNrofStati
] = let_dpStatus
;
71 StateMachine::AddToken( const char * in_sToken
,
72 TextToken::F_CRTOK in_fTokenCreateFunction
,
73 const INT16
* in_aBranches
,
74 INT16 in_nBoundsStatus
)
76 if (csv::no_str(in_sToken
))
79 // Durch existierende Stati durchhangeln:
83 for ( const char * pChar
= in_sToken
;
88 StmStatus
& rPst
= Status(nPeekedStatus
);
89 if ( rPst
.IsADefault() OR rPst
.AsBounds() != 0 )
91 nPeekedStatus
= AddStatus( new StmArrayStatus(nStatusSize
, in_aBranches
, 0, false ) );
92 CurrentStatus().SetBranch( *pChar
, nPeekedStatus
);
94 nCurrentStatus
= nPeekedStatus
;
96 StmArrayStatus
& rLastStatus
= CurrentStatus();
97 rLastStatus
.SetTokenCreateFunction(in_fTokenCreateFunction
);
98 for (intt i
= 0; i
< nStatusSize
; i
++)
100 if (Status(rLastStatus
.NextBy(i
)).AsBounds() != 0)
101 rLastStatus
.SetBranch(i
,in_nBoundsStatus
);
105 StateMachine::~StateMachine()
107 for (intt i
= 0; i
< nNrofStati
; i
++)
115 StateMachine::GetCharChain( TextToken::F_CRTOK
& o_nTokenCreateFunction
,
116 CharacterSource
& io_rText
)
118 nCurrentStatus
= C_nTopStatus
;
120 Peek(io_rText
.CurChar());
121 while (BoundsStatus() == 0)
123 nCurrentStatus
= nPeekedStatus
;
124 Peek(io_rText
.MoveOn());
126 o_nTokenCreateFunction
= CurrentStatus().TokenCreateFunction();
128 return *BoundsStatus();
132 StateMachine::ResizeStati()
134 intt nNewSize
= nStatiSpace
+ C_nStatuslistResizeValue
;
136 StatusList pNewStati
= new StmStatus
*[nNewSize
];
138 for ( ; i
< nNrofStati
; i
++)
140 pNewStati
[i
] = pStati
[i
];
144 (nNewSize
-i
) * sizeof(StmStatus
*) );
148 nStatiSpace
= nNewSize
;
152 StateMachine::Status(intt in_nStatusNr
) const
154 csv_assert( csv::in_range(intt(0), in_nStatusNr
, intt(nNrofStati
)) );
155 return *pStati
[in_nStatusNr
];
159 StateMachine::CurrentStatus() const
161 StmArrayStatus
* pCurSt
= Status(nCurrentStatus
).AsArray();
163 csv_assert(pCurSt
!= 0);
165 // csv_assert(false);
170 StateMachine::BoundsStatus() const
172 return Status(nPeekedStatus
).AsBounds();
176 StateMachine::Peek(intt in_nBranch
)
178 StmArrayStatus
& rSt
= CurrentStatus();
179 nPeekedStatus
= rSt
.NextBy(in_nBranch
);