aboutsummaryrefslogtreecommitdiff
path: root/match_copyright.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_copyright.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_copyright.go')
-rw-r--r--match_copyright.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/match_copyright.go b/match_copyright.go
index aa35950..723c63f 100644
--- a/match_copyright.go
+++ b/match_copyright.go
@@ -11,12 +11,18 @@ import (
type matchCopyright struct {
rePattern *regexp.Regexp
+ reDeleteLineBefore []*regexp.Regexp
+ reDeleteLineAfter []*regexp.Regexp
+
// Pattern to be searched in file.
Pattern string `ini:"match-copyright::pattern"`
year string
author string
contact string
+
+ DeleteLineBefore []string `ini:"match-copyright::delete_line_before"`
+ DeleteLineAfter []string `ini:"match-copyright::delete_line_after"`
}
func (cmc *matchCopyright) init() (err error) {
@@ -27,6 +33,22 @@ func (cmc *matchCopyright) init() (err error) {
return fmt.Errorf(`%s: pattern %q: %w`, logp, cmc.Pattern, err)
}
}
+ cmc.reDeleteLineBefore = make([]*regexp.Regexp, len(cmc.DeleteLineBefore))
+ for x, pattern := range cmc.DeleteLineBefore {
+ re, err := regexp.Compile(pattern)
+ if err != nil {
+ return fmt.Errorf(`%s: delete_line_before %q: %w`, logp, pattern, err)
+ }
+ cmc.reDeleteLineBefore[x] = re
+ }
+ cmc.reDeleteLineAfter = make([]*regexp.Regexp, len(cmc.DeleteLineAfter))
+ for x, pattern := range cmc.DeleteLineAfter {
+ re, err := regexp.Compile(pattern)
+ if err != nil {
+ return fmt.Errorf(`%s: delete_line_after %q: %w`, logp, pattern, err)
+ }
+ cmc.reDeleteLineAfter[x] = re
+ }
return nil
}