| Crates.io | delim |
| lib.rs | delim |
| version | 0.1.1 |
| created_at | 2021-03-14 07:44:44.70428+00 |
| updated_at | 2021-03-20 19:31:16.447352+00 |
| description | A library for parsing values from delimited strings. |
| homepage | https://github.com/stuartthompson/delim |
| repository | https://github.com/stuartthompson/delim |
| max_upload_size | |
| id | 368711 |
| size | 55,444 |
Helps parse strings that use delimeters to separate values.
The following retrieves a value wrapped by matched delimiters:
assert_eq!(Delimited::matched("abc:12:def", ":"), Some(12));
This retrieves a value wrapped within mismatched patterns:
assert_eq!(Delimited::mismatched("abc<<12*&def", "<<", "*&"), Some(12));
The following shows how using a Delimited instance along with consume_matched can be used to extract two different delimited values from a string.
let mut d = Delimited::new("aaa :12: bbb :34: ccc");
// Consume first value (expecting 12)
let first = d.consume_matched(":");
// Consume second value (expecting 34)
let second = d.consume_matched(":");
assert_eq!(first, Some(12));
assert_eq!(second, Some(34));
There are three primary delimited pattern types:
Additionally, a number of bytes can be consumed raw (without delimiters) and either returned as a string or parsed to a specified type.
In the following string, the value 12 occupies the first two bytes.
12abc
The first two bytes can be consumed as a u8 with the following:
let d = Delimited::new("12abc");
assert_eq!(d.bytes::<u8>(2), Some(12));
In the following string, the value 12 is wrapped by matched ":" delimiters.
abc:12:def
In this string, the value 12 is wrapped by mismatched ":" and "<" delimiters.
abc:12<def
In this string, we decide that the value 12 is prefixed by |.
abc|12def
Prefixed delimiter searches requires the value length to be specified.