wildcard-glob 11.2.0

Zero-dependency, zero-allocation compiled wildcard and path glob pattern matcher supporting *, **, ?, character classes, brace alternation, and multi-pattern GlobSet.
Documentation
use super::*;

/// Compact 8-byte compiled token inside a single brace-expanded glob branch.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum GlobToken {
    /// Exact literal character.
    Literal(char),
    /// Matches any single character (`?`, excluding `/` in path-aware mode).
    AnyChar,
    /// Matches zero or more characters (`*`, excluding `/` in path-aware mode).
    Star,
    /// Matches zero or more characters including path separators (`**`).
    DoubleStar,
    /// Index into the branch's side [`CharClass`] table.
    Class(u16),
}

/// Fast-path classification for a single compiled glob branch.
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) enum CompiledBranch {
    /// Pure literal string with no wildcards.
    Exact(String),
    /// Literal prefix followed by `**` (or `*` in non-path mode).
    Prefix(String),
    /// `**` (or `*` in non-path mode) followed by literal suffix.
    Suffix(String),
    /// Literal prefix followed by single-segment `*` (no `/` in remaining tail).
    StarPrefix(String),
    /// Single-segment `*` followed by literal suffix (no `/` in leading head).
    StarSuffix(String),
    /// Literal prefix + single-segment `*` + literal suffix (no `/` in middle).
    PrefixStarSuffix {
        /// Leading literal prefix.
        prefix: String,
        /// Trailing literal suffix.
        suffix: String,
    },
    /// Literal prefix + `**` + literal suffix.
    PrefixDoubleStarSuffix {
        /// Leading literal prefix.
        prefix: String,
        /// Trailing literal suffix.
        suffix: String,
    },
    /// `**` + literal + `**` substring search.
    Contains(String),
    /// `**/*<suffix>` where `<suffix>` contains no `/` (must end with suffix and have `/` before it).
    DoubleStarSlashStarSuffix(String),
    /// General token sequence evaluated in linear/iterative time.
    Tokens {
        /// Compact token array.
        tokens: Vec<GlobToken>,
        /// Side table of compiled character classes referenced by `GlobToken::Class`.
        classes: Vec<CharClass>,
    },
}