Path: blob/main/cranelift/filetests/src/match_directive.rs
1691 views
/// Look for a directive in a comment string.1/// The directive is of the form "foo:" and should follow the leading `;` in the comment:2///3/// ; dominates: block3 block44///5/// Return the comment text following the directive.6pub fn match_directive<'a>(comment: &'a str, directive: &str) -> Option<&'a str> {7assert!(8directive.ends_with(':'),9"Directive must include trailing colon"10);11let text = comment.trim_start_matches(';').trim_start();12text.strip_prefix(directive).map(|s| s.trim())13}1415#[test]16fn test_match_directive() {17assert_eq!(match_directive("; foo: bar ", "foo:"), Some("bar"));18assert_eq!(match_directive(" foo:bar", "foo:"), Some("bar"));19assert_eq!(match_directive("foo:bar", "foo:"), Some("bar"));20assert_eq!(match_directive(";x foo: bar", "foo:"), None);21assert_eq!(match_directive(";;; foo: bar", "foo:"), Some("bar"));22}232425