aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-05-09 18:41:13 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-05-09 18:41:13 -0700
commitbb9317e1eb68a975cb9462d0cd61c62ff6061a49 (patch)
tree24d6d9346a647aadd37e7646c53e1596e26e8eec /src
parentfe0e6110261a2ccc742334699aa247b428348b82 (diff)
sscanf support for negative integers
Diffstat (limited to 'src')
-rw-r--r--src/library.js9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/library.js b/src/library.js
index f2f1a3cb..bac57b59 100644
--- a/src/library.js
+++ b/src/library.js
@@ -2306,13 +2306,15 @@ LibraryManager.library = {
unget();
next = get();
} else {
+ var first = true;
while ((curr < max_ || isNaN(max_)) && next > 0) {
if (!(next in __scanString.whiteSpace) && // stop on whitespace
- ((type == 's' ||
- ((type === 'd' || type == 'u') && next >= '0'.charCodeAt(0) && next <= '9'.charCodeAt(0)) ||
+ (type == 's' ||
+ ((type === 'd' || type == 'u') && ((next >= '0'.charCodeAt(0) && next <= '9'.charCodeAt(0)) ||
+ (first && next == '-'.charCodeAt(0)))) ||
(type === 'x' && (next >= '0'.charCodeAt(0) && next <= '9'.charCodeAt(0) ||
next >= 'a'.charCodeAt(0) && next <= 'f'.charCodeAt(0) ||
- next >= 'A'.charCodeAt(0) && next <= 'F'.charCodeAt(0))))) &&
+ next >= 'A'.charCodeAt(0) && next <= 'F'.charCodeAt(0)))) &&
(formatIndex >= format.length || next !== format[formatIndex].charCodeAt(0))) { // Stop when we read something that is coming up
buffer.push(String.fromCharCode(next));
next = get();
@@ -2320,6 +2322,7 @@ LibraryManager.library = {
} else {
break;
}
+ first = false;
}
}
if (buffer.length === 0) return 0; // Failure.