mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-11 21:03:05 +08:00
+rfc: some code refactorings
This commit is contained in:
parent
d796c33ccf
commit
66c1209a55
@ -23,6 +23,7 @@
|
||||
#include <mbstring.h>
|
||||
|
||||
#define VC_EXTRALEAN 1
|
||||
#define NOMINMAX 1
|
||||
#include <windows.h>
|
||||
|
||||
#include "Geometry.h"
|
||||
@ -88,7 +89,11 @@ static void SetSimpleOptions(OnigOptionType &onigOptions, EOLmode /*eolMode*/,
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_NOTBOL);
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_NOTEOL);
|
||||
// ----------------------------------------------------------
|
||||
|
||||
//~ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_ASCII_RANGE);
|
||||
//~ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_CAPTURE_GROUP);
|
||||
//~ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_NOT_BEGIN_POSITION);
|
||||
// ----------------------------------------------------------
|
||||
|
||||
if (rangeBegIsDocBeg) {
|
||||
ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_NOT_BEGIN_STRING);
|
||||
} else {
|
||||
@ -100,10 +105,7 @@ static void SetSimpleOptions(OnigOptionType &onigOptions, EOLmode /*eolMode*/,
|
||||
ONIG_OPTION_ON(onigOptions, ONIG_OPTION_NOT_END_STRING);
|
||||
}
|
||||
|
||||
//~ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_ASCII_RANGE);
|
||||
//~ONIG_OPTION_OFF(onigOptions, ONIG_OPTION_CAPTURE_GROUP);
|
||||
//~ONIG_OPTION_ON(onigOptions, ONIG_OPTION_NOT_BEGIN_POSITION);
|
||||
|
||||
|
||||
// dynamic options
|
||||
//switch (eolMode) {
|
||||
// case EOLmode::CR:
|
||||
@ -296,19 +298,19 @@ Sci::Position OnigurumaRegExEngine::FindText(Document* doc, Sci::Position minPos
|
||||
|
||||
auto const docBegPos = SciPos(0);
|
||||
auto const docEndPos = SciPos(doc->Length());
|
||||
EOLmode const eolMode = static_cast<EOLmode>(doc->eolMode);
|
||||
|
||||
bool const findForward = (minPos <= maxPos);
|
||||
int const increment = findForward ? 1 : -1;
|
||||
|
||||
// Range endpoints should not be inside DBCS characters, but just in case, move them.
|
||||
minPos = doc->MovePositionOutsideChar(minPos, increment, true);
|
||||
maxPos = doc->MovePositionOutsideChar(maxPos, increment, true);
|
||||
maxPos = doc->MovePositionOutsideChar(maxPos, -increment, true);
|
||||
|
||||
Sci::Position const rangeBeg = (findForward) ? minPos : maxPos;
|
||||
Sci::Position const rangeEnd = (findForward) ? maxPos : minPos;
|
||||
Sci::Position const rangeLen = (rangeEnd - rangeBeg);
|
||||
|
||||
EOLmode const eolMode = static_cast<EOLmode>(doc->eolMode);
|
||||
|
||||
OnigOptionType onigOptions;
|
||||
SetSimpleOptions(onigOptions, eolMode, caseSensitive, findForward, searchFlags, (rangeBeg == docBegPos), (rangeEnd == docEndPos));
|
||||
|
||||
@ -353,8 +355,8 @@ Sci::Position OnigurumaRegExEngine::FindText(Document* doc, Sci::Position minPos
|
||||
|
||||
// --- search document range for pattern match ---
|
||||
// !!! Performance issue: Scintilla: moving Gap needs memcopy - high costs for find/replace in large document
|
||||
auto const docBegPtr = UCharCPtr(doc->RangePointer(0, docEndPos));
|
||||
auto const docEndPtr = UCharCPtr(doc->RangePointer(docEndPos, 0));
|
||||
auto const docBegPtr = UCharCPtr(doc->BufferPointer());
|
||||
auto const docEndPtr = UCharCPtr(doc->RangePointer(docEndPos, 1));
|
||||
auto const rangeBegPtr = UCharCPtr(doc->RangePointer(rangeBeg, rangeLen));
|
||||
auto const rangeEndPtr = UCharCPtr(doc->RangePointer(rangeEnd, 0));
|
||||
|
||||
@ -377,9 +379,9 @@ Sci::Position OnigurumaRegExEngine::FindText(Document* doc, Sci::Position minPos
|
||||
return SciPos(-3);
|
||||
}
|
||||
|
||||
if ((m_Result >= 0) && (m_Region.num_regs >= 1))
|
||||
if ((m_Result >= rangeBeg) && (m_Result <= rangeEnd) && (m_Region.num_regs >= 1))
|
||||
{
|
||||
//~m_MatchPos = SciPos(m_Result); //
|
||||
//~m_MatchPos = SciPos(m_Result);
|
||||
m_MatchPos = SciPos(m_Region.beg[0]);
|
||||
//~m_MatchLen = SciPos(m_Region.end[0] - m_Result);
|
||||
m_MatchLen = SciPos(m_Region.end[0]) - m_MatchPos;
|
||||
@ -742,6 +744,7 @@ public:
|
||||
onig_initialize(s_UsedEncodingsTypes, _ARRAYSIZE(s_UsedEncodingsTypes));
|
||||
|
||||
m_OnigSyntax.op |= ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END; // xcluded from ONIG_SYNTAX_DEFAULT ?
|
||||
|
||||
onig_set_default_syntax(&m_OnigSyntax); // std is: ONIG_SYNTAX_ONIGURUMA
|
||||
|
||||
onig_region_init(&m_Region);
|
||||
|
||||
@ -708,8 +708,8 @@ onigenc_is_mbc_newline_0x0a(const UChar* p, const UChar* end)
|
||||
#endif
|
||||
}
|
||||
#ifdef USE_END_OF_FILE_AS_LINE_TERMINATOR
|
||||
//if (p == end)
|
||||
// return 1;
|
||||
if (p == end)
|
||||
return 1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -725,8 +725,8 @@ onigenc_is_mbc_newline_0x0d(const UChar* p, const UChar* end)
|
||||
#endif
|
||||
}
|
||||
#ifdef USE_END_OF_FILE_AS_LINE_TERMINATOR
|
||||
//if (p == end)
|
||||
// return 1;
|
||||
if (p == end)
|
||||
return 1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
17
src/Edit.c
17
src/Edit.c
@ -5906,19 +5906,6 @@ static char* _GetReplaceString(HWND hwnd, CLPCEDITFINDREPLACE lpefr, int* iRepla
|
||||
// ONIG_MISMATCH
|
||||
#define NOT_FOUND ((DocPos)(-1LL))
|
||||
|
||||
__forceinline DocPos validate_found_pos(DocPos pos, const DocPos rbeg, const DocPos rend)
|
||||
{
|
||||
if (pos >= 0LL) {
|
||||
if (rbeg <= rend) { // forward search
|
||||
if ((pos < rbeg) || (pos > rend)) { pos = NOT_FOUND; }
|
||||
} else {
|
||||
if ((pos < rend) || (pos > rbeg)) { pos = NOT_FOUND; }
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
static DocPos _FindInTarget(LPCWSTR wchFind, int sFlags,
|
||||
DocPos* begin, DocPos* end, bool bForceNext, FR_UPD_MODES fMode)
|
||||
{
|
||||
@ -5942,7 +5929,7 @@ static DocPos _FindInTarget(LPCWSTR wchFind, int sFlags,
|
||||
|
||||
SciCall_SetSearchFlags(sFlags);
|
||||
SciCall_SetTargetRange(start, stop);
|
||||
iPos = validate_found_pos(SciCall_SearchInTarget(len, chFind), start, stop); // not found if beyond stop
|
||||
iPos = SciCall_SearchInTarget(len, chFind);
|
||||
|
||||
#if 1
|
||||
// handle next in case of zero-length-matches or invalid position (regex) !
|
||||
@ -5953,7 +5940,7 @@ static DocPos _FindInTarget(LPCWSTR wchFind, int sFlags,
|
||||
bool const bProceed = (bFindNext ? (newStart < stop) : (newStart > stop)) && (newStart != iPos);
|
||||
if (bProceed) {
|
||||
SciCall_SetTargetRange(newStart, stop);
|
||||
iPos = validate_found_pos(SciCall_SearchInTarget(len, chFind), newStart, stop); // not found if beyond stop
|
||||
iPos = SciCall_SearchInTarget(len, chFind); // not found if beyond stop
|
||||
}
|
||||
else {
|
||||
iPos = NOT_FOUND; // already at document begin, end or stuck => not found
|
||||
|
||||
@ -795,7 +795,7 @@ DeclareSciCallR0(IsSelectionRectangle, SELECTIONISRECTANGLE, bool);
|
||||
// length of line w/o line-end chars (full use SciCall_LineLength()
|
||||
#define Sci_GetNetLineLength(line) (SciCall_GetLineEndPosition(line) - SciCall_PositionFromLine(line))
|
||||
|
||||
//~define Sci_GetDocEndPosition() SciCall_GetTextLength()
|
||||
//~#define Sci_GetDocEndPosition() SciCall_GetTextLength()
|
||||
#define Sci_GetDocEndPosition() SciCall_PositionAfter(SciCall_GetTextLength() - 1)
|
||||
|
||||
#define Sci_ClampAlpha(alpha) clampi((alpha), SC_ALPHA_TRANSPARENT, SC_ALPHA_OPAQUE) //~SC_ALPHA_NOALPHA
|
||||
|
||||
Loading…
Reference in New Issue
Block a user