gobwas / glob

Go glob
MIT License
948 stars 63 forks source link

Add MatchBytes() #32

Open willbuckner opened 5 years ago

willbuckner commented 5 years ago

Adding a MatchBytes() to match a glob pattern against a byte slice would be incredibly useful for searching within files.

For example:

package main

import "github.com/gobwas/glob"

func main() {
    var g glob.Glob

    g = glob.MustCompile("*.github.com")
    g.MatchBytes([]byte("api.github.com")) // true
}

A further justification of this is how the regex package operates on bytes by default. I am not suggesting modifying the default behavior, though, but adding a MatchString() alias could help maintain compatibility if it ever becomes the default.