@@ -2,11 +2,11 @@ package provider
22
33import (
44 "fmt"
5- "strings"
65
76 C "github.com/metacubex/mihomo/constant"
87 P "github.com/metacubex/mihomo/constant/provider"
98 "github.com/metacubex/mihomo/log"
9+ "github.com/metacubex/mihomo/rules/common"
1010)
1111
1212type classicalStrategy struct {
@@ -39,7 +39,7 @@ func (c *classicalStrategy) Reset() {
3939}
4040
4141func (c * classicalStrategy ) Insert (rule string ) {
42- ruleType , rule , params := ruleParse (rule )
42+ ruleType , rule , params := common . ParseRulePayload (rule )
4343 r , err := c .parse (ruleType , rule , "" , params )
4444 if err != nil {
4545 log .Warnln ("parse classical rule error: %s" , err .Error ())
@@ -51,23 +51,6 @@ func (c *classicalStrategy) Insert(rule string) {
5151
5252func (c * classicalStrategy ) FinishInsert () {}
5353
54- func ruleParse (ruleRaw string ) (string , string , []string ) {
55- item := strings .Split (ruleRaw , "," )
56- if len (item ) == 1 {
57- return "" , item [0 ], nil
58- } else if len (item ) == 2 {
59- return item [0 ], item [1 ], nil
60- } else if len (item ) > 2 {
61- if item [0 ] == "NOT" || item [0 ] == "OR" || item [0 ] == "AND" || item [0 ] == "SUB-RULE" || item [0 ] == "DOMAIN-REGEX" || item [0 ] == "PROCESS-NAME-REGEX" || item [0 ] == "PROCESS-PATH-REGEX" {
62- return item [0 ], strings .Join (item [1 :], "," ), nil
63- } else {
64- return item [0 ], item [1 ], item [2 :]
65- }
66- }
67-
68- return "" , "" , nil
69- }
70-
7154func NewClassicalStrategy (parse func (tp , payload , target string , params []string , subRules map [string ][]C.Rule ) (parsed C.Rule , parseErr error )) * classicalStrategy {
7255 return & classicalStrategy {rules : []C.Rule {}, parse : func (tp , payload , target string , params []string ) (parsed C.Rule , parseErr error ) {
7356 switch tp {
0 commit comments