split_ignore_arbitrary

Function split_ignore_arbitrary 

Source
pub fn split_ignore_arbitrary<P: Pattern>(
    val: &str,
    searched_pattern: P,
    ignore_parenthesis: bool,
) -> impl Iterator<Item = (usize, &str)>
Expand description

Split a value while avoiding arbitrary values/variants (wrapped in brackets) from being split.

The last argument indicates whether variant groups (wrapped in parentheses) are also ignored.

ยงExample

use encre_css::utils::split_ignore_arbitrary;

let value = "bg-red-500 content-[wrapped in `[]`, will not be split] (words wrapped in parenthesis are not split too)";
assert_eq!(split_ignore_arbitrary(value, ' ', true).collect::<Vec<(usize, &str)>>(), vec![(0, "bg-red-500"), (11, "content-[wrapped in `[]`, will not be split]"), (56, "(words wrapped in parenthesis are not split too)")]);