code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(33 lines)

% API

Builtins

Bool

Bool.parse

Bool.parse : func(text: Text, remainder: &Text? = none -> Bool?)

Converts a text representation of a boolean value into a boolean. Acceptable boolean values are case-insensitive variations of yes/no, y/n, true/false, on/off.

Argument Type Description Default
text Text The string containing the boolean value. -
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: yes if the string matches a recognized truthy boolean value; otherwise return no.

Example:

assert Bool.parse("yes") == yes
assert Bool.parse("no") == no
assert Bool.parse("???") == none

assert Bool.parse("yesJUNK") == none
remainder : Text
assert Bool.parse("yesJUNK", &remainder) == yes
assert remainder == "JUNK"

1 % API
3 # Builtins
5 # Bool
6 ## Bool.parse
8 ```tomo
9 Bool.parse : func(text: Text, remainder: &Text? = none -> Bool?)
10 ```
12 Converts a text representation of a boolean value into a boolean. Acceptable boolean values are case-insensitive variations of `yes`/`no`, `y`/`n`, `true`/`false`, `on`/`off`.
14 Argument | Type | Description | Default
15 ---------|------|-------------|---------
16 text | `Text` | The string containing the boolean value. | -
17 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`
19 **Return:** `yes` if the string matches a recognized truthy boolean value; otherwise return `no`.
22 **Example:**
23 ```tomo
24 assert Bool.parse("yes") == yes
25 assert Bool.parse("no") == no
26 assert Bool.parse("???") == none
28 assert Bool.parse("yesJUNK") == none
29 remainder : Text
30 assert Bool.parse("yesJUNK", &remainder) == yes
31 assert remainder == "JUNK"
33 ```