aboutsummaryrefslogtreecommitdiff
path: root/match_license.go
diff options
context:
space:
mode:
Diffstat (limited to 'match_license.go')
-rw-r--r--match_license.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/match_license.go b/match_license.go
new file mode 100644
index 0000000..1d15d7f
--- /dev/null
+++ b/match_license.go
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-3.0-only
+// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info>
+
+package spdxconv
+
+import (
+ "fmt"
+ "regexp"
+)
+
+type matchLicense struct {
+ rePattern *regexp.Regexp
+ reDeleteLine []*regexp.Regexp
+
+ // Pattern to be searched in file.
+ Pattern string `ini:"match-license::pattern"`
+
+ // LicenseIdentifier that replace the default "license_identifier"
+ // 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"`
+}
+
+func (cml *matchLicense) 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
+}