swift-filename-matcher
0.1.2
published 11 months ago
6 stars
3 forks
2 watchers
MIT License
public
1 assets
637 downloads
12 KB
Compatibility level 1
abXb7Uu0iChOejY4LECma/Zn9/6THch/IeikkYhnjMg=
Maintained byIan Leitch
0.1.2
August 24, 2024
[expand for release notes]

swift-filename-matcher

A Swift port of Python's fnmatch module with optional support for Bash 'globstar' behavior (**).

Installation

Swift Package Manager

.package(url: "https://github.com/ileitch/swift-filename-matcher.git", from: "0.0.0")
.product(name: "FilenameMatcher", package: "swift-filename-matcher")

Bazel

bazel_dep(name = "swift-filename-matcher", version = "<version>")

Usage

let matcher = FilenameMatcher(
    pattern: "**/*.swift",
    options: [.globstar]
)
matcher.match(filename: "path/to/File.swift") // true

To obtain the regex for a given pattern:

FilenameMatcher.translate("**/File.swift") // (?s:(.*/)?File\.swift)\Z

Options

See FilenameMatcherOptions for the options that can be passed to FilenameMatcher. Note that 'globstar' support is enabled by default.