예제 #1
0
func TestTrieOptimizer_Compile(t *testing.T) {
	to := regexp.NewTrieOptimizer()
	to.Add("hoge")
	to.Add("fuga")
	to.Add("piyo")
	if to.Re() != "(?:fuga|hoge|piyo)" {
		t.Errorf("%s vs (?:fuga|hoge|piyo)", to.Re())
	}

	to = regexp.NewTrieOptimizer()
	to.Add("public")
	to.Add("private")
	to.Add("pipip.$")
	if to.Re() != "p(?:ipip\\.\\$|rivate|ublic)" {
		t.Errorf("%s vs p(?:ipip\\.\\$|rivate|ublic)", to.Re())
	}

	to = regexp.NewTrieOptimizer()
	if to.Re() != "^\\b\x00" {
		t.Errorf("%s vs ^\\b\x00", to.Re())
	}

	to = regexp.NewTrieOptimizer()
	to.Add("sun")
	to.Add("sunw")
	to.Add("org")
	pp.Println(to)
	if to.Re() != "(?:org|sunw?)" {
		t.Errorf("%s vs (?:org|sunw?)", to.Re())
	}
}
예제 #2
0
func newPathFilter(excludes []string, includes []string) *PathFilter {
	f := &PathFilter{}

	// ignore always
	ex := jireg.NewTrieOptimizer()
	for _, exclude := range excludes {
		prefix := strings.Replace(exclude, ".", "/", -1) + "/"
		if prefix != "/" {
			ex.Add(prefix)
		}
	}
	if *debug {
		fmt.Fprintf(os.Stderr, "exclude pattern: %s\n", ex.Re())
	}
	f.excludePattern, _ = regexp.Compile("^" + ex.Re() + "|\\$\\d+\\.class$")

	in := jireg.NewTrieOptimizer()
	for _, include := range includes {
		prefix := strings.Replace(include, ".", "/", -1) + "/"
		if prefix != "/" {
			in.Add(prefix)
		}
	}
	if *debug {
		fmt.Fprintf(os.Stderr, "include pattern: %s\n", in.Re())
	}
	f.includePattern, _ = in.Compile()
	return f
}