aboutsummaryrefslogtreecommitdiff
path: root/api/integers.md
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-16 17:21:01 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-16 17:21:01 -0400
commitc72b0406a32ffc3f04324f7b6c321486762fca41 (patch)
tree244e51c858890ea2ffb8c74a2c33c81b79de376e /api/integers.md
parent849fd423a759edf1b58b548a6148c177a6f8cd71 (diff)
Improved parsing and prefix/suffix matching using a `remainder`
parameter
Diffstat (limited to 'api/integers.md')
-rw-r--r--api/integers.md11
1 files changed, 10 insertions, 1 deletions
diff --git a/api/integers.md b/api/integers.md
index efb891bf..6468589e 100644
--- a/api/integers.md
+++ b/api/integers.md
@@ -272,7 +272,7 @@ stop if i == 10
## Int.parse
```tomo
-Int.parse : func(text: Text -> Int?)
+Int.parse : func(text: Text, remainder: &Text? = none -> Int?)
```
Converts a text representation of an integer into an integer.
@@ -280,6 +280,7 @@ Converts a text representation of an integer into an integer.
Argument | Type | Description | Default
---------|------|-------------|---------
text | `Text` | The text containing the integer. | -
+remainder | `&Text?` | If non-none, this argument will be set to the remainder of the text after the matching part. If none, parsing will only succeed if the entire text matches. | `none`
**Return:** The integer represented by the text. If the given text contains a value outside of the representable range or if the entire text can't be parsed as an integer, `none` will be returned.
@@ -291,6 +292,14 @@ text | `Text` | The text containing the integer. | -
>> Int.parse("0xFF")
= 255 : Int?
+>> Int.parse("123xyz")
+= none
+remainder : Text
+>> Int.parse("123xyz", &remainder)
+= 123 : Int?
+>> remainder
+= "xyz"
+
# Can't parse:
>> Int.parse("asdf")
= none : Int?