wildcard

package module
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2025 License: Apache-2.0, BSD-3-Clause Imports: 1 Imported by: 25

README

Go-wildcard

Go Report Card Go Reference BSD 3 Clause

💡 Why

The purpose of this library is to provide a simple and fast wildcard pattern matching. Regex are much more complex and slower (even prepared regex)... and the filepath.Match is file-name-centric.

So, this library is a very fast and very simple alternative to regex and not tied to filename semantics unlike filepath.Match. There are no dependencies and is alocation free. 🥳

🧰 Features

There are the supported patterns operators:

  • * match zero or more characters
  • ? match zero or one character
  • . match exactly one character

🧐 How to

⚠️ WARNING: Unlike the GNU "libc", this library have no equivalent to "FNM_FILE_NAME". To do this you can use "path/filepath" https://pkg.go.dev/path/filepath#Match

There is super simple to use this library, you just have to import it and use the Match function.

package main

import (
	"fmt"

	"github.com/IGLOU-EU/go-wildcard/v2"
)

func main() {
    str := "daaadabadmanda"
    pattern := "?a*da*d.?*"

    resultM := wildcard.Match(pattern, str) // Fastest way but can't use '?' or '." with rune multiple byte representation
    resultMFB = wildcard.MatchFromByte([]byte(pattern), []byte(str)) // Same as Match to avoid convertion (bad example here)
    resultMBR = wildcard.MatchByRune(pattern, str) // Slower than Match but with strict rune comparison (not grapheme cluster)

	fmt.Println(str, pattern, result)
}

🛸 Benchmark

The benchmark is done with the following command:

go test -benchmem -bench . github.com/IGLOU-EU/go-wildcard/v2/benchmark
goos: linux
goarch: amd64
pkg: github.com/IGLOU-EU/go-wildcard/v2
cpu: AMD Ryzen 7 PRO 6850U with Radeon Graphics  

The tested fonctions are:

  • regexp.MatchString
  • filepath.Match
  • oldMatchSimple From the commit a899be92514ed08aa5271bc3b93320b719ce2114
  • oldMatch From the commit a899be92514ed08aa5271bc3b93320b719ce2114
  • Match From string with byte comparison
  • MatchByRune From string with rune comparison
  • MatchFromByte From byte slice with byte comparison

time bench allocs bench

🕰 History

Originally, this library was a fork from the Minio project. The purpose was to give access to this "lib" under Apache license, without importing the entire Minio project. And to keep it usable under the Apache License Version 2.0 after MinIO project is migrated to GNU Affero General Public License 3.0 or later from update license change for MinIO

The actual Minio wildcard matching code can be found in wildcard.go

Documentation

Overview

Code generated with go generate; DO NOT EDIT. This file was generated by cmd/build/build.go at 2025-02-07 17:37:01.573285599 +0100 CET using source from source/wildcard_match.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(pattern, s string) bool

Match returns true if the pattern matches the string s. It uses byte comparison rather than rune or grapheme cluster comparison. For matching complex Unicode, only the "*" wildcard or exact equality is supported.

func MatchByRune added in v2.1.0

func MatchByRune(pattern, s string) bool

MatchByRune returns true if the pattern matches the string s. It supports complex Unicode matching with wildcards such as "*", "?", and ".". Note that it incurs allocation and more CPU usage.

func MatchFromByte added in v2.1.0

func MatchFromByte(pattern, s []byte) bool

MatchFromByte returns true if the pattern matches the byte slice s. Similar to Match but operates on byte slices to avoid conversions/alloc.

Types

This section is empty.

Directories

Path Synopsis
cmd
build command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL