diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-04 16:08:34 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-04 16:08:34 -0400 |
| commit | 3513b94fc7505e48208814436a8d4bd6edcdd10c (patch) | |
| tree | 7c7632c58d8a975173369d84d3f9b02f7e2f7501 /docs/integers.md | |
| parent | 973b1c55c209a8f91e8cfacb3ab4a053ef82939e (diff) | |
Unify parsing code to correctly handle parsing integers and numbers with
a &success boolean. Check for overflow as well.
Diffstat (limited to 'docs/integers.md')
| -rw-r--r-- | docs/integers.md | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/docs/integers.md b/docs/integers.md index 653322fd..50ecd034 100644 --- a/docs/integers.md +++ b/docs/integers.md @@ -144,23 +144,39 @@ Converts a text representation of an integer into an integer. **Usage:** ```tomo -from_text(text: Text, the_rest: Text = "!&Text") -> Int +from_text(text: Text, success: Bool = !&Bool?) -> Int ``` **Parameters:** -- `text`: The string containing the integer. -- `the_rest`: If non-null, this pointer will be set to point to any unparseable text after the integer. +- `text`: The text containing the integer. +- `success`: If non-null, this pointer will be set to `yes` if the whole text + is a valid integer that fits within the representable range of the integer + type, otherwise `no`. **Returns:** -The integer represented by the string. +The integer represented by the text. If the given text contains a value outside +of the representable range, the number will be truncated to the minimum or +maximum representable value. Other failures to parse the number will return +zero. **Example:** ```tomo ->> from_text("123") +>> Int.from_text("123") = 123 ->> from_text("0xFF") +>> Int.from_text("0xFF") = 255 + +success := no +>> Int.from_text("asdf", &success) += 0 +>> success += no + +>> Int8.from_text("9999999", &success) += 127 +>> success += no ``` --- |
