code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(51 lines)
1 '\" t
2 .\" Copyright (c) 2026 Bruce Hill
3 .\" All rights reserved.
4 .\"
5 .TH Int.parse 3 2026-03-08 "Tomo man-pages"
6 .SH NAME
7 Int.parse \- convert text to integer
8 .SH LIBRARY
9 Tomo Standard Library
10 .SH SYNOPSIS
11 .nf
12 .BI Int.parse\ :\ func(text:\ Text,\ base:\ Int?\ =\ none,\ remainder:\ &Text?\ =\ none\ ->\ Int?)
13 .fi
14 .SH DESCRIPTION
15 Converts a text representation of an integer into an integer.
18 .SH ARGUMENTS
20 .TS
21 allbox;
22 lb lb lbx lb
23 l l l l.
24 Name Type Description Default
25 text Text The text containing the integer. -
26 base Int? The numeric base to use when parsing the integer. If unspecified, the integer's base will be inferred from the text prefix. After any "+" or "-" sign, if the text begins with "0x", the base will be assumed to be 16, "0o" will assume base 8, "0b" will assume base 2, otherwise the base will be assumed to be 10. none
27 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
28 .TE
29 .SH RETURN
30 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.
32 .SH EXAMPLES
33 .EX
34 assert Int.parse("123") == 123
35 assert Int.parse("0xFF") == 255
36 assert Int.parse("123xyz") == none
37 remainder : Text
38 assert Int.parse("123xyz", remainder=&remainder) == 123
39 assert remainder == "xyz"
41 # Can't parse:
42 assert Int.parse("asdf") == none
44 # Outside valid range:
45 assert Int8.parse("9999999") == none
47 # Explicitly specifying base:
48 assert Int.parse("10", base=16) == 16
49 .EE
50 .SH SEE ALSO
51 .BR Tomo-Int (3)