Skip to main content

Crate parse_numeric_range

Crate parse_numeric_range 

Source
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

SeparatorMeaningExampleResult
-, .., inclusive of the end1-3[1, 2, 3]
..., , exclusive of the end1...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 input into the list of integers it describes.