Fix parsing numbers with padded whitespaces (#607)

This commit is contained in:
Max Graey
2019-05-27 15:37:07 +03:00
committed by Daniel Wirtz
parent 0339d82781
commit 9c51f1332c
5 changed files with 2287 additions and 1988 deletions

View File

@ -40,7 +40,7 @@ export const enum CharCode {
z = 0x7A
}
export function isWhiteSpaceOrLineTerminator(c: u16): bool {
export function isWhiteSpaceOrLineTerminator(c: i32): bool {
switch (c) {
case 9: // <TAB>
case 10: // <LF>
@ -67,6 +67,11 @@ export function parse<T>(str: string, radix: i32 = 0): T {
// determine sign
var sign: T;
// trim white spaces
while (isWhiteSpaceOrLineTerminator(code)) {
code = <i32>load<u16>(ptr += 2);
--len;
}
if (code == CharCode.MINUS) {
// @ts-ignore: cast
if (!--len) return <T>NaN;