bit_ignore

.gitignore + glob matching (gix-ignore + gix-glob equivalent)

git
gitignore
glob
moon add mizchi/bit_ignore@0.46.4
Download zip
Author
Version
0.46.4
License
Apache-2.0
Last updated
4 days ago
Downloads
495
README

#
Matcher

pub struct Matcher {
rules : Array[Rule]
negation_count : Int
}

A collection of ignore rules that can check if paths are ignored.

#
Matcher::add_rules

fn Matcher::add_rules(self : Matcher, base : String, content : String) -> Unit

Add rules from gitignore content. base is the relative directory where the gitignore file is located.

#
Matcher::could_negate_under

fn Matcher::could_negate_under(self : Matcher, dir_rel : String) -> Bool

Check if any negation rule could potentially un-ignore a child under dir_rel. More precise than has_negation() — only returns true if a negation rule's target path overlaps with the given directory.

#
Matcher::has_negation

fn Matcher::has_negation(self : Matcher) -> Bool

Whether any negation rules have been added.

#
Matcher::is_ignored

fn Matcher::is_ignored(self : Matcher, rel_path : String, is_dir : Bool) -> Bool

Check if a path is ignored. rel_path is the path relative to the root. is_dir indicates whether the path is a directory.

#
Matcher::len

fn Matcher::len(self : Matcher) -> Int

Get current number of rules.

#
Matcher::new

fn Matcher::new() -> Matcher

Create a new empty matcher.

#
Matcher::truncate

fn Matcher::truncate(self : Matcher, len : Int) -> Unit

Remove rules added after a certain point (for backtracking during traversal).

#
Rule

pub struct Rule {
base : String
pattern : String
pattern_chars : FixedArray[UInt16]
pattern_segments : Array[FixedArray[UInt16]]
negated : Bool
dir_only : Bool
anchored : Bool
has_slash : Bool
base_len : Int
}

A single ignore rule parsed from a gitignore file.

#
match_glob

fn match_glob(pattern : String, text : String) -> Bool

Check if a single pattern matches a path segment. Supports * (any characters) and ? (single character) wildcards.

#
parse

fn parse(content : String, base : String) -> Array[Rule]

Parse gitignore content into rules. base is the relative directory where the gitignore file is located.

Source Files