#iterator #escaping #text

escaped-delimiter

Iterator of delimited slices with escape characters

1 unstable release

0.1.0 Jun 8, 2023

#1746 in Text processing

MIT/Apache

11KB
207 lines

escaped-delimiter

escaped-delimiter provides an iterator of a delimited slice, considering an escape character.

See the examples at the doc.


lib.rs:

escaped-delimiter provides an iterator of a delimited slice, considering an escape character.

See the examples below.

Examples

use escaped_delimiter::iter;

// Without escape characters
let s = b"The quick brown fox";
let s_vec: Vec<_> = iter(s, b' ', b'\\').collect();
assert_eq!(s_vec, &[&b"The"[..], &b"quick"[..], &b"brown"[..], &b"fox"[..]]);

// Reverse it (`DoubleEndedIterator`)
let s = b"The quick brown fox";
let s_vec: Vec<_> = iter(s, b' ', b'\\').rev().collect();
assert_eq!(s_vec, &[&b"fox"[..], &b"brown"[..], &b"quick"[..], &b"The"[..]]);

// With escape characters
let s = b"a\\ b\\\\ c\\\\\\ d\\\\\\\\ e";
let s_vec: Vec<_> = iter(s, b' ', b'\\').collect();
assert_eq!(s_vec, &[&b"a\\ b\\\\"[..], &b"c\\\\\\ d\\\\\\\\"[..], &b"e"[..]]);

No runtime deps