Skip to main content

classify

Function classify 

Source
pub fn classify(pat: &str) -> PatternKind
Expand description

Classify a raw pattern according to the suite’s promotion rule.

A pattern is Regex only when it both carries explicit regex metacharacters and compiles, so an invalid-as-regex string such as *.java (leading quantifier) falls back to Glob.

§Examples

use coding_tools::pattern::{classify, PatternKind};

assert_eq!(classify("ERROR:"), PatternKind::Literal); // no metacharacters
assert_eq!(classify("*.java"), PatternKind::Glob);     // a leading `*` is not a valid regex
assert_eq!(classify(r"\d+"), PatternKind::Regex);      // valid regex with metacharacters