scanf: '+' or '-' alone aren't really numbers
This commit is contained in:
parent
e95edc0b43
commit
13a5e62995
1 changed files with 9 additions and 2 deletions
|
@ -282,9 +282,13 @@ var scanf = func(str, format) {
|
|||
}
|
||||
|
||||
var numstr = "";
|
||||
var plus = 0;
|
||||
if (f == `d` or f == `f`) { # int or float with optional minus
|
||||
if (str.getc() == `-`)
|
||||
numstr = "-";
|
||||
var c = str.getc();
|
||||
if (c == `+`)
|
||||
plus = 1;
|
||||
elsif (c == `-`)
|
||||
numstr = chr(c);
|
||||
else
|
||||
str.ungetc();
|
||||
}
|
||||
|
@ -305,6 +309,9 @@ var scanf = func(str, format) {
|
|||
str.ungetc();
|
||||
}
|
||||
|
||||
if (!size(numstr) and plus or numstr == "-")
|
||||
return nil;
|
||||
|
||||
if (fnum != nil and size(numstr) > fnum)
|
||||
for (var i = size(numstr) - fnum; i; i -= 1)
|
||||
str.ungetc();
|
||||
|
|
Loading…
Reference in a new issue