[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Gm2] TextIO.ReadRestLine includes EOL char in string result
From: |
Breeden, Thomas (tmb) |
Subject: |
RE: [Gm2] TextIO.ReadRestLine includes EOL char in string result |
Date: |
Thu, 29 Oct 2009 20:29:28 -0400 |
> From: address@hidden [On Behalf Of SiTex Graphics]
> Not entirely sure this is a bug, but TextIO.ReadRestLine includes the
> EOL char in the string result. The XDS and Stonybrook implementations
> do not.
It is a bug; ReadRestLine() should not read the EOL or past it.
Verified by pulling out my trusty ISO/IEC 1014-1 document.
ReadRestLine() will return "allRight" if it finds some text before an EOL or
EOF,
so long as it does not find too much text for the parameter, in which case it
will
return "outOfRange" (and the excess chars are discarded).
Either way, you need to call SkipLine() to get past the EOL char, which returns
"allRight",
unless you are positioned past the last EOL char in the file in which case it
returns
"endOfInput".
ReadRestLine(), however will return "endOfLine" if the line was blank with an
EOL at the end.
You still have to call SkipLine() to get past that EOL char.
ReadRestLine() will instead return "endOfInput" if you are positioned beyond
the last EOL char.
At one point I got tired of my mistake prone attempts to rewrite the code for
reading a file line by line
via TextIO and write the following module whose procedures return only
"allRight" or "endOfInput".
It hides all the SkipLines() and necessity for multiple tests on return codes:
--------------------------------------------------------------------------------------------------------------------------------------
DEFINITION MODULE TextIOHelper;
...
PROCEDURE ReadNextLine(cid:ChanId; VAR OneLine:ARRAY OF CHAR):ReadResults;
PROCEDURE ReadNextNonBlankLine(cid:ChanId; VAR OneLine:ARRAY OF CHAR; VAR
NumSkipped:CARDINAL):ReadResults;
PROCEDURE dReadNextLine(cid:ChanId; VAR dOneLine:DynStr):ReadResults;
(* dOneLine must exist or .str be NIL *)
PROCEDURE dReadNextNonBlankLine(cid:ChanId; VAR dOneLine:DynStr; VAR
NumSkipped:CARDINAL):ReadResults;
(* ReadNextLine - silently truncates any line that won't fit in the
OneLine parameter
- never returns endOfLine. For empty line returns allRight
with empty OneLine
- endOfInput is returned only on the call AFTER the one
that returned the
last line allRight.
dReadNextLine - reallocates dOneLine to be larger if necessary.
*)
--------------------------------------------------------------------------------------------------------------------------------------
regards,
Tom
tmb"virginia.edu