From 8a9087626be14e65751f615c280035dde9c69975 Mon Sep 17 00:00:00 2001 From: RaiKoHoff Date: Mon, 17 Feb 2020 18:18:29 +0100 Subject: [PATCH] + fix: RegEx - group replacement backref --- Versions/build.txt | 2 +- Versions/day.txt | 2 +- res/Notepad3.exe.manifest.conf | 2 +- scioniguruma/OnigurumaRegExEngine.cxx | 17 ++++++++--------- src/VersionEx.h | 6 +++--- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Versions/build.txt b/Versions/build.txt index 0cfbf0888..d00491fd7 100644 --- a/Versions/build.txt +++ b/Versions/build.txt @@ -1 +1 @@ -2 +1 diff --git a/Versions/day.txt b/Versions/day.txt index a817176f4..0ddd619ce 100644 --- a/Versions/day.txt +++ b/Versions/day.txt @@ -1 +1 @@ -216 +217 diff --git a/res/Notepad3.exe.manifest.conf b/res/Notepad3.exe.manifest.conf index 6e1459e78..9f1f274ec 100644 --- a/res/Notepad3.exe.manifest.conf +++ b/res/Notepad3.exe.manifest.conf @@ -3,7 +3,7 @@ Notepad3 RC1 diff --git a/scioniguruma/OnigurumaRegExEngine.cxx b/scioniguruma/OnigurumaRegExEngine.cxx index 8c4390e55..511ee148a 100644 --- a/scioniguruma/OnigurumaRegExEngine.cxx +++ b/scioniguruma/OnigurumaRegExEngine.cxx @@ -400,8 +400,6 @@ const char* OnigurumaRegExEngine::SubstituteByPosition(Document* doc, const char m_SubstBuffer.clear(); - //TODO: allow for arbitrary number of groups/regions - for (size_t j = 0; j < rawReplStrg.length(); j++) { bool bReplaced = false; @@ -409,7 +407,9 @@ const char* OnigurumaRegExEngine::SubstituteByPosition(Document* doc, const char { if ((rawReplStrg[j + 1] >= '0') && (rawReplStrg[j + 1] <= '9')) { - int const grpNum = rawReplStrg[j + 1] - '0'; + // group # limit = 99 / TODO: allow for arbitrary number of groups/regions + bool const num2nd = ((rawReplStrg[j + 2] >= '0') && (rawReplStrg[j + 2] <= '9')); + int const grpNum = num2nd ? (rawReplStrg[j + 1] - '0') * 10 + (rawReplStrg[j + 2] - '0') : (rawReplStrg[j + 1] - '0'); if (grpNum < m_Region.num_regs) { auto const rBeg = SciPos(m_Region.beg[grpNum]); @@ -418,13 +418,13 @@ const char* OnigurumaRegExEngine::SubstituteByPosition(Document* doc, const char m_SubstBuffer.append(doc->RangePointer(rBeg, len), static_cast(len)); } bReplaced = true; - ++j; + j += num2nd ? 2 : 1; } else if (rawReplStrg[j] == '$') { size_t k = ((rawReplStrg[j + 1] == '+') && (rawReplStrg[j + 2] == '{')) ? (j + 3) : ((rawReplStrg[j + 1] == '{') ? (j + 2) : 0); if (k > 0) { - // named group replacemment + // named group replacement auto const name_beg = UCharCPtr(&(rawReplStrg[k])); while (rawReplStrg[k] && IsCharAlphaNumericA(rawReplStrg[k])) { ++k; } if (rawReplStrg[k] == '}') @@ -567,6 +567,8 @@ std::string& OnigurumaRegExEngine::convertReplExpr(std::string& replStr) // former behavior convenience: // change "\\" to deelx's group reference ($) tmpStr.push_back('$'); + tmpStr.push_back(ch); + continue; } switch (ch) { // check for escape seq: @@ -574,10 +576,7 @@ std::string& OnigurumaRegExEngine::convertReplExpr(std::string& replStr) tmpStr.push_back('\a'); break; case 'b': - tmpStr.push_back('\b'); - break; - case '\x1B': - tmpStr.push_back('\e'); + tmpStr.push_back('\x1B'); break; case 'f': tmpStr.push_back('\f'); diff --git a/src/VersionEx.h b/src/VersionEx.h index 0510c0026..e28d7bd83 100644 --- a/src/VersionEx.h +++ b/src/VersionEx.h @@ -8,12 +8,12 @@ #define SAPPNAME "Notepad3" #define VERSION_MAJOR 5 #define VERSION_MINOR 20 -#define VERSION_REV 216 -#define VERSION_BUILD 2 +#define VERSION_REV 217 +#define VERSION_BUILD 1 #define SCINTILLA_VER 430 #define ONIGURUMA_REGEX_VER 6.9.4 #define UCHARDET_VER 2018.09.27 #define TINYEXPR_VER 2018.05.11 #define UTHASH_VER 2.1.0 #define VERSION_PATCH RC1 -#define VERSION_COMMIT_ID nebukadn +#define VERSION_COMMIT_ID t7820-rk