aboutsummaryrefslogtreecommitdiff
path: root/config_match_license.go
diff options
context:
space:
mode:
Diffstat (limited to 'config_match_license.go')
-rw-r--r--config_match_license.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/config_match_license.go b/config_match_license.go
index 11e09fe..c027019 100644
--- a/config_match_license.go
+++ b/config_match_license.go
@@ -3,7 +3,15 @@
package spdxconv
+import (
+ "fmt"
+ "regexp"
+)
+
type configMatchLicense struct {
+ rePattern *regexp.Regexp
+ reDeleteLine []*regexp.Regexp
+
// Pattern to be searched in file.
Pattern string `ini:"match-license::pattern"`
@@ -21,3 +29,22 @@ type configMatchLicense struct {
// be deleted.
DeleteMatch bool `ini:"match-license::delete_match"`
}
+
+func (cml *configMatchLicense) init() (err error) {
+ var logp = `match-license`
+ if cml.Pattern != `` {
+ cml.rePattern, err = regexp.Compile(cml.Pattern)
+ if err != nil {
+ return fmt.Errorf(`%s: pattern %q: %w`, logp, cml.Pattern, err)
+ }
+ }
+ cml.reDeleteLine = make([]*regexp.Regexp, len(cml.DeleteLinePattern))
+ for x, pattern := range cml.DeleteLinePattern {
+ re, err := regexp.Compile(pattern)
+ if err != nil {
+ return fmt.Errorf(`%s: delete_line_pattern %q: %w`, logp, pattern, err)
+ }
+ cml.reDeleteLine[x] = re
+ }
+ return nil
+}