Go glob
Go to file
gobwas 787d8be671 Progress 2016-01-11 10:17:19 +03:00
match Progress 2016-01-11 10:17:19 +03:00
.gitignore Initial 2015-11-30 17:58:20 +03:00
.travis.yml Travis 2015-11-30 18:37:30 +03:00
all.mem Progress 2016-01-11 10:17:19 +03:00
all.prof Progress 2016-01-11 10:17:19 +03:00
compiler.go Progress 2016-01-11 10:17:19 +03:00
compiler_test.go Progress 2016-01-11 10:17:19 +03:00
glob.go Progress 2016-01-08 20:14:31 +03:00
glob.test Progress 2016-01-11 10:17:19 +03:00
glob_test.go Progress 2016-01-11 10:17:19 +03:00
lexer.go Progress 2016-01-08 20:14:31 +03:00
lexer_test.go Progress 2016-01-08 20:14:31 +03:00
parser.go Fixes 2016-01-09 02:34:41 +03:00
parser_test.go Progress 2016-01-08 20:14:31 +03:00
readme.md =) 2015-12-01 17:22:53 +03:00
util.go Fixes 2016-01-09 02:34:41 +03:00

readme.md

glob.go

GoDoc Build Status

Simple globbing library.

Install

    go get github.com/gobwas/glob

Example


package main

import "github.com/gobwas/glob"

func main() {
    var g glob.Glob
    
    // create simple glob
    g = glob.New("*.github.com")
    g.Match("api.github.com") // true
    
    // create new glob with set of delimiters as ["."]
    g = glob.New("api.*.com", ".")
    g.Match("api.github.com") // true
    g.Match("api.gi.hub.com") // false
    
    // create new glob with set of delimiters as ["."]
    // but now with super wildcard
    g = glob.New("api.**.com", ".")
    g.Match("api.github.com") // true
    g.Match("api.gi.hub.com") // true
        
    // create glob with single symbol wildcard
    g = glob.New("?at")
    g.Match("cat") // true
    g.Match("fat") // true
    g.Match("at") // false
    
    // create glob with single symbol wildcard and delimiters ["f"]
    g = glob.New("?at", "f")
    g.Match("cat") // true
    g.Match("fat") // false
    g.Match("at") // false 
}

Performance

In comparison with go-glob, it is ~2.5x faster (on my Mac), because my impl compiles patterns for future usage. If you will not use compiled glob.Glob object, and do g := glob.New(pattern); g.Match(...) every time, then your code will be about ~3x slower.

Run go test bench=. from source root to see the benchmarks:

Test Operations Speed
github.com/gobwas/glob 20000000 150 ns/op
github.com/ryanuber/go-glob 10000000 375 ns/op

Also, there are few simple optimizations, that help to test much faster patterns like *abc, abc* or a*c:

Test Operations Speed
prefix 200000000 8.78 ns/op
suffix 200000000 9.46 ns/op
prefix-suffix 100000000 16.3 ns/op