Fix parse error with some Surge/Quantumult X subscriptions

This commit is contained in:
Tindy X
2020-05-01 14:04:06 +08:00
parent 94baa44870
commit 2c793a0f95
3 changed files with 7 additions and 7 deletions

View File

@@ -637,7 +637,7 @@ int regGetMatch(const std::string &src, const std::string &match, size_t group_c
{
std::string* arg = va_arg(vl, std::string*);
if(arg != NULL)
*arg = result[index];
*arg = std::move(result[index]);
index++;
group_count--;
}
@@ -673,13 +673,13 @@ bool regFind(const std::string &src, const std::string &match)
return reg.match(src);
}
std::string regReplace(const std::string &src, const std::string &match, const std::string &rep)
std::string regReplace(const std::string &src, const std::string &match, const std::string &rep, bool global)
{
jp::Regex reg;
reg.setPattern(match).addModifier("gm").addPcre2Option(PCRE2_UTF).compile();
if(!reg)
return src;
return reg.replace(src, rep, "g");
return reg.replace(src, rep, global ? "g" : "");
}
bool regValid(const std::string &reg)
@@ -695,7 +695,7 @@ int regGetMatch(const std::string &src, const std::string &match, size_t group_c
jp::VecNum vec_num;
jp::RegexMatch rm;
size_t count = rm.setRegexObject(&reg).setSubject(src).setNumberedSubstringVector(&vec_num).match();
if(!count || count < group_count - 1)
if(!count)
return -1;
va_list vl;
va_start(vl, group_count);
@@ -704,7 +704,7 @@ int regGetMatch(const std::string &src, const std::string &match, size_t group_c
{
std::string* arg = va_arg(vl, std::string*);
if(arg != NULL)
*arg = vec_num[match_index][index];
*arg = std::move(vec_num[match_index][index]);
index++;
group_count--;
if(vec_num[match_index].size() <= index)

View File

@@ -128,7 +128,7 @@ std::string getFormData(const std::string &raw_data);
void sleep(int interval);
bool regValid(const std::string &reg);
bool regFind(const std::string &src, const std::string &match);
std::string regReplace(const std::string &src, const std::string &match, const std::string &rep);
std::string regReplace(const std::string &src, const std::string &match, const std::string &rep, bool global = true);
bool regMatch(const std::string &src, const std::string &match);
int regGetMatch(const std::string &src, const std::string &match, size_t group_count, ...);
std::string regTrim(const std::string &src);

View File

@@ -1298,7 +1298,7 @@ bool explodeSurge(std::string surge, const std::string &custom_port, std::vector
ini.IncludeSection("Proxy");
ini.AddDirectSaveSection("Proxy");
if(surge.find("[Proxy]") != surge.npos)
surge = regReplace(surge, "^[\\S\\s]*?\\[", "[");
surge = regReplace(surge, "^[\\S\\s]*?\\[", "[", false);
ini.Parse(surge);
if(!ini.SectionExist("Proxy"))