KiCad PCB EDA Suite
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 <dick@softplc.com>
6  * Copyright (C) 2007 KiCad Developers, see change_log.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 <string.h>
27 #include <richio.h>
28 #include <filter_reader.h>
29 
30 
32  LINE_READER( 1 ),
33  reader( aReader )
34 {
35  // Not using our own line buffer, will be using aReader's. This changes
36  // the meaning of this->line to be merely a pointer to aReader's line, which of course
37  // is not owned here.
38  delete [] line;
39 
40  line = 0;
41 }
42 
43 
45 {
46  // Our '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  line = 0;
49 }
50 
51 
53 {
54  char* s;
55 
56  while( ( s = reader.ReadLine() ) != NULL )
57  {
58  if( !strchr( "#\n\r", s[0] ) )
59  break;
60  }
61 
62  line = reader.Line();
63  length = reader.Length();
64 
65  return length ? line : NULL;
66 }
67 
68 
70  LINE_READER( 1 ),
71  reader( aReader )
72 {
73  // Not using our own line buffer, will be using aReader's. This changes
74  // the meaning of this->line to be merely a pointer to aReader's line, which of course
75  // is not owned here.
76  delete [] line;
77 
78  line = 0;
79 }
80 
81 
83 {
84  // Our '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  line = 0;
87 }
88 
89 
91 {
92  char* s;
93 
94  while( ( s = reader.ReadLine() ) != NULL )
95  {
96  while( s != NULL && strchr( " \t", *s ) )
97  s++;
98 
99  if( s != NULL && !strchr( "#\n\r", *s ) )
100  break;
101  }
102 
103  line = s;
104  length = reader.Length();
105 
106  return length ? line : NULL;
107 }
LINE_READER & reader
Definition: filter_reader.h:39
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
char * line
the read line of UTF8 text
Definition: richio.h:87
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
WHITESPACE_FILTER_READER(LINE_READER &aReader)
Constructor ( LINE_READER& ) does not take ownership over aReader, so will not destroy it...
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
unsigned length
no. bytes in line before trailing nul.
Definition: richio.h:84
unsigned Length() const
Function Length returns the number of bytes in the last line read from this LINE_READER.
Definition: richio.h:168
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter...
FILTER_READER(LINE_READER &aReader)
Constructor ( LINE_READER& ) does not take ownership over aReader, so will not destroy it...