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: tkpstam2.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/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
),
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
);
58 StateMachin2::AddStatus(StmStatu2
* let_dpStatus
)
60 if (nNrofStati
== nStatiSpace
)
64 pStati
[nNrofStati
] = let_dpStatus
;
69 StateMachin2::AddToken( const char * in_sToken
,
71 const INT16
* in_aBranches
,
72 INT16 in_nBoundsStatus
)
74 if (csv::no_str(in_sToken
))
77 // Durch existierende Stati durchhangeln:
81 for ( const char * pChar
= in_sToken
;
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
;
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
);
103 StateMachin2::~StateMachin2()
105 for (intt i
= 0; i
< nNrofStati
; i
++)
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();
129 StateMachin2::ResizeStati()
131 intt nNewSize
= nStatiSpace
+ C_nStatuslistResizeValue
;
133 StatusList pNewStati
= new StmStatu2
*[nNewSize
];
135 for ( ; i
< nNrofStati
; i
++)
137 pNewStati
[i
] = pStati
[i
];
141 (nNewSize
-i
) * sizeof(StmStatu2
*) );
145 nStatiSpace
= nNewSize
;
149 StateMachin2::Status(intt in_nStatusNr
) const
151 csv_assert( csv::in_range(intt(0), in_nStatusNr
, intt(nNrofStati
)) );
152 return *pStati
[in_nStatusNr
];
156 StateMachin2::CurrentStatus() const
158 StmArrayStatu2
* pCurSt
= Status(nCurrentStatus
).AsArray();
167 StateMachin2::BoundsStatus() const
169 return Status(nPeekedStatus
).AsBounds();
173 StateMachin2::Peek(intt in_nBranch
)
175 StmArrayStatu2
& rSt
= CurrentStatus();
176 nPeekedStatus
= rSt
.NextBy(in_nBranch
);