Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write a number algorithm that matches ABNF #551

Merged
merged 3 commits into from Apr 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 18 additions & 6 deletions draft-ietf-httpbis-header-structure.md
Expand Up @@ -354,12 +354,24 @@ Example-IntegerHeader: 42

NOTE: This algorithm parses both Integers and Floats {{float}}, and returns the corresponding structure.

1. If the first character of input_string is not "-" or a DIGIT, fail parsing.
2. Let input_number be the result of consuming input_string up to (but not including) the first character that is not in DIGIT, "-", and ".".
3. If any character of input_number after the first is "-", fail parsing.
4. If input_number contains ".", parse it as a floating point number and let output_number be the result.
5. Otherwise, parse input_number as an integer and let output_number be the result.
6. Return output_number.
1. Let type be "integer".
2. Let sign be 1.
3. Let input_number be an empty string.
4. If the first character of input_string is "-", remove it from input_string and set sign to -1.
5. If input_string is empty, fail parsing.
6. If the first character of input_string is not a DIGIT, fail parsing.
7. While input_string is not empty:
1. Let char be the result of removing the first character of input_string.
2. If char is a DIGIT, append it to input_number.
3. Else, if type is "integer" and char is ".", append char to input_number and set type to "float".
4. Otherwise, fail parsing.
5. If type is "integer" and input_number contains more than 19 characters, fail parsing.
6. If type is "float" and input_number contains more than 16 characters, fail parsing.
8. If type is "integer", parse input_number as an integer and let output_number be the result.
9. Otherwise:
1. If the final character of input_number is ".", fail parsing.
2. Parse input_number as a float and let output_number be the result.
0. Return the product of output_number and sign.


## Floats {#float}
Expand Down