Skip to content

Commit

Permalink
Add definition for find and replace default regex flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Oct 13, 2023
1 parent 1bfaf31 commit 2c61b23
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions scintilla/include/Scintilla.iface
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ set void SetPrintColourMode=2148(PrintOption mode,)
# Returns the print colour mode.
get PrintOption GetPrintColourMode=2149(,)

# https://learn.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-findreplacea
enu FindOption=SCFIND_
val SCFIND_NONE=0x0
val SCFIND_WHOLEWORD=0x2
Expand Down
5 changes: 2 additions & 3 deletions scintilla/src/RESearch.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ const char *RESearch::DoCompile(const char *pattern, Sci::Position length, bool
*/
int RESearch::Execute(const CharacterIndexer &ci, Sci::Position lp, Sci::Position endp) {
Sci::Position ep = NOTFOUND;
const char *ap = nfa;
const char * const ap = nfa;

failure = 0;

Expand Down Expand Up @@ -804,8 +804,7 @@ int RESearch::Execute(const CharacterIndexer &ci, Sci::Position lp, Sci::Positio
if (ep == NOTFOUND) {
/* similar to EOL, match EOW at line end */
if (endp == lineEndPos && *ap == EOW) {
++ap;
if ((*ap == END || ((*ap == EOL && ap[1] == END))) && iswordc(ci.CharAt(lp - 1))) {
if ((ap[1] == END || ((ap[1] == EOL && ap[2] == END))) && iswordc(ci.CharAt(lp - 1))) {
lp = endp;
ep = lp;
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/Edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5033,7 +5033,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
}

if (IsButtonChecked(hwnd, IDC_FINDREGEXP)) {
lpefr->fuFlags |= SCFIND_REGEXP | SCFIND_POSIX;
lpefr->fuFlags |= NP2_RegexDefaultFlags;
}

lpefr->bTransformBS = IsButtonChecked(hwnd, IDC_FINDTRANSFORMBS);
Expand Down Expand Up @@ -7051,7 +7051,7 @@ char* EditGetStringAroundCaret(LPCSTR delimiters) {
}

struct Sci_TextToFindFull ft = { { iCurrentPos, 0 }, delimiters, { 0, 0 } };
const int findFlag = SCFIND_REGEXP | SCFIND_POSIX;
const int findFlag = NP2_RegexDefaultFlags;

// forward
if (iCurrentPos < iLineEnd) {
Expand Down Expand Up @@ -7339,13 +7339,13 @@ void EditOpenSelection(OpenSelectionType type) {
strcat(lpstrText, "[\'\"]?");

struct Sci_TextToFindFull ft = { { 0, SciCall_GetLength() }, mszSelection, { 0, 0 } };
Sci_Position iPos = SciCall_FindTextFull(SCFIND_REGEXP | SCFIND_POSIX, &ft);
Sci_Position iPos = SciCall_FindTextFull(NP2_RegexDefaultFlags, &ft);
if (iPos < 0) {
lpstrText = mszSelection + 2;
lpstrText[0] = 'i';
lpstrText[1] = 'd';
ft.lpstrText = lpstrText;
iPos = SciCall_FindTextFull(SCFIND_REGEXP | SCFIND_POSIX, &ft);
iPos = SciCall_FindTextFull(NP2_RegexDefaultFlags, &ft);
}
NP2HeapFree(mszSelection);
if (iPos >= 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/Edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#define NP2_FIND_REPLACE_LIMIT 2048
#define NP2_LONG_LINE_LIMIT 4096

//#define NP2_RegexDefaultFlags (SCFIND_REGEXP | SCFIND_CXX11REGEX) // use std::regex
#define NP2_RegexDefaultFlags (SCFIND_REGEXP | SCFIND_POSIX) // use builtin regex
#define NP2_InvalidSearchFlags (-1)
#define NP2_MarkAllMultiline 0x00001000
#define NP2_MarkAllBookmark 0x00002000
Expand Down
8 changes: 4 additions & 4 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ void InitInstance(HINSTANCE hInstance, int nCmdShow) {
WideCharToMultiByte(CP_UTF8, 0, lpMatchArg, -1, efrData.szFindUTF8, COUNTOF(efrData.szFindUTF8), NULL, NULL);

if (flagMatchText & MatchTextFlag_Regex) {
efrData.fuFlags |= SCFIND_REGEXP | SCFIND_POSIX;
efrData.fuFlags |= NP2_RegexDefaultFlags;
} else if (flagMatchText & MatchTextFlag_TransformBS) {
efrData.bTransformBS = true;
}
Expand Down Expand Up @@ -4805,7 +4805,7 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) {
strcpy(efrData.szFindUTF8, mszSelection);
}

efrData.fuFlags &= (~(SCFIND_REGEXP | SCFIND_POSIX));
efrData.fuFlags &= ~NP2_RegexDefaultFlags;
efrData.bTransformBS = false;

switch (LOWORD(wParam)) {
Expand Down Expand Up @@ -5484,7 +5484,7 @@ void LoadSettings(void) {
efrData.fuFlags |= SCFIND_WORDSTART;
}
if (IniSectionGetBool(pIniSection, L"FindReplaceRegExpSearch", false)) {
efrData.fuFlags |= SCFIND_REGEXP | SCFIND_POSIX;
efrData.fuFlags |= NP2_RegexDefaultFlags;
}
efrData.bTransformBS = IniSectionGetBool(pIniSection, L"FindReplaceTransformBackslash", false);
efrData.bWildcardSearch = IniSectionGetBool(pIniSection, L"FindReplaceWildcardSearch", false);
Expand Down Expand Up @@ -5864,7 +5864,7 @@ void SaveSettings(bool bSaveSettingsNow) {
IniSectionSetBoolEx(pIniSection, L"FindReplaceMatchCase", (efrData.fuFlags & SCFIND_MATCHCASE), false);
IniSectionSetBoolEx(pIniSection, L"FindReplaceMatchWholeWorldOnly", (efrData.fuFlags & SCFIND_WHOLEWORD), false);
IniSectionSetBoolEx(pIniSection, L"FindReplaceMatchBeginingWordOnly", (efrData.fuFlags & SCFIND_WORDSTART), false);
IniSectionSetBoolEx(pIniSection, L"FindReplaceRegExpSearch", (efrData.fuFlags & (SCFIND_REGEXP | SCFIND_POSIX)), false);
IniSectionSetBoolEx(pIniSection, L"FindReplaceRegExpSearch", (efrData.fuFlags & SCFIND_REGEXP), false);
IniSectionSetBoolEx(pIniSection, L"FindReplaceTransformBackslash", efrData.bTransformBS, false);
IniSectionSetBoolEx(pIniSection, L"FindReplaceWildcardSearch", efrData.bWildcardSearch, false);
}
Expand Down

0 comments on commit 2c61b23

Please sign in to comment.