1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef ADC_TKPCHARS_HXX
21 #define ADC_TKPCHARS_HXX
36 1||||||||||||||||||||||a||||||||||||b|||c||||||||||||||||||||...
39 1 := first character of Sourcecode.
40 a := nLastTokenStart, there starts the last cut token.
41 b := nLastCut, there is a '\0'-char which marks the end of
42 the last cut token. The original character at b is stored
43 in cCharAtLastCut and will replace the '\0'-char, when the
45 c := The current cursor position.
50 @use This class can be used by any parser to get the chars of a
51 text one by one and separate them to tokens.
62 /** Loads the complete contents of in_rSource into the classes private memory.
63 If in_rSource is a file, it has to be open of course.
64 After loading the text, the CurChar() is set on the begin of the text.
67 csv::bstream
& io_rSource
);
69 /// @return CurChar() after moving forward one char.
72 The token which starts at the char which was CurChar(), when
73 CutToken() was called the last time - or at the beginning of the text.
74 The token ends by the CurChar() being replaced by a '\0'.
76 Value is valid until the next call of CutToken() or ~CharacterSource().
78 const char * CutToken();
82 /// @return The result of the last CutToken(). Or NULL, if there was none yet.
83 const char * CurToken() const;
87 bool IsFinished() const;
104 CharacterSource::MoveOn()
106 if (DEBUG_ShowText())
108 Cerr() << char(dpSource
[nCurPos
+1]) << Flush();
110 if ( nCurPos
< nSourceSize
-1 )
111 return dpSource
[++nCurPos
];
113 return dpSource
[nCurPos
= nSourceSize
];
116 CharacterSource::CurChar() const
117 { return nCurPos
!= nLastCut
? dpSource
[nCurPos
] : cCharAtLastCut
; }
119 CharacterSource::CurToken() const
120 { return &dpSource
[nLastTokenStart
]; }
122 CharacterSource::IsFinished() const
123 { return nCurPos
>= nSourceSize
; }
125 CharacterSource::CurPos() const
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */