code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(30 lines)
1 Bool.parse:
2 short: parse into boolean
3 description: >
4 Converts a text representation of a boolean value into a boolean. Acceptable
5 boolean values are case-insensitive variations of `yes`/`no`, `y`/`n`,
6 `true`/`false`, `on`/`off`.
7 return:
8 type: 'Bool?'
9 description: >
10 `yes` if the string matches a recognized truthy boolean value; otherwise return `no`.
11 args:
12 text:
13 type: 'Text'
14 description: >
15 The string containing the boolean value.
16 remainder:
17 type: '&Text?'
18 default: 'none'
19 description: >
20 If non-none, this argument will be set to the remainder of the text after the matching part.
21 If none, parsing will only succeed if the entire text matches.
22 example: |
23 assert Bool.parse("yes") == yes
24 assert Bool.parse("no") == no
25 assert Bool.parse("???") == none
27 assert Bool.parse("yesJUNK") == none
28 remainder : Text
29 assert Bool.parse("yesJUNK", &remainder) == yes
30 assert remainder == "JUNK"