mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-05 03:02:06 +00:00
Add support for WireGuard nodes in Clash, Surge and Loon configs
This commit is contained in:
7 files changed
+255
-20
No files matched your search
+37
-15
@@ -10,6 +10,8 @@
|
||||
using jp = jpcre2::select<char>;
|
||||
//#endif // USE_STD_REGEX
|
||||
|
||||
#include "regexp.h"
|
||||
|
||||
/*
|
||||
#ifdef USE_STD_REGEX
|
||||
bool regValid(const std::string ®)
|
||||
@@ -164,34 +166,54 @@ bool regValid(const std::string ®)
|
||||
}
|
||||
|
||||
int regGetMatch(const std::string &src, const std::string &match, size_t group_count, ...)
|
||||
{
|
||||
auto result = regGetAllMatch(src, match, false);
|
||||
if(result.empty())
|
||||
return -1;
|
||||
va_list vl;
|
||||
va_start(vl, group_count);
|
||||
size_t index = 0;
|
||||
while(group_count)
|
||||
{
|
||||
std::string* arg = va_arg(vl, std::string*);
|
||||
if(arg != nullptr)
|
||||
*arg = std::move(result[index]);
|
||||
index++;
|
||||
group_count--;
|
||||
if(result.size() <= index)
|
||||
break;
|
||||
}
|
||||
va_end(vl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<std::string> regGetAllMatch(const std::string &src, const std::string &match, bool group_only)
|
||||
{
|
||||
jp::Regex reg;
|
||||
reg.setPattern(match).addModifier("m").addPcre2Option(PCRE2_UTF|PCRE2_ALT_BSUX).compile();
|
||||
jp::VecNum vec_num;
|
||||
jp::RegexMatch rm;
|
||||
size_t count = rm.setRegexObject(®).setSubject(src).setNumberedSubstringVector(&vec_num).setModifier("g").match();
|
||||
std::vector<std::string> result;
|
||||
if(!count)
|
||||
return -1;
|
||||
va_list vl;
|
||||
va_start(vl, group_count);
|
||||
size_t index = 0, match_index = 0;
|
||||
while(group_count)
|
||||
return result;
|
||||
size_t begin = 0;
|
||||
if(group_only)
|
||||
begin = 1;
|
||||
size_t index = begin, match_index = 0;
|
||||
while(true)
|
||||
{
|
||||
std::string* arg = va_arg(vl, std::string*);
|
||||
if(arg != NULL)
|
||||
*arg = std::move(vec_num[match_index][index]);
|
||||
index++;
|
||||
group_count--;
|
||||
if(vec_num.size() <= match_index)
|
||||
break;
|
||||
if(vec_num[match_index].size() <= index)
|
||||
{
|
||||
match_index++;
|
||||
index = 0;
|
||||
index = begin;
|
||||
}
|
||||
if(vec_num.size() <= match_index)
|
||||
break;
|
||||
result.push_back(std::move(vec_num[match_index][index]));
|
||||
index++;
|
||||
}
|
||||
va_end(vl);
|
||||
return 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
//#endif // USE_STD_REGEX
|
||||
|
||||
@@ -8,6 +8,7 @@ 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, bool global = true, bool multiline = 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::vector<std::string> regGetAllMatch(const std::string &src, const std::string &match, bool group_only = false);
|
||||
std::string regTrim(const std::string &src);
|
||||
|
||||
#endif // REGEXP_H_INCLUDED
|
||||
@@ -354,7 +354,7 @@ bool isStrUTF8(const std::string &data)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string randomStr(const int len)
|
||||
std::string randomStr(int len)
|
||||
{
|
||||
std::string retData;
|
||||
srand(time(NULL));
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ std::string trim(const std::string& str, bool before = true, bool after = true);
|
||||
std::string trimQuote(const std::string &str, bool before = true, bool after = true);
|
||||
void trimSelfOf(std::string &str, char target, bool before = true, bool after = true);
|
||||
std::string trimWhitespace(const std::string &str, bool before = false, bool after = true);
|
||||
std::string randomStr(const int len);
|
||||
std::string randomStr(int len);
|
||||
bool isStrUTF8(const std::string &data);
|
||||
|
||||
void removeUTF8BOM(std::string &data);
|
||||
|
||||
Reference in new issue
Block a user