From cfe84578d0914627b78267779c3d54508170ec91 Mon Sep 17 00:00:00 2001 From: zufuliu Date: Thu, 14 Dec 2023 19:27:00 +0800 Subject: [PATCH] Sync Scintilla regex changes. --- scintilla/src/Document.cxx | 56 +++++++++++++++++-------------------- scintilla/src/Document.h | 5 ++-- scintilla/win32/PlatWin.cxx | 8 ++---- src/Helpers.c | 7 +++-- version.txt | 6 ++-- 5 files changed, 37 insertions(+), 45 deletions(-) diff --git a/scintilla/src/Document.cxx b/scintilla/src/Document.cxx index 33b7abf1fd..b9bde4b908 100644 --- a/scintilla/src/Document.cxx +++ b/scintilla/src/Document.cxx @@ -2954,14 +2954,12 @@ class BuiltinRegex final : public RegexSearchBase { public: explicit BuiltinRegex(const CharClassify *charClassTable) : search(charClassTable) {} - Sci::Position FindText(const Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *pattern, - FindOption flags, Sci::Position *length) override; + Sci::Position FindText(const Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *pattern, FindOption flags, Sci::Position *length) override; - const char *SubstituteByPosition(Document *doc, const char *text, Sci::Position *length) override; + const char *SubstituteByPosition(const Document *doc, const char *text, Sci::Position *length) override; #if defined(BOOST_REGEX_STANDALONE) || !defined(NO_CXX11_REGEX) - Sci::Position CxxRegexFindText(const Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *pattern, - FindOption flags, Sci::Position *length); + Sci::Position CxxRegexFindText(const Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *pattern, FindOption flags, Sci::Position *length); #endif private: @@ -3218,7 +3216,14 @@ class UTF8Iterator { std::regex_constants::match_flag_type MatchFlags(const Document *doc, Sci::Position startPos, Sci::Position endPos, Sci::Position lineStartPos, Sci::Position lineEndPos) noexcept { std::regex_constants::match_flag_type flagsMatch = std::regex_constants::match_default; if (startPos != lineStartPos) { +#if defined(_LIBCPP_VERSION) + flagsMatch |= std::regex_constants::match_not_bol; + if (!doc->IsWordStartAt(startPos)) { + flagsMatch |= std::regex_constants::match_not_bow; + } +#else flagsMatch |= std::regex_constants::match_prev_avail; +#endif } if (endPos != lineEndPos) { flagsMatch |= std::regex_constants::match_not_eol; @@ -3289,8 +3294,7 @@ bool MatchOnLines(const Document *doc, const Regex ®exp, const RESearchRange return matched; } -Sci::Position BuiltinRegex::CxxRegexFindText(const Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *pattern, - FindOption flags, Sci::Position *length) { +Sci::Position BuiltinRegex::CxxRegexFindText(const Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *pattern, FindOption flags, Sci::Position *length) { const RESearchRange resr(doc, minPos, maxPos); try { //const ElapsedPeriod ep; @@ -3352,9 +3356,7 @@ Sci::Position BuiltinRegex::CxxRegexFindText(const Document *doc, Sci::Position #endif // BOOST_REGEX_STANDALONE || !NO_CXX11_REGEX -Sci::Position BuiltinRegex::FindText(const Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *pattern, - FindOption flags, Sci::Position *length) { - +Sci::Position BuiltinRegex::FindText(const Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *pattern, FindOption flags, Sci::Position *length) { #if defined(BOOST_REGEX_STANDALONE) || !defined(NO_CXX11_REGEX) if (FlagSet(flags, FindOption::Cxx11RegEx)) { return CxxRegexFindText(doc, minPos, maxPos, pattern, flags, length); @@ -3411,37 +3413,29 @@ Sci::Position BuiltinRegex::FindText(const Document *doc, Sci::Position minPos, search.SetLineRange(lineStartPos, lineEndPos); int success = search.Execute(di, startOfLine, endOfLine); if (success) { - pos = search.bopat[0]; - lenRet = search.eopat[0] - pos; + Sci::Position endPos = search.eopat[0]; // There can be only one start of a line, so no need to look for last match in line if ((resr.increment < 0) && !searchforLineStart) { // Check for the last match on this line. - Sci::Position endPos = search.eopat[0]; - RESearch::MatchPositions bopat{}; - RESearch::MatchPositions eopat{}; while (success && (endPos < endOfLine)) { - bopat = search.bopat; - eopat = search.eopat; - if (lenRet == 0) { + const RESearch::MatchPositions bopat = search.bopat; + const RESearch::MatchPositions eopat = search.eopat; + pos = endPos; + if (pos == bopat[0]) { // empty match - endPos = doc->NextPosition(endPos, 1); + pos = doc->NextPosition(pos, 1); } - success = search.Execute(di, endPos, endOfLine); + success = search.Execute(di, pos, endOfLine); if (success) { endPos = search.eopat[0]; - if (endPos <= minPos) { - pos = search.bopat[0]; - lenRet = endPos - pos; - } else { - success = 0; - } + } else { + search.bopat = bopat; + search.eopat = eopat; } } - if (!success) { - search.bopat = bopat; - search.eopat = eopat; - } } + pos = search.bopat[0]; + lenRet = endPos - pos; break; } } @@ -3449,7 +3443,7 @@ Sci::Position BuiltinRegex::FindText(const Document *doc, Sci::Position minPos, return pos; } -const char *BuiltinRegex::SubstituteByPosition(Document *doc, const char *text, Sci::Position *length) { +const char *BuiltinRegex::SubstituteByPosition(const Document *doc, const char *text, Sci::Position *length) { substituted.clear(); for (Sci::Position j = 0; j < *length; j++) { if (text[j] == '\\') { diff --git a/scintilla/src/Document.h b/scintilla/src/Document.h index a0916b4cd1..b47c05bc20 100644 --- a/scintilla/src/Document.h +++ b/scintilla/src/Document.h @@ -98,11 +98,10 @@ class RegexSearchBase { public: virtual ~RegexSearchBase() = default; - virtual Sci::Position FindText(const Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *pattern, - Scintilla::FindOption flags, Sci::Position *length) = 0; + virtual Sci::Position FindText(const Document *doc, Sci::Position minPos, Sci::Position maxPos, const char *pattern, Scintilla::FindOption flags, Sci::Position *length) = 0; ///@return String with the substitutions, must remain valid until the next call or destruction - virtual const char *SubstituteByPosition(Document *doc, const char *text, Sci::Position *length) = 0; + virtual const char *SubstituteByPosition(const Document *doc, const char *text, Sci::Position *length) = 0; }; /// Factory function for RegexSearchBase diff --git a/scintilla/win32/PlatWin.cxx b/scintilla/win32/PlatWin.cxx index 73e4e0f799..4db21a5394 100644 --- a/scintilla/win32/PlatWin.cxx +++ b/scintilla/win32/PlatWin.cxx @@ -905,10 +905,9 @@ DIBSection::DIBSection(HDC hdc, SIZE size_) noexcept { size = size_; // -size.y makes bitmap start from top - const BITMAPINFO bpih = { {sizeof(BITMAPINFOHEADER), size.cx, -size.cy, 1, 32, BI_RGB, 0, 0, 0, 0, 0}, - {{0, 0, 0, 0}} }; + const BITMAPINFO bpih = { {sizeof(BITMAPINFOHEADER), size.cx, -size.cy, 1, 32, BI_RGB, 0, 0, 0, 0, 0}, {{0, 0, 0, 0}} }; void *image = nullptr; - hbmMem = CreateDIBSection(hMemDC, &bpih, DIB_RGB_COLORS, &image, {}, 0); + hbmMem = CreateDIBSection(hMemDC, &bpih, DIB_RGB_COLORS, &image, nullptr, 0); if (!hbmMem || !image) { return; } @@ -3850,8 +3849,7 @@ LRESULT ListBoxX::WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam ::InflateRect(&client, -ListBoxXFakeFrameSize + 1, -ListBoxXFakeFrameSize + 1); HDC hMemDC = CreateCompatibleDC(hDC); - const BITMAPINFO bpih = { {sizeof(BITMAPINFOHEADER), width, height, 1, 32, BI_RGB, 0, 0, 0, 0, 0}, - {{0, 0, 0, 0}} }; + const BITMAPINFO bpih = { {sizeof(BITMAPINFOHEADER), width, -height, 1, 32, BI_RGB, 0, 0, 0, 0, 0}, {{0, 0, 0, 0}} }; HBITMAP hbmMem = CreateDIBSection(hMemDC, &bpih, DIB_RGB_COLORS, nullptr, nullptr, 0); if (hbmMem) { diff --git a/src/Helpers.c b/src/Helpers.c index 9a35147b7f..cd7b04738f 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -2584,9 +2584,10 @@ HBITMAP BitmapCache_Get(BitmapCache *cache, LPCWSTR path) { if (hbmp == NULL) { HDC hDC = GetDC(NULL); HDC bitmapDC = CreateCompatibleDC(hDC); - RECT rect = { 0, 0, 0, 0 }; - ImageList_GetIconSize(imageList, (int *)(&rect.right), (int *)(&rect.bottom)); - const BITMAPINFO bmi = { {sizeof(BITMAPINFOHEADER), rect.right, rect.bottom, 1, 32, BI_RGB, 0, 0, 0, 0, 0}, {{ 0, 0, 0, 0 }} }; + int width = 0; + int height = 0; + ImageList_GetIconSize(imageList, &width, &height); + const BITMAPINFO bmi = { {sizeof(BITMAPINFOHEADER), width, -height, 1, 32, BI_RGB, 0, 0, 0, 0, 0}, {{ 0, 0, 0, 0 }} }; hbmp = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, NULL, NULL, 0); HBITMAP oldBitmap = (HBITMAP)SelectObject(bitmapDC, hbmp); ImageList_Draw(imageList, iIcon, bitmapDC, 0, 0, ILD_TRANSPARENT); diff --git a/version.txt b/version.txt index 8326e56351..bfaa58a711 100644 --- a/version.txt +++ b/version.txt @@ -5,17 +5,17 @@ git clone https://github.com/XhmikosR/notepad2-mod.git Scintilla (upstream) hg clone http://hg.code.sf.net/p/scintilla/code scintilla 5.4.0 -2023-12-09 9455:dad186dd18a5 +2023-12-14 9460:1590ab9ae151 Lexilla (upstream) git clone https://github.com/ScintillaOrg/lexilla.git 5.2.9 -2023-12-04 3f1121ed1af3dfeef75e751ec28af7200c5310b6 +2023-12-14 1179da2c996a1a961223c011c013ffcb1fb65bf0 SciTE (upstream) hg clone http://hg.code.sf.net/p/scintilla/scite 5.4.0 -2023-12-04 6230:43295c7effc2 +2023-12-14 6232:55255a7fe856 init submodule: git submodule init