Function torut::utils::parse_single_key_value[][src]

pub fn parse_single_key_value(text: &str) -> Result<(&str, &str), ()>
Expand description

parse_single_key_value parses response in following format:

KEYWORD=VALUE
...

Error

It returns an error:

  • if there is no equal sign
  • if data before equal sign is not A-Za-z0-9_ -/$ ascii chars(notice space character)
  • if value is quoted string and enclosing quote is not last character of text

It does not return an error when key value is empty string so format is: ="asdf"

Example

use torut::utils::parse_single_key_value;
assert_eq!(parse_single_key_value("KEY=VALUE"), Ok(("KEY", "VALUE")));
assert_eq!(parse_single_key_value("INVALID"), Err(()));
assert_eq!(parse_single_key_value("VALID="), Ok(("VALID", "")));
assert_eq!(parse_single_key_value("KEY=\"QUOTED VALUE\""), Ok(("KEY", "\"QUOTED VALUE\"")));