KiCad PCB EDA Suite
Loading...
Searching...
No Matches
filter_reader.cpp
Go to the documentation of this file.
1
2/*
3 * This program source code file is part of KiCad, a free EDA CAD application.
4 *
5 * Copyright (C) 2007-2010 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2007-2021 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <cstring>
27#include <filter_reader.h>
28#include <richio.h>
29
30
32 LINE_READER( 1 ),
33 reader( aReader )
34{
35 // Not using our own m_line buffer, will be using aReader's. This changes
36 // the meaning of this->m_line to be merely a pointer to aReader's m_line, which of course
37 // is not owned here.
38 delete [] m_line;
39
40 m_line = nullptr;
41}
42
43
45{
46 // Our 'm_line' points to aReader's, and he will delete that buffer.
47 // Prevent subsequent call to ~LINE_READER() from deleting a buffer we do not own.
48 m_line = nullptr;
49}
50
51
53{
54 char* s;
55
56 while( ( s = reader.ReadLine() ) != nullptr )
57 {
58 if( !strchr( "#\n\r", s[0] ) )
59 break;
60 }
61
62 m_line = reader.Line();
64
65 return m_length ? m_line : nullptr;
66}
67
68
70 LINE_READER( 1 ),
71 reader( aReader )
72{
73 // Not using our own m_line buffer, will be using aReader's. This changes
74 // the meaning of this->m_line to be merely a pointer to aReader's m_line, which of course
75 // is not owned here.
76 delete [] m_line;
77
78 m_line = nullptr;
79}
80
81
83{
84 // Our 'm_line' points to aReader's, and he will delete that buffer.
85 // Prevent subsequent call to ~LINE_READER() from deleting a buffer we do not own.
86 m_line = nullptr;
87}
88
89
91{
92 char* s;
93
94 while( ( s = reader.ReadLine() ) != nullptr )
95 {
96 while( s != nullptr && strchr( " \t", *s ) )
97 s++;
98
99 if( s != nullptr && !strchr( "#\n\r", *s ) )
100 break;
101 }
102
103 m_line = s;
105
106 return m_length ? m_line : nullptr;
107}
LINE_READER & reader
Definition: filter_reader.h:59
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
FILTER_READER(LINE_READER &aReader)
Does not take ownership over aReader so will not destroy it.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
unsigned m_length
no. bytes in line before trailing nul.
Definition: richio.h:167
char * m_line
the read line of UTF8 text
Definition: richio.h:170
unsigned Length() const
Return the number of bytes in the last line read from this LINE_READER.
Definition: richio.h:155
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:129
WHITESPACE_FILTER_READER(LINE_READER &aReader)
Doe not take ownership over aReader, so will not destroy it.
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.