Skip to content

About

detect extglob patterns in a string

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

is-extglob

Detect extglob patterns in a string.

An extglob is one of bash's extended pattern operators: a trigger character from @ ? ! + * directly followed by a parenthesized group, like ?(abc) or @(a|b). This crate reports whether a string contains an unescaped extglob. It does not match or expand the pattern. Glob tooling uses a check like this first to skip strings that need no further work.

Installation

[dependencies]
is-extglob = "0.1"

Usage

use is_extglob::is_extglob;

assert!(is_extglob("?(abc)"));
assert!(is_extglob("xyz/@(a|b)/xyz"));
assert!(is_extglob("\\?(abc)/?(abc)")); // escaped one skipped, real one found

assert!(!is_extglob("\\?(abc)")); // escaped trigger
assert!(!is_extglob("@\\(abc)")); // escaped paren
assert!(!is_extglob("*.js")); // plain glob, not an extglob
assert!(!is_extglob("")); // empty string

Behavior

  • A trigger char directly followed by ( and a later ) is an extglob.
  • A backslash neutralizes the next character, so \?(abc) and ?\(abc) are not extglobs.
  • An escaped extglob followed by a real one returns true.
  • A closing paren on a later line does not complete the pattern. Four characters end a line: LF, CR, LINE SEPARATOR (U+2028), and PARAGRAPH SEPARATOR (U+2029). So @(a\rb) is not an extglob.
  • The empty string returns false.

No runtime dependencies. no_std compatible.

License

Licensed under the MIT license.

About

detect extglob patterns in a string

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages