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: tkpchars.hxx,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 ************************************************************************/
31 #ifndef ADC_TKPCHARS_HXX
32 #define ADC_TKPCHARS_HXX
47 1||||||||||||||||||||||a||||||||||||b|||c||||||||||||||||||||...
50 1 := first character of Sourcecode.
51 a := nLastTokenStart, there starts the last cut token.
52 b := nLastCut, there is a '\0'-char which marks the end of
53 the last cut token. The original character at b is stored
54 in cCharAtLastCut and will replace the '\0'-char, when the
56 c := The current cursor position.
61 @use This class can be used by any parser to get the chars of a
62 text one by one and separate them to tokens.
73 /** Loads the complete contents of in_rSource into the classes private memory.
74 If in_rSource is a file, it has to be open of course.
75 After loading the text, the CurChar() is set on the begin of the text.
78 csv::bstream
& io_rSource
);
80 void InsertTextAtCurPos(
81 const char * i_sText2Insert
);
83 /// @return CurChar() after moving forward one char.
86 The token which starts at the char which was CurChar(), when
87 CutToken() was called the last time - or at the beginning of the text.
88 The token ends by the CurChar() being replaced by a '\0'.
90 Value is valid until the next call of CutToken() or ~CharacterSource().
92 const char * CutToken();
96 /// @return The result of the last CutToken(). Or NULL, if there was none yet.
97 const char * CurToken() const;
101 bool IsFinished() const;
111 intt nLastTokenStart
;
119 intt nLastTokenStart
,
120 char cCharAtLastCut
);
125 char MoveOn_OverStack();
128 std::stack
< S_SourceState
>
136 intt nLastTokenStart
;
142 CharacterSource::MoveOn()
144 if (DEBUG_ShowText())
146 Cerr() << char(dpSource
[nCurPos
+1]) << Flush();
148 if ( nCurPos
< nSourceSize
-1 )
149 return dpSource
[++nCurPos
];
150 else if ( aSourcesStack
.size() > 0 )
151 return MoveOn_OverStack();
153 return dpSource
[nCurPos
= nSourceSize
];
156 CharacterSource::CurChar() const
157 { return nCurPos
!= nLastCut
? dpSource
[nCurPos
] : cCharAtLastCut
; }
159 CharacterSource::CurToken() const
160 { return &dpSource
[nLastTokenStart
]; }
162 CharacterSource::IsFinished() const
163 { return nCurPos
>= nSourceSize
; }
165 CharacterSource::CurPos() const