// 5. If position is past the end of input, return an error.
if(lexer.is_eof()){
return{};
}
// 6. If the character indicated by position (the first character) is a U+002D HYPHEN-MINUS character (-):
//
// If we parse a signed integer, then we include the sign character (if present) in the collect step
// (step 8) and lean on `AK::StringUtils::convert_to_int` to handle it for us.
size_tstart_index=lexer.tell();
if(lexer.peek()=='-'||lexer.peek()=='+'){
lexer.consume();
}
// 7. If the character indicated by position is not an ASCII digit, then return an error.
if(!lexer.next_is(is_ascii_digit)){
return{};
}
// 8. Collect a sequence of code points that are ASCII digits from input given position, and interpret the resulting sequence as a base-ten integer. Let value be that integer.
// 13.3. If the character indicated by position is a U+0065 LATIN SMALL LETTER E character (e) or a U+0045 LATIN CAPITAL LETTER E character (E),
// skip the remainder of these substeps.
if(lexer.next_is('e')||lexer.next_is('E')){
gotofraction_exit;
}
// fraction_loop:
while(true){
// 13.4. Fraction loop: Multiply divisor by ten.
divisor*=10;
// 13.5. Add the value of the character indicated by position, interpreted as a base-ten digit (0..9) and divided by divisor, to value.
value+=(lexer.peek()-'0')/divisor;
// 13.6. Advance position to the next character.
lexer.consume();
// 13.7. If position is past the end of input, then jump to the step labeled conversion.
if(lexer.is_eof()){
gotoconversion;
}
// 13.8. If the character indicated by position is an ASCII digit, jump back to the step labeled fraction loop in these substeps.
if(!lexer.next_is(is_ascii_digit)){
break;
}
}
}
fraction_exit:
}
// 14. If the character indicated by position is U+0065 (e) or a U+0045 (E), then:
if(lexer.next_is('e')||lexer.next_is('E')){
// 14.1. Advance position to the next character.
lexer.consume();
// 14.2. If position is past the end of input, then jump to the step labeled conversion.
if(lexer.is_eof()){
gotoconversion;
}
// 14.3. If the character indicated by position is a U+002D HYPHEN-MINUS character (-):
if(lexer.next_is('-')){
// 14.3.1. Change exponent to −1.
exponent=-1;
// 14.3.2. Advance position to the next character.
lexer.consume();
// 14.3.3. If position is past the end of input, then jump to the step labeled conversion.
if(lexer.is_eof()){
gotoconversion;
}
}
// Otherwise, if the character indicated by position is a U+002B PLUS SIGN character (+):
elseif(lexer.next_is('+')){
// 14.3.1. Advance position to the next character.
lexer.consume();
// 14.3.2. If position is past the end of input, then jump to the step labeled conversion.
if(lexer.is_eof()){
gotoconversion;
}
}
// 14.4. If the character indicated by position is not an ASCII digit, then jump to the step labeled conversion.
if(!lexer.next_is(is_ascii_digit)){
gotoconversion;
}
// 14.5. Collect a sequence of code points that are ASCII digits from input given position, and interpret the resulting sequence as a base-ten integer.
// 16. Let rounded-value be the number in S that is closest to value, selecting the number with an even significand if there are two equally close values.
// (The two special values 2^1024 and −2^1024 are considered to have even significands for this purpose.)
doublerounded_value=value;
// 17. If rounded-value is 2^1024 or −2^1024, return an error.