pub fn non_escaped<const N: usize>(
input: &str,
esc: char,
delims: Sorted<char, N>,
) -> Result<NonEscaped<'_, N>, NonEscapedError>Expand description
Splits a str by the given delimiter unless it is preceded by a given escape. This is a
sanitization free version of non_escaped_sanitize.
§Errors
Returns an error if:
esc == delim
§Complexity
This algorithm requires O(n) time where n is the length of the input string.
§Allocation
No allocations are done.
§Examples
use strtools::split;
// split a string by some separator but ignore escaped ones
let parts: Vec<_> = split::non_escaped(
r"this string\ is split by\ spaces unless they are\ escaped",
'\\',
[' '].try_into()?
)?.collect();
// nothing is sanitized, the escapes are kept
assert_eq!(
parts,
[
r"this",
r"string\ is",
r"split",
r"by\ spaces",
r"unless",
r"they",
r"are\ escaped"
]
);