diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/library.js | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/library.js b/src/library.js index a2d3244e..6eab2587 100644 --- a/src/library.js +++ b/src/library.js @@ -1579,12 +1579,12 @@ LibraryManager.library = { // stdio.h // ========================================================================== - _isFloat: function(text) { - return !!(/^[+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?$/.exec(text)); + _getFloat: function(text) { + return /^[+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?/.exec(text); }, // TODO: Document. - _scanString__deps: ['_isFloat'], + _scanString__deps: ['_getFloat'], _scanString: function(format, get, unget, varargs) { if (!__scanString.whiteSpace) { __scanString.whiteSpace = {}; @@ -1743,15 +1743,13 @@ LibraryManager.library = { // Read characters according to the format. floats are trickier, they may be in an unfloat state in the middle, then be a valid float later if (type == 'f' || type == 'e' || type == 'g' || type == 'F' || type == 'E' || type == 'G') { - var last = 0; next = get(); while (next > 0 && (!(next in __scanString.whiteSpace))) { buffer.push(String.fromCharCode(next)); - if (__isFloat(buffer.join(''))) { - last = buffer.length; - } next = get(); } + var m = __getFloat(buffer.join('')); + var last = m ? m[0].length : 0; for (var i = 0; i < buffer.length - last + 1; i++) { unget(); } |