Enhancements

Fix when subscription download timeout before complete, the parser will still try to parse downloaded content.
Change default regex library to PCRE2.
Change Quantumult X "url-test" equivalent to "available".
Optimize codes.
Update build scripts.
This commit is contained in:
Tindy X committed 2020-02-02 23:18:20 +08:00
1 parent fd5a74ec93
commit 00976c9eeb
12 files changed
+164 -133

No files matched your search

+48 -54
View File
@@ -11,7 +11,8 @@
#ifdef USE_STD_REGEX
#include <regex>
#else
#include <pcrecpp.h>
#include <jpcre2.hpp>
typedef jpcre2::select<char> jp;
#endif // USE_STD_REGEX
#include <rapidjson/document.h>
@@ -489,7 +490,7 @@ bool regValid(std::string &reg)
{
try
{
std::regex r(reg);
std::regex r(reg, std::regex::ECMAScript);
return true;
}
catch (std::regex_error &e)
@@ -502,7 +503,13 @@ bool regFind(std::string src, std::string target)
{
try
{
std::regex reg(target);
std::regex::flag_type flags = std::regex::extended | std::regex::ECMAScript;
if(target.find("(?i)") == 0)
{
target.erase(0, 4);
flags |= std::regex::icase;
}
std::regex reg(target, flags);
return regex_search(src, reg);
}
catch (std::regex_error &e)
@@ -516,7 +523,13 @@ std::string regReplace(std::string src, std::string match, std::string rep)
std::string result = "";
try
{
std::regex reg(match);
std::regex::flag_type flags = std::regex::extended | std::regex::ECMAScript;
if(match.find("(?i)") == 0)
{
match.erase(0, 4);
flags |= std::regex::icase;
}
std::regex reg(match, flags);
regex_replace(back_inserter(result), src.begin(), src.end(), reg, rep);
}
catch (std::regex_error &e)
@@ -530,7 +543,13 @@ bool regMatch(std::string src, std::string match)
{
try
{
std::regex reg(match);
std::regex::flag_type flags = std::regex::extended | std::regex::ECMAScript;
if(match.find("(?i)") == 0)
{
match.erase(0, 4);
flags |= std::regex::icase;
}
std::regex reg(match, flags);
return regex_match(src, reg);
}
catch (std::regex_error &e)
@@ -541,62 +560,37 @@ bool regMatch(std::string src, std::string match)
#else
bool regValid(std::string &reg)
bool regMatch(std::string src, std::string target, bool partial)
{
try
{
pcrecpp::RE r(reg);
return true;
}
catch (std::exception &e)
{
jp::Regex reg;
reg.setPattern(target).addModifier("gm").compile();
if(!reg)
return false;
}
return reg.replace(src, "$0") == src;
}
bool regFind(std::string src, std::string target)
{
try
{
pcrecpp::RE reg(target);
return reg.PartialMatch(src);
}
catch (std::exception &e)
{
jp::Regex reg;
reg.setPattern(target).addModifier("gm").compile();
if(!reg)
return false;
}
return reg.match(src);
}
std::string regReplace(std::string src, std::string match, std::string rep)
std::string regReplace(std::string src, std::string target, std::string rep)
{
std::string result = src;
try
{
if(rep.find("$") != rep.npos)
rep = replace_all_distinct(rep, "$", "\\");
pcrecpp::RE reg(match);
if(reg.GlobalReplace(rep, &result))
return result;
else
return src;
}
catch (std::exception &e)
{
jp::Regex reg;
reg.setPattern(target).addModifier("gm").compile();
if(!reg)
return src;
}
return reg.replace(src, rep);
}
bool regMatch(std::string src, std::string match)
bool regValid(std::string &target)
{
try
{
pcrecpp::RE reg(match);
return reg.FullMatch(src);
}
catch (std::exception &e)
{
return false;
}
jp::Regex reg(target);
return !!reg;
}
#endif // USE_STD_REGEX
@@ -640,19 +634,19 @@ std::string getMD5(std::string data)
unsigned int i = 0;
unsigned char digest[16] = {};
#ifdef USE_MBEDTLS
#ifdef USE_MBEDTLS
mbedtls_md5_context ctx;
mbedtls_md5_init(&ctx);
mbedtls_md5_update(&ctx, data.data(), data.size());
mbedtls_md5_finish(&ctx, (unsigned char *)&digest);
#else
#else
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx, data.data(), data.size());
MD5_Final((unsigned char *)&digest, &ctx);
#endif // USE_MBEDTLS
#endif // USE_MBEDTLS
char tmp[3] = {};
for(i = 0; i < 16; i++)
@@ -673,11 +667,11 @@ std::string fileGet(std::string path, bool binary, bool scope_limit)
if(scope_limit)
{
#ifdef _WIN32
if(path.find(":/") != path.npos || path.find("..") != path.npos)
return std::string();
if(path.find(":/") != path.npos || path.find("..") != path.npos)
return std::string();
#else
if(path.find("/") == 0 || path.find("..") != path.npos)
return std::string();
if(path.find("/") == 0 || path.find("..") != path.npos)
return std::string();
#endif // _WIN32
}