Function icu::experimental::unicodeset_parse::parse_with_variables
source · pub fn parse_with_variables(
source: &str,
variable_map: &VariableMap<'_>,
) -> Result<(CodePointInversionListAndStringList<'static>, usize), ParseError>
Expand description
Parses a UnicodeSet pattern with support for variables enabled.
See parse
for more information.
§Examples
use icu::experimental::unicodeset_parse::*;
let (my_set, _) = parse("[abc]").unwrap();
let mut variable_map = VariableMap::new();
variable_map.insert_char("start".into(), 'a').unwrap();
variable_map.insert_char("end".into(), 'z').unwrap();
variable_map.insert_string("str".into(), "Hello World".into()).unwrap();
variable_map.insert_set("the_set".into(), my_set).unwrap();
// If a variable already exists, `Err` is returned, and the map is not updated.
variable_map.insert_char("end".into(), 'Ω').unwrap_err();
let source = "[[$start-$end]-$the_set $str]";
let (set, consumed) = parse_with_variables(source, &variable_map).unwrap();
assert_eq!(consumed, source.len());
assert!(set.code_points().contains_range('d'..='z'));
assert!(set.contains_str("Hello World"));
assert_eq!(set.size(), 1 + ('d'..='z').count());