Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef ADC_TKPCHARS_HXX
21 : #define ADC_TKPCHARS_HXX
22 :
23 : // USED SERVICES
24 : // BASE CLASSES
25 : // COMPONENTS
26 : // PARAMETRS
27 : #include <adc_cl.hxx>
28 : #include <stack>
29 :
30 :
31 :
32 : /** @descr
33 :
34 : dpSource:
35 :
36 : 1||||||||||||||||||||||a||||||||||||b|||c||||||||||||||||||||...
37 :
38 :
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
44 : next token is cut.
45 : c := The current cursor position.
46 :
47 :
48 : @needs cosv.lib
49 :
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.
52 : **/
53 :
54 : class CharacterSource
55 : {
56 : public:
57 : // LIFECYCLE
58 : CharacterSource();
59 : ~CharacterSource();
60 :
61 : // OPERATIONS
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.
65 : **/
66 : void LoadText(
67 : csv::bstream & io_rSource);
68 :
69 : /// @return CurChar() after moving forward one char.
70 : char MoveOn();
71 : /** @return
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'.
75 :
76 : Value is valid until the next call of CutToken() or ~CharacterSource().
77 : **/
78 : const char * CutToken();
79 :
80 : // INQUIRY
81 : char CurChar() const;
82 : /// @return The result of the last CutToken(). Or NULL, if there was none yet.
83 : const char * CurToken() const;
84 :
85 : // INQUIRY
86 : /// @return true, if
87 : bool IsFinished() const;
88 :
89 : private:
90 : void BeginSource();
91 : intt CurPos() const;
92 :
93 : DYN char * dpSource;
94 : intt nSourceSize;
95 :
96 : intt nCurPos;
97 : intt nLastCut;
98 : intt nLastTokenStart;
99 : char cCharAtLastCut;
100 : };
101 :
102 :
103 : inline char
104 11430960 : CharacterSource::MoveOn()
105 : {
106 11430960 : if (DEBUG_ShowText())
107 : {
108 0 : Cerr() << char(dpSource[nCurPos+1]) << Flush();
109 : }
110 11430960 : if ( nCurPos < nSourceSize-1 )
111 11426825 : return dpSource[++nCurPos];
112 : else
113 4135 : return dpSource[nCurPos = nSourceSize];
114 : }
115 : inline char
116 2340156 : CharacterSource::CurChar() const
117 2340156 : { return nCurPos != nLastCut ? dpSource[nCurPos] : cCharAtLastCut; }
118 : inline const char *
119 0 : CharacterSource::CurToken() const
120 0 : { return &dpSource[nLastTokenStart]; }
121 : inline bool
122 2566254 : CharacterSource::IsFinished() const
123 2566254 : { return nCurPos >= nSourceSize; }
124 : inline intt
125 1915863 : CharacterSource::CurPos() const
126 1915863 : { return nCurPos; }
127 :
128 :
129 :
130 :
131 : #endif
132 :
133 :
134 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|