-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathCSearchAgent.h
138 lines (117 loc) · 4.53 KB
/
CSearchAgent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*! @file */
/*
Copyright (C) 2008, kobake
Copyright (C) 2018-2022, Sakura Editor Organization
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef SAKURA_CSEARCHAGENT_9FAD6EE9_3D33_4D9F_9E9D_CAA9BE284140_H_
#define SAKURA_CSEARCHAGENT_9FAD6EE9_3D33_4D9F_9E9D_CAA9BE284140_H_
#pragma once
#include "_main/global.h"
#include "util/design_template.h"
#include "basis/SakuraBasis.h"
class CDocLineMgr;
struct DocLineReplaceArg;
class CBregexp;
class CNativeW;
// #define SEARCH_STRING_KMP
#define SEARCH_STRING_SUNDAY_QUICK
class CSearchStringPattern
{
public:
CSearchStringPattern();
CSearchStringPattern(HWND, const wchar_t* pszPattern, int nPatternLen, const SSearchOption& sSearchOption, CBregexp* pRegexp);
~CSearchStringPattern();
void Reset();
bool SetPattern(HWND hwnd, const wchar_t* pszPattern, int nPatternLen, const SSearchOption& sSearchOption, CBregexp* pRegexp){
return SetPattern(hwnd, pszPattern, nPatternLen, NULL, sSearchOption, pRegexp, false);
}
bool SetPattern(HWND, const wchar_t* pszPattern, int nPatternLen, const wchar_t* pszPattern2, const SSearchOption& sSearchOption, CBregexp* pRegexp, bool bGlobal);
const wchar_t* GetKey() const{ return m_pszKey; }
const wchar_t* GetCaseKey() const{ return m_pszCaseKeyRef; }
int GetLen() const{ return m_nPatternLen; }
bool GetIgnoreCase() const{ return !m_psSearchOption->bLoHiCase; }
bool GetLoHiCase() const{ return m_psSearchOption->bLoHiCase; }
const SSearchOption& GetSearchOption() const{ return *m_psSearchOption; }
CBregexp* GetRegexp() const{ return m_pRegexp; }
#ifdef SEARCH_STRING_KMP
const int* GetKMPNextTable() const{ return m_pnNextPossArr; }
#endif
#ifdef SEARCH_STRING_SUNDAY_QUICK
const int* GetUseCharSkipMap() const{ return m_pnUseCharSkipArr; }
static int GetMapIndex( wchar_t c );
#endif
private:
// 外部依存
const wchar_t* m_pszKey;
const SSearchOption* m_psSearchOption;
mutable CBregexp* m_pRegexp;
const wchar_t* m_pszCaseKeyRef;
// 内部バッファ
wchar_t* m_pszPatternCase;
int m_nPatternLen;
#ifdef SEARCH_STRING_KMP
int* m_pnNextPossArr;
#endif
#ifdef SEARCH_STRING_SUNDAY_QUICK
int* m_pnUseCharSkipArr;
#endif
DISALLOW_COPY_AND_ASSIGN(CSearchStringPattern);
};
class CSearchAgent{
public:
// 文字列検索
static const wchar_t* SearchString(
const wchar_t* pLine,
int nLineLen,
int nIdxPos,
const CSearchStringPattern& pattern
);
// 単語単位で文字列検索
static const wchar_t* SearchStringWord(
const wchar_t* pLine,
int nLineLen,
int nIdxPos,
const std::vector<std::pair<const wchar_t*, CLogicInt> >& searchWords,
bool bLoHiCase,
int* pnMatchLen
);
// 検索条件の情報
static void CreateCharCharsArr(
const wchar_t* pszPattern,
int nSrcLen,
int** ppnCharCharsArr
);
static void CreateWordList(
std::vector<std::pair<const wchar_t*, CLogicInt> >& searchWords,
const wchar_t* pszPattern,
int nPatternLen
);
public:
CSearchAgent(CDocLineMgr* pcDocLineMgr) : m_pcDocLineMgr(pcDocLineMgr) { }
bool WhereCurrentWord( CLogicInt nLineNum, CLogicInt nIdx,
CLogicInt* pnIdxFrom, CLogicInt* pnIdxTo,
CNativeW* pcmcmWord, CNativeW* pcmcmWordLeft ); /* 現在位置の単語の範囲を調べる */
bool PrevOrNextWord( CLogicInt nLineNum, CLogicInt nIdx, CLogicInt* pnColumnNew,
BOOL bLEFT, BOOL bStopsBothEnds ); /* 現在位置の左右の単語の先頭位置を調べる */
// Jun. 26, 2001 genta 正規表現ライブラリの差し替え
int SearchWord( CLogicPoint ptSerachBegin, ESearchDirection eDirection, CLogicRange* pMatchRange, const CSearchStringPattern& pattern ); /* 単語検索 */
void ReplaceData( DocLineReplaceArg* pArg, bool bEnableExtEol );
private:
CDocLineMgr* m_pcDocLineMgr;
};
#endif /* SAKURA_CSEARCHAGENT_9FAD6EE9_3D33_4D9F_9E9D_CAA9BE284140_H_ */