1010
1111// / rule type lists
1212#define basic_types " DOMAIN" , " DOMAIN-SUFFIX" , " DOMAIN-KEYWORD" , " IP-CIDR" , " SRC-IP-CIDR" , " GEOIP" , " MATCH" , " FINAL"
13- string_array ClashRuleTypes = {basic_types, " IP-CIDR6" , " SRC-PORT" , " DST-PORT" , " PROCESS-NAME" };
13+ string_array ClashRuleTypes = {basic_types, " IP-CIDR6" , " SRC-PORT" , " DST-PORT" , " PROCESS-NAME" , " DOMAIN-REGEX " , " DOMAIN-WILDCARD " , " GEOSITE " , " IP-SUFFIX " , " IP-ASN " , " SRC-GEOIP " , " SRC-IP-ASN " , " SRC-IP-SUFFIX " , " IN-PORT " , " IN-TYPE " , " IN-USER " , " IN-NAME " , " PROCESS-PATH-REGEX " , " PROCESS-PATH " , " PROCESS-NAME-REGEX " , " PROCESS-NAME-WILDCARD " , " PROCESS-PATH-WILDCARD " , " UID " , " NETWORK " , " DSCP " , " SUB-RULE " , " RULE-SET " , " AND " , " OR " , " NOT " };
1414string_array Surge2RuleTypes = {basic_types, " IP-CIDR6" , " USER-AGENT" , " URL-REGEX" , " PROCESS-NAME" , " IN-PORT" , " DEST-PORT" , " SRC-IP" };
1515string_array SurgeRuleTypes = {basic_types, " IP-CIDR6" , " USER-AGENT" , " URL-REGEX" , " AND" , " OR" , " NOT" , " PROCESS-NAME" , " IN-PORT" , " DEST-PORT" , " SRC-IP" };
1616string_array QuanXRuleTypes = {basic_types, " USER-AGENT" , " HOST" , " HOST-SUFFIX" , " HOST-KEYWORD" };
@@ -133,6 +133,7 @@ void rulesetToClash(YAML::Node &base_rule, std::vector<RulesetContent> &ruleset_
133133
134134 if (!overwrite_original_rules && base_rule[field_name].IsDefined ())
135135 rules = base_rule[field_name];
136+ // const std::string rule_match_regex = "^(.*?,.*?)(,.*)(,.*)$";
136137
137138 std::vector<std::string_view> temp (4 );
138139 for (RulesetContent &x : ruleset_content_array)
@@ -152,6 +153,8 @@ void rulesetToClash(YAML::Node &base_rule, std::vector<RulesetContent> &ruleset_
152153 if (startsWith (strLine, " FINAL" ))
153154 strLine.replace (0 , 5 , " MATCH" );
154155 strLine = transformRuleToCommon (temp, strLine, rule_group);
156+ // if(!startsWith(strLine, "AND") && !startsWith(strLine, "OR") && !startsWith(strLine, "NOT") && count_least(strLine, ',', 3))
157+ // strLine = regReplace(strLine, rule_match_regex, "$1$3$2");
155158 allRules.emplace_back (strLine);
156159 total_rules++;
157160 continue ;
@@ -178,6 +181,8 @@ void rulesetToClash(YAML::Node &base_rule, std::vector<RulesetContent> &ruleset_
178181 strLine = trimWhitespace (strLine);
179182 }
180183 strLine = transformRuleToCommon (temp, strLine, rule_group);
184+ // if(!startsWith(strLine, "AND") && !startsWith(strLine, "OR") && !startsWith(strLine, "NOT") && count_least(strLine, ',', 3))
185+ // strLine = regReplace(strLine, rule_match_regex, "$1$3$2");
181186 allRules.emplace_back (strLine);
182187 }
183188 }
@@ -205,6 +210,8 @@ std::string rulesetToClashStr(YAML::Node &base_rule, std::vector<RulesetContent>
205210 }
206211 base_rule.remove (field_name);
207212
213+ // const std::string rule_match_regex = "^(.*?,.*?)(,.*)(,.*)$";
214+
208215 string_view_array temp (4 );
209216 for (RulesetContent &x : ruleset_content_array)
210217 {
@@ -223,6 +230,8 @@ std::string rulesetToClashStr(YAML::Node &base_rule, std::vector<RulesetContent>
223230 if (startsWith (strLine, " FINAL" ))
224231 strLine.replace (0 , 5 , " MATCH" );
225232 strLine = transformRuleToCommon (temp, strLine, rule_group);
233+ // if(!startsWith(strLine, "AND") && !startsWith(strLine, "OR") && !startsWith(strLine, "NOT") && count_least(strLine, ',', 3))
234+ // strLine = regReplace(strLine, rule_match_regex, "$1$3$2");
226235 output_content += " - " + strLine + " \n " ;
227236 total_rules++;
228237 continue ;
@@ -248,8 +257,26 @@ std::string rulesetToClashStr(YAML::Node &base_rule, std::vector<RulesetContent>
248257 strLine.erase (strLine.find (" //" ));
249258 strLine = trimWhitespace (strLine);
250259 }
251- strLine = transformRuleToCommon (temp, strLine, rule_group);
252- output_content += " - " + strLine + " \n " ;
260+ // AND & OR & NOT
261+ if (startsWith (strLine, " AND" ) || startsWith (strLine, " OR" ) || startsWith (strLine, " NOT" ))
262+ {
263+ output_content += " - " + strLine + " ," + rule_group + " \n " ;
264+ }
265+ // SUB-RULE & RULE-SET
266+ else if (startsWith (strLine, " SUB-RULE" ) || startsWith (strLine, " RULE-SET" ))
267+ {
268+ output_content += " - " + strLine + " \n " ;
269+ }
270+ else
271+ // OTHER
272+ {
273+ strLine = transformRuleToCommon (temp, strLine, rule_group);
274+ output_content += " - " + strLine + " \n " ;
275+ }
276+ // strLine = transformRuleToCommon(temp, strLine, rule_group);
277+ // if(!startsWith(strLine, "AND") && !startsWith(strLine, "OR") && !startsWith(strLine, "NOT") && count_least(strLine, ',', 3))
278+ // strLine = regReplace(strLine, rule_match_regex, "$1$3$2");
279+ // output_content += " - " + strLine + "\n";
253280 total_rules++;
254281 }
255282 }
0 commit comments