Skip to content

Commit

Permalink
Sync Scintilla regex changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Dec 14, 2023
1 parent 67eba8e commit cfe8457
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 45 deletions.
56 changes: 25 additions & 31 deletions scintilla/src/Document.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3289,8 +3294,7 @@ bool MatchOnLines(const Document *doc, const Regex &regexp, 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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -3411,45 +3413,37 @@ 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;
}
}
*length = lenRet;
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] == '\\') {
Expand Down
5 changes: 2 additions & 3 deletions scintilla/src/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions scintilla/win32/PlatWin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions src/Helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions version.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cfe8457

Please sign in to comment.