| 1 | package experimental |
| 2 | |
| 3 | import ( |
| 4 | "github.com/betterleaks/go-re2" |
| 5 | "github.com/betterleaks/go-re2/internal" |
| 6 | ) |
| 7 | |
| 8 | // CompileLatin1 is like regexp.Compile but causes the matching to treat |
| 9 | // the input as arbitrary bytes rather than unicode strings. This is |
| 10 | // similar behavior to the rsc.io/binaryregexp package. |
| 11 | func CompileLatin1(expr string) (*re2.Regexp, error) { |
| 12 | return internal.Compile(expr, internal.CompileOptions{Latin1: true}) //nolint:wrapcheck // just a method forwarder |
| 13 | } |
| 14 | |
| 15 | // MustCompileLatin1 is like CompileLatin1 but panics if the expression cannot be parsed. |
| 16 | // It simplifies safe initialization of global variables holding compiled regular |
| 17 | // expressions. |
| 18 | func MustCompileLatin1(str string) *re2.Regexp { |
| 19 | regexp, err := CompileLatin1(str) |
| 20 | if err != nil { |
| 21 | panic(`regexp: CompileLatin1(` + internal.QuoteForError(str) + `): ` + err.Error()) |
| 22 | } |
| 23 | return regexp |
| 24 | } |
| 25 | |
| 26 | // Set is a compiled collection of regular expressions that can be searched for simultaneously. |
| 27 | type Set = internal.Set |
| 28 | |
| 29 | // CompileSet compiles the set of regular expression in preparation for matching. |
| 30 | func CompileSet(exprs []string) (*Set, error) { |
| 31 | return internal.CompileSet(exprs, internal.CompileOptions{}) //nolint:wrapcheck // just a method forwarder |
| 32 | } |