Crates.io | choice-string |
lib.rs | choice-string |
version | 0.0.1 |
source | src |
created_at | 2023-04-15 01:52:48.625222 |
updated_at | 2023-04-15 01:52:48.625222 |
description | Provides utilities to parse selections (indices and ranges) from a string |
homepage | |
repository | https://github.com/CerulanLumina/choice-string |
max_upload_size | |
id | 839630 |
size | 26,872 |
Provides utilities to parse selections (indices and ranges) from a string
For this crate, the format of the selection string can be understood through the following example:
The following packages are available:
(1) good-package (2) bad-package (3) decent-package
(4) awful-package (5) amazing-package (6) package6
(7) package7 (8) package8
Select which packages to install:
>> 1 3 5 6-8
The following packages are being installed:
good-package, decent-package, amazing-package, package6,
package7, package8
...
In this case, the user has selected indices 1, 3, 5, and all between (inclusive) 6 through 8.
let selection = choice_string::parse("1, 2, 3, 4-8").expect("parse error");
assert!(selection.contains_item(5));
The delimiters are flexible. Any of the following work:
- A space,
- A comma;
- A semicolonYou can also use any combination of the above in a single string, and even mix as single separators.
For example:
1, 2, 3,5 6-9
1-8 11, 12
1,2,3,4
1;2;3;4
After parsing, the provided ranges are condensed by a union operation.
For example:
1, 2, 3, 4-5, 11
-> 1-5, 11