summaryrefslogtreecommitdiff
path: root/plugin/plaintext
diff options
context:
space:
mode:
authorLoyalsoldier <[email protected]>2023-10-29 15:37:22 +0800
committerLoyalsoldier <[email protected]>2023-10-29 15:37:22 +0800
commit82bc6a9f3ccf028ff4c01849b4aee33a0c0bd94d (patch)
tree9fe3f104f4f232bb4fb81c92dabeb9e4dc087430 /plugin/plaintext
parentcbbee50da7d45aad95c2700bc7148e0636170c62 (diff)
Feat: skip comment within a line in plaintext formats automatically
content starts with `#` `//` `/*` within a line will be treated as comment and be ignored
Diffstat (limited to 'plugin/plaintext')
-rw-r--r--plugin/plaintext/common_in.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/plugin/plaintext/common_in.go b/plugin/plaintext/common_in.go
index c8bfe367..0c146ae1 100644
--- a/plugin/plaintext/common_in.go
+++ b/plugin/plaintext/common_in.go
@@ -44,6 +44,13 @@ func (t *textIn) scanFileForTextIn(reader io.Reader, entry *lib.Entry) error {
if line == "" {
continue
}
+ line, _, _ = strings.Cut(line, "#")
+ line, _, _ = strings.Cut(line, "//")
+ line, _, _ = strings.Cut(line, "/*")
+ line = strings.TrimSpace(line)
+ if line == "" {
+ continue
+ }
if err := entry.AddPrefix(line); err != nil {
return err
}
@@ -70,7 +77,11 @@ func (t *textIn) scanFileForClashRuleSetIn(reader io.Reader, entry *lib.Entry) e
}
for _, cidrStr := range payload.Payload {
- if err := entry.AddPrefix(strings.TrimSpace(cidrStr)); err != nil {
+ cidrStr = strings.TrimSpace(cidrStr)
+ if cidrStr == "" {
+ continue
+ }
+ if err := entry.AddPrefix(cidrStr); err != nil {
return err
}
}
@@ -88,11 +99,13 @@ func (t *textIn) scanFileForClashClassicalRuleSetInAndSurgeIn(reader io.Reader,
switch {
case strings.HasPrefix(line, "ip-cidr,"), strings.HasPrefix(line, "ip-cidr6,"):
- parts := strings.Split(line, ",")
- if len(parts) > 1 {
- if err := entry.AddPrefix(strings.TrimSpace(parts[1])); err != nil {
- return err
- }
+ _, line, _ = strings.Cut(line, ",")
+ line = strings.TrimSpace(line)
+ if line == "" {
+ continue
+ }
+ if err := entry.AddPrefix(line); err != nil {
+ return err
}
default:
continue