1
0
Fork 0

scanf: '+' or '-' alone aren't really numbers

This commit is contained in:
mfranz 2008-09-28 16:20:49 +00:00
parent e95edc0b43
commit 13a5e62995

View file

@ -282,9 +282,13 @@ var scanf = func(str, format) {
} }
var numstr = ""; var numstr = "";
var plus = 0;
if (f == `d` or f == `f`) { # int or float with optional minus if (f == `d` or f == `f`) { # int or float with optional minus
if (str.getc() == `-`) var c = str.getc();
numstr = "-"; if (c == `+`)
plus = 1;
elsif (c == `-`)
numstr = chr(c);
else else
str.ungetc(); str.ungetc();
} }
@ -305,6 +309,9 @@ var scanf = func(str, format) {
str.ungetc(); str.ungetc();
} }
if (!size(numstr) and plus or numstr == "-")
return nil;
if (fnum != nil and size(numstr) > fnum) if (fnum != nil and size(numstr) > fnum)
for (var i = size(numstr) - fnum; i; i -= 1) for (var i = size(numstr) - fnum; i; i -= 1)
str.ungetc(); str.ungetc();