I'm using StrReadWord to parse a line of input to my program. If the last 'word' is a single character, then it doesn't get read. Is this behaviour intentional?
Example: program test(output);
uses StringUtils;
var src : string ="abc xy"; dest : string; i : integer;
begin i := 1;
while StrReadWord(src,i,dest) do writeln(i,dest:10)
end.
This produces, as I expected:
4 abc 7 xy
But if the last character of the string is removed:
src : string ="abc x";
the output becomes:
4 abc
What happened to the 'x'?
I'm using gpc 20010115.
Steve Loft wrote:
I'm using StrReadWord to parse a line of input to my program. If the last 'word' is a single character, then it doesn't get read. Is this behaviour intentional?
No, thanks for the bug report (steve1.pas). It's an easy off-by-one error. Here's a fix which will also be uploaded soon:
--- /home/gpc/src/p/units/stringutils.pas.orig Wed Feb 7 18:16:16 2001 +++ /home/gpc/src/p/units/stringutils.pas Wed Feb 7 18:16:19 2001 @@ -451,7 +451,7 @@ begin StrReadWord := False; StrSkipSpaces (s, i); - if i >= Length (s) then Exit; + if i > Length (s) then Exit; j := CharPosFrom (SpaceCharacters + [','], s, i + 1); if j = 0 then j := Length (s) + 1; if j - i > GetStringCapacity (Dest) then Exit;
Frank
On Wednesday 07 February 2001 5:18 pm, Frank Heckenbach wrote:
No, thanks for the bug report (steve1.pas). It's an easy off-by-one error. Here's a fix which will also be uploaded soon:
Thanks for that, Frank, works a treat. I'm only sorry I didn't spend a few minutes trying to find the bug myself.