+ fix: RegEx - group replacement backref

This commit is contained in:
RaiKoHoff 2020-02-17 18:18:29 +01:00
parent adff0bc598
commit 8a9087626b
5 changed files with 14 additions and 15 deletions

View File

@ -1 +1 @@
2
1

View File

@ -1 +1 @@
216
217

View File

@ -3,7 +3,7 @@
<assemblyIdentity
name="Notepad3"
processorArchitecture="*"
version="5.20.216.2"
version="5.20.217.1"
type="win32"
/>
<description>Notepad3 RC1</description>

View File

@ -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<size_t>(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 "\\<n>" to deelx's group reference ($<n>)
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');

View File

@ -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