parse-numeric-range
Parse a 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
(used by syntax highlighters for line-range selection).
- Zero dependencies,
#![no_std] - Inclusive (
-,..,‥) and exclusive (...,…,⋯) ranges - Negative numbers and descending ranges
- Differential-tested against the reference
parse-numeric-rangeimplementation
Install
[]
= "0.1"
Usage
use parse;
assert_eq!;
assert_eq!;
assert_eq!; // descending
assert_eq!; // negatives
assert_eq!; // exclusive
assert_eq!; // junk is ignored
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; unrecognized entries are ignored,
and duplicates are kept (no deduplication). Numbers are parsed as i64. Like the reference,
ranges are fully expanded, so a very large range allocates one entry per value.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
Licensed under either of MIT or Apache-2.0 at your option.