gix_glob/
lib.rs

1//! Provide glob [`Patterns`][Pattern] for matching against paths or anything else.
2//! ## Feature Flags
3#![cfg_attr(
4    all(doc, feature = "document-features"),
5    doc = ::document_features::document_features!()
6)]
7#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg, doc_auto_cfg))]
8#![deny(missing_docs, rust_2018_idioms)]
9#![forbid(unsafe_code)]
10
11use bstr::BString;
12
13/// A glob pattern optimized for matching paths relative to a root directory.
14///
15/// For normal globbing, use [`wildmatch()`] instead.
16#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
17#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18pub struct Pattern {
19    /// the actual pattern bytes
20    pub text: BString,
21    /// Additional information to help accelerate pattern matching.
22    pub mode: pattern::Mode,
23    /// The position in `text` with the first wildcard character, or `None` if there is no wildcard at all.
24    pub first_wildcard_pos: Option<usize>,
25}
26
27///
28pub mod pattern;
29
30pub mod search;
31
32///
33pub mod wildmatch;
34pub use wildmatch::function::wildmatch;
35
36mod parse;
37
38/// Create a [`Pattern`] by parsing `text` or return `None` if `text` is empty.
39///
40/// Note that
41pub fn parse(text: impl AsRef<[u8]>) -> Option<Pattern> {
42    Pattern::from_bytes(text.as_ref())
43}