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 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();
|
||||||
|
|
Loading…
Reference in a new issue