Expand description
§parse-numeric-range — parse a string of numbers and ranges
Expand a comma-separated string of numbers and ranges into a list of integers:
"1,3-5,8" → [1, 3, 4, 5, 8]. A faithful Rust port of the
parse-numeric-range npm package.
use parse_numeric_range::parse;
assert_eq!(parse("1,3-5,8"), [1, 3, 4, 5, 8]);
assert_eq!(parse("5-1"), [5, 4, 3, 2, 1]); // descending
assert_eq!(parse("-5--2"), [-5, -4, -3, -2]); // negatives§Range separators
| Separator | Meaning | Example | Result |
|---|---|---|---|
-, .., ‥ | inclusive of the end | 1-3 | [1, 2, 3] |
..., …, ⋯ | exclusive of the end | 1...3 | [1, 2] |
Whitespace around each comma-separated entry is trimmed; anything that is not a plain
number or a number SEP number range is ignored. Numbers are parsed as i64.
Note: like the reference, ranges are fully expanded, so a huge range (e.g. 0-1000000000)
allocates one entry per value.
Zero dependencies and #![no_std].
Functions§
- parse
- Parse
inputinto the list of integers it describes.