Update ooo320-m1
[ooovba.git] / autodoc / source / inc / tools / tkpchars.hxx
blob475d9a5a574f5c5563173c35761962397ce40199
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: tkpchars.hxx,v $
10 * $Revision: 1.4 $
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
34 // USED SERVICES
35 // BASE CLASSES
36 // COMPONENTS
37 // PARAMETRS
38 #include <adc_cl.hxx>
39 #include <stack>
43 /** @descr
45 dpSource:
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
55 next token is cut.
56 c := The current cursor position.
59 @needs cosv.lib
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.
63 **/
65 class CharacterSource
67 public:
68 // LIFECYCLE
69 CharacterSource();
70 ~CharacterSource();
72 // OPERATIONS
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.
76 **/
77 void LoadText(
78 csv::bstream & io_rSource);
80 void InsertTextAtCurPos(
81 const char * i_sText2Insert );
83 /// @return CurChar() after moving forward one char.
84 char MoveOn();
85 /** @return
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().
91 **/
92 const char * CutToken();
94 // INQUIRY
95 char CurChar() const;
96 /// @return The result of the last CutToken(). Or NULL, if there was none yet.
97 const char * CurToken() const;
99 // INQUIRY
100 /// @return true, if
101 bool IsFinished() const;
103 private:
104 struct S_SourceState
106 DYN char * dpSource;
107 intt nSourceSize;
109 intt nCurPos;
110 intt nLastCut;
111 intt nLastTokenStart;
112 char cCharAtLastCut;
114 S_SourceState(
115 DYN char * dpSource,
116 intt nSourceSize,
117 intt nCurPos,
118 intt nLastCut,
119 intt nLastTokenStart,
120 char cCharAtLastCut );
123 void BeginSource();
124 intt CurPos() const;
125 char MoveOn_OverStack();
127 // DATA
128 std::stack< S_SourceState >
129 aSourcesStack;
131 DYN char * dpSource;
132 intt nSourceSize;
134 intt nCurPos;
135 intt nLastCut;
136 intt nLastTokenStart;
137 char cCharAtLastCut;
141 inline char
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();
152 else
153 return dpSource[nCurPos = nSourceSize];
155 inline char
156 CharacterSource::CurChar() const
157 { return nCurPos != nLastCut ? dpSource[nCurPos] : cCharAtLastCut; }
158 inline const char *
159 CharacterSource::CurToken() const
160 { return &dpSource[nLastTokenStart]; }
161 inline bool
162 CharacterSource::IsFinished() const
163 { return nCurPos >= nSourceSize; }
164 inline intt
165 CharacterSource::CurPos() const
166 { return nCurPos; }
171 #endif