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 The 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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <cstring>
23#include <filter_reader.h>
24#include <richio.h>
25
26
28 LINE_READER( 1 ),
29 reader( aReader )
30{
31 // Not using our own m_line buffer, will be using aReader's. This changes
32 // the meaning of this->m_line to be merely a pointer to aReader's m_line, which of course
33 // is not owned here.
34 delete [] m_line;
35
36 m_line = nullptr;
37}
38
39
41{
42 // Our 'm_line' points to aReader's, and he will delete that buffer.
43 // Prevent subsequent call to ~LINE_READER() from deleting a buffer we do not own.
44 m_line = nullptr;
45}
46
47
49{
50 char* s;
51
52 while( ( s = reader.ReadLine() ) != nullptr )
53 {
54 if( !strchr( "#\n\r", s[0] ) )
55 break;
56 }
57
58 m_line = reader.Line();
59 m_length = reader.Length();
60
61 return m_length ? m_line : nullptr;
62}
63
64
66 LINE_READER( 1 ),
67 reader( aReader )
68{
69 // Not using our own m_line buffer, will be using aReader's. This changes
70 // the meaning of this->m_line to be merely a pointer to aReader's m_line, which of course
71 // is not owned here.
72 delete [] m_line;
73
74 m_line = nullptr;
75}
76
77
79{
80 // Our 'm_line' points to aReader's, and he will delete that buffer.
81 // Prevent subsequent call to ~LINE_READER() from deleting a buffer we do not own.
82 m_line = nullptr;
83}
84
85
87{
88 char* s;
89
90 while( ( s = reader.ReadLine() ) != nullptr )
91 {
92 while( s != nullptr && strchr( " \t", *s ) )
93 s++;
94
95 if( s != nullptr && !strchr( "#\n\r", *s ) )
96 break;
97 }
98
99 m_line = s;
100 m_length = reader.Length();
101
102 return m_length ? m_line : nullptr;
103}
LINE_READER & reader
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.
LINE_READER(unsigned aMaxLineLength=LINE_READER_LINE_DEFAULT_MAX)
Build a line reader and fixes the length of the maximum supported line length to aMaxLineLength.
Definition richio.cpp:100
unsigned m_length
no. bytes in line before trailing nul.
Definition richio.h:136
char * m_line
the read line of UTF8 text
Definition richio.h:139
WHITESPACE_FILTER_READER(LINE_READER &aReader)
Do 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.