aboutsummaryrefslogtreecommitdiff
path: root/match_license.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-13 01:44:23 +0700
committerShulhan <ms@kilabit.info>2026-01-13 01:45:18 +0700
commit434139fe3918fdb56704558301ad9275f1da06ad (patch)
tree76f4a942f9f47398ab153a8319b2c4d2e442d167 /match_license.go
parente16e2a4ec74443aa8f4c21a73ee837cb72ed46fb (diff)
downloadspdxconv-434139fe3918fdb56704558301ad9275f1da06ad.tar.xz
all: split the delete_line_pattern into before and after
While at it, also add configuration for delete line before and after for match-copyright section.
Diffstat (limited to 'match_license.go')
-rw-r--r--match_license.go36
1 files changed, 25 insertions, 11 deletions
diff --git a/match_license.go b/match_license.go
index 1d15d7f..a9abb99 100644
--- a/match_license.go
+++ b/match_license.go
@@ -9,8 +9,10 @@ import (
)
type matchLicense struct {
- rePattern *regexp.Regexp
- reDeleteLine []*regexp.Regexp
+ rePattern *regexp.Regexp
+
+ reDeleteLineBefore []*regexp.Regexp
+ reDeleteLineAfter []*regexp.Regexp
// Pattern to be searched in file.
Pattern string `ini:"match-license::pattern"`
@@ -19,11 +21,15 @@ type matchLicense struct {
// value if Pattern match.
LicenseIdentifier string `ini:"match-license::license_identifier"`
- // DeleteLinePattern zero or more pattern that will be search after
- // Pattern match line.
- // A line that match with this pattern will be deleted.
- // An empty line stop the search.
- DeleteLinePattern []string `ini:"match-license::delete_line_pattern"`
+ // DeleteLineBefore zero or more pattern that will be search before
+ // the matched Pattern line, and deleted if its match.
+ // Each pattern is executed in order until it does not match.
+ DeleteLineBefore []string `ini:"match-license::delete_line_before"`
+
+ // DeleteLineAfter zero or more pattern that will be search after
+ // the matched Pattern line, and deleted if its match.
+ // Each pattern is executed in order until it does not match.
+ DeleteLineAfter []string `ini:"match-license::delete_line_after"`
}
func (cml *matchLicense) init() (err error) {
@@ -34,13 +40,21 @@ func (cml *matchLicense) init() (err error) {
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 {
+ cml.reDeleteLineBefore = make([]*regexp.Regexp, len(cml.DeleteLineBefore))
+ for x, pattern := range cml.DeleteLineBefore {
+ re, err := regexp.Compile(pattern)
+ if err != nil {
+ return fmt.Errorf(`%s: delete_line_before %q: %w`, logp, pattern, err)
+ }
+ cml.reDeleteLineBefore[x] = re
+ }
+ cml.reDeleteLineAfter = make([]*regexp.Regexp, len(cml.DeleteLineAfter))
+ for x, pattern := range cml.DeleteLineAfter {
re, err := regexp.Compile(pattern)
if err != nil {
- return fmt.Errorf(`%s: delete_line_pattern %q: %w`, logp, pattern, err)
+ return fmt.Errorf(`%s: delete_line_after %q: %w`, logp, pattern, err)
}
- cml.reDeleteLine[x] = re
+ cml.reDeleteLineAfter[x] = re
}
return nil
}