-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding
regexp
capabilities to speed up pattern checks per line dras…
…tically
- Loading branch information
Showing
4 changed files
with
34 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package re | ||
|
||
import ( | ||
"errors" | ||
"regexp" | ||
) | ||
|
||
// CompileSlice takes a slice of string of what could be | ||
// regular expression patterns, attempts to compile them and return | ||
// the compiled pattern for use along with a slice of errors for any | ||
// that failed. | ||
func CompileSlice(patterns []string) ([]*regexp.Regexp, error) { | ||
errs := make([]error, 0, len(patterns)) | ||
regexps := make([]*regexp.Regexp, 0, len(patterns)) | ||
for _, pattern := range patterns { | ||
c, err := regexp.Compile(pattern) | ||
if err != nil { | ||
errs = append(errs, err) | ||
} else { | ||
regexps = append(regexps, c) | ||
} | ||
} | ||
return regexps, errors.Join(errs...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package re |