Function kvc::get_reserved_matchers[][src]

pub fn get_reserved_matchers() -> Vec<(String, Regex)>

Get the reserved keyword matchers as a HashMap<String,regex::Regex> You can add to this to change the way text is parsed

For each whitespace delimited token in the line, see if the regex matches it. If it does, that token is added as a “String” key,value pair under the corresponding name.

Default matchers pull out “Date” fields of the form YYYY-MM-DD and return tuples of the form (“Date”,)

You can add regexes and names by inserting into the returned hashmap and passing that to all kvc:: functions

Examples

The default result

 let (counts,strs) =kvc::read_kvc_line_default(&"    2021-01-01 ".to_string());
 assert_eq!(strs.len(),1);
 assert_eq!(counts.len(),0);
 assert_eq!(strs[0],("Date".to_string(),"2021-01-01".to_string()));

Adding a custom keyword matcher:

    let mut keywords = kvc::get_reserved_matchers();
    keywords.push(
        ( "One-plus-one".to_string(), regex::Regex::new(r"^\d{1}\+\d{1}$").unwrap()) );
    let (counts,strs) = kvc::read_kvc_line(&"    2021-01-01 \n 1+1   ".to_string(),&keywords,&"");
    assert_eq!(counts.len(),0);
    assert_eq!(strs.len(),2);
    assert_eq!(strs[0],("One-plus-one".to_string(),"1+1".to_string()));
    assert_eq!(strs[1],("Date".to_string(),"2021-01-01".to_string()));

Returns

A keyword matcher, populated with the following matchers

  • {“^\d{4}-\d{2}-\d{2}” –> “Date”}

See also

  • [kvc::read_kvc_line]