fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

Add lowerRegexp function.

+28
+18
regexp.go
··· 4 4 "regexp/syntax" 5 5 ) 6 6 7 + func lowerRegexp(r *syntax.Regexp) *syntax.Regexp { 8 + newRE := *r 9 + switch r.Op { 10 + case syntax.OpLiteral, syntax.OpCharClass: 11 + for i, r := range newRE.Rune { 12 + if r >= 'A' && r <= 'Z' { 13 + newRE.Rune[i] = r + 'a' - 'A' 14 + } 15 + } 16 + default: 17 + for i, s := range newRE.Sub { 18 + newRE.Sub[i] = lowerRegexp(s) 19 + } 20 + } 21 + 22 + return &newRE 23 + } 24 + 7 25 // regexpToQuery tries to distill a substring search query that 8 26 // matches a superset of the regexp. 9 27 func regexpToQuery(r *syntax.Regexp) Query {
+10
regexp_test.go
··· 73 73 } 74 74 } 75 75 } 76 + 77 + func TestLowerRegexp(t *testing.T) { 78 + in := "[a-zA-Z]fooBAR" 79 + re := mustParseRE(in) 80 + got := lowerRegexp(re) 81 + want := "[a-za-z]foobar" 82 + if got.String() != want { 83 + t.Errorf("got %s, want %s", got, want) 84 + } 85 + }