kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #06053
Re: Using FILE_LINE_READER in pcbnew
-
To:
kicad-developers@xxxxxxxxxxxxxxxxxxx
-
From:
Dick Hollenbeck <dick@xxxxxxxxxxx>
-
Date:
Thu, 13 Jan 2011 01:22:18 -0600
-
In-reply-to:
<AANLkTinhQyjZUecMmw+Kc91HzksSa4thjAg=dSXoThy2@mail.gmail.com>
-
User-agent:
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7
Marco Mattila,
You get the highest praise I can offer, and that is that I could not have
written it any better myself.
Truly outstanding.
+ while( aReader->ReadLine() )
{
+ Line = aReader->Line();
I see you even caught the fact that if there is an absurdly long line, >
5000, that the Line pointer can change as the LINE_READER reallocates and
moves the internal buffer. I see that you only pay for the minor overhead
of traveling through the virtual functions once per line.
Everything is just plain excellently done.
> I guess that the strtok was there to take care of situations where a
> file saved in windows is opened in linux (?). Opening a board having
> \r\n line endings seems to work using FILE_LINE_READER. A file using
> \r's only would not work.
I think fgets() will hide the platform specific ugliness well enough. No
sleep lost here.
The requirement for XML parsers would make a good requirement for how
fgets() should work:
http://www.w3.org/TR/REC-xml/#sec-line-ends
Quoted here:
To simplify the tasks of applications
<http://www.w3.org/TR/REC-xml/#dt-app>, the XML processor
<http://www.w3.org/TR/REC-xml/#dt-xml-proc> /MUST/ behave as if it
normalized all line breaks in external parsed entities (including the
document entity) on input, before parsing, by translating both the
two-character sequence #xD #xA and any #xD that is not followed by #xA to a
single #xA character.
fgets() may not do this on all our 'supported' platforms. If what comes in
are lines of text, and \r and \n are whitespace, same as \t and ' ', then
reasonably written line using code should be fine.
(Supported platforms is an oxymoron when you think about it. Isn't a
platform supposed to support us?) If we find one that does not, or we get
grief, then we can re-implement FILE_LINE_READER::ReadLine(), whose API can
be protected contractually, because it is worth protecting. At that point a
looping fgetc() call comes to mind, under the hood of ReadLine().
Thanks for your work. I literally could not have done it better myself.
Dick
References