diff options
| author | Loyalsoldier <[email protected]> | 2023-10-29 15:37:22 +0800 |
|---|---|---|
| committer | Loyalsoldier <[email protected]> | 2023-10-29 15:37:22 +0800 |
| commit | 82bc6a9f3ccf028ff4c01849b4aee33a0c0bd94d (patch) | |
| tree | 9fe3f104f4f232bb4fb81c92dabeb9e4dc087430 /lib/lib.go | |
| parent | cbbee50da7d45aad95c2700bc7148e0636170c62 (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 'lib/lib.go')
| -rw-r--r-- | lib/lib.go | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -164,6 +164,14 @@ func (e *Entry) processPrefix(src any) (*netip.Prefix, IPType, error) { } case string: + src, _, _ = strings.Cut(src, "#") + src, _, _ = strings.Cut(src, "//") + src, _, _ = strings.Cut(src, "/*") + src = strings.TrimSpace(src) + if src == "" { + return nil, "", ErrCommentLine + } + _, network, err := net.ParseCIDR(src) switch err { case nil: @@ -256,7 +264,7 @@ func (e *Entry) remove(prefix *netip.Prefix, ipType IPType) error { func (e *Entry) AddPrefix(cidr any) error { prefix, ipType, err := e.processPrefix(cidr) - if err != nil { + if err != nil && err != ErrCommentLine { return err } if err := e.add(prefix, ipType); err != nil { @@ -267,7 +275,7 @@ func (e *Entry) AddPrefix(cidr any) error { func (e *Entry) RemovePrefix(cidr string) error { prefix, ipType, err := e.processPrefix(cidr) - if err != nil { + if err != nil && err != ErrCommentLine { return err } if err := e.remove(prefix, ipType); err != nil { |
