mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-02 01:33:04 +00:00
Fix bad implementation of regex library for include/exclude
Add support for using \uhhhh to match characters with regex. Optimize codes.
This commit is contained in:
3 files changed
+9
-8
No files matched your search
+2
-2
@@ -223,7 +223,7 @@ public:
|
||||
if(do_utf8_to_gbk && is_str_utf8(content))
|
||||
content = UTF8ToACP(content); //do conversion if flag is set
|
||||
|
||||
if(store_isolated_line)
|
||||
if(store_isolated_line && isolated_items_section.size())
|
||||
{
|
||||
curSection = isolated_items_section; //items before any section define will be store in this section
|
||||
//check this section first
|
||||
@@ -384,7 +384,7 @@ public:
|
||||
if(section != cached_section)
|
||||
{
|
||||
cached_section = section;
|
||||
cached_section_content= ini_content.find(section);
|
||||
cached_section_content = ini_content.find(section);
|
||||
}
|
||||
auto &cache = cached_section_content->second;
|
||||
return cache.find(itemName) != cache.end();
|
||||
|
||||
+5
-4
@@ -677,7 +677,7 @@ bool regMatch(const std::string &src, const std::string &match)
|
||||
bool regFind(const std::string &src, const std::string &match)
|
||||
{
|
||||
jp::Regex reg;
|
||||
reg.setPattern(match).addModifier("m").addPcre2Option(PCRE2_UTF).compile();
|
||||
reg.setPattern(match).addModifier("m").addPcre2Option(PCRE2_UTF|PCRE2_ALT_BSUX).compile();
|
||||
if(!reg)
|
||||
return false;
|
||||
return reg.match(src, "g");
|
||||
@@ -686,7 +686,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)
|
||||
{
|
||||
jp::Regex reg;
|
||||
reg.setPattern(match).addModifier("m").addPcre2Option(PCRE2_UTF|PCRE2_MULTILINE).compile();
|
||||
reg.setPattern(match).addModifier("m").addPcre2Option(PCRE2_UTF|PCRE2_MULTILINE|PCRE2_ALT_BSUX).compile();
|
||||
if(!reg)
|
||||
return src;
|
||||
return reg.replace(src, rep, global ? "gx" : "x");
|
||||
@@ -694,14 +694,15 @@ std::string regReplace(const std::string &src, const std::string &match, const s
|
||||
|
||||
bool regValid(const std::string ®)
|
||||
{
|
||||
jp::Regex r(reg);
|
||||
jp::Regex r;
|
||||
r.setPattern(reg).addPcre2Option(PCRE2_UTF|PCRE2_ALT_BSUX).compile();
|
||||
return !!r;
|
||||
}
|
||||
|
||||
int regGetMatch(const std::string &src, const std::string &match, size_t group_count, ...)
|
||||
{
|
||||
jp::Regex reg;
|
||||
reg.setPattern(match).addModifier("m").addPcre2Option(PCRE2_UTF).compile();
|
||||
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();
|
||||
|
||||
@@ -2002,7 +2002,7 @@ void filterNodes(std::vector<nodeInfo> &nodes, string_array &exclude_remarks, st
|
||||
|
||||
for(i = 0; i < exclude_remarks.size(); i++)
|
||||
{
|
||||
std::unique_ptr<pcre2_code, decltype(&pcre2_code_free)> pattern(pcre2_compile(reinterpret_cast<const unsigned char*>(exclude_remarks[i].c_str()), PCRE2_ZERO_TERMINATED | PCRE2_MULTILINE, 0, &errornumber, &erroroffset, NULL), &pcre2_code_free);
|
||||
std::unique_ptr<pcre2_code, decltype(&pcre2_code_free)> pattern(pcre2_compile(reinterpret_cast<const unsigned char*>(exclude_remarks[i].c_str()), exclude_remarks[i].size(), PCRE2_UTF | PCRE2_MULTILINE | PCRE2_ALT_BSUX, &errornumber, &erroroffset, NULL), &pcre2_code_free);
|
||||
if(!pattern)
|
||||
return;
|
||||
exclude_patterns.emplace_back(std::move(pattern));
|
||||
@@ -2012,7 +2012,7 @@ void filterNodes(std::vector<nodeInfo> &nodes, string_array &exclude_remarks, st
|
||||
}
|
||||
for(i = 0; i < include_remarks.size(); i++)
|
||||
{
|
||||
std::unique_ptr<pcre2_code, decltype(&pcre2_code_free)> pattern(pcre2_compile(reinterpret_cast<const unsigned char*>(include_remarks[i].c_str()), PCRE2_ZERO_TERMINATED | PCRE2_MULTILINE, 0, &errornumber, &erroroffset, NULL), &pcre2_code_free);
|
||||
std::unique_ptr<pcre2_code, decltype(&pcre2_code_free)> pattern(pcre2_compile(reinterpret_cast<const unsigned char*>(include_remarks[i].c_str()), include_remarks[i].size(), PCRE2_UTF | PCRE2_MULTILINE | PCRE2_ALT_BSUX, &errornumber, &erroroffset, NULL), &pcre2_code_free);
|
||||
if(!pattern)
|
||||
return;
|
||||
include_patterns.emplace_back(std::move(pattern));
|
||||
|
||||
Reference in new issue
Block a user