-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtclPattern.cpp
More file actions
291 lines (269 loc) · 8.22 KB
/
Copy pathtclPattern.cpp
File metadata and controls
291 lines (269 loc) · 8.22 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/* -------------------------------------
This file is part of AnalysePlugin for NotePad++
Copyright (c) 2022 Matthias H. mattesh(at)gmx.net
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------- */
/**
tclPattern implements information stored to execute one search on
*/
//#include "stdafx.h"
#include "tclPattern.h"
#include <windows.h>
#include <stdio.h>
const TCHAR* tclPattern::transSearchType[max_searchType] = {
TEXT("normal"),
TEXT("escaped"),
TEXT("regex"),
TEXT("rgx_multiline")
};
const TCHAR* tclPattern::transSelectionType[max_selectionType] = {
TEXT("text"),
TEXT("line")
};
const TCHAR* tclPattern::transBool[2] = {
TEXT("false"),
TEXT("true") // == 1
};
// ########################################################
tclPattern::tclPattern()
:mOrderNum(TEXT(""))
,mDoSearch(true)
,mSearchType(normal)
,mWholeWord(false)
,mMatchCase(false)
,mBold(false)
,mItalic(false)
,mUnderlined(false)
,mColor(tclColor::black)
,mBgColor(tclColor::white)
,mHideText(false)
,mDoReplace(false)
,mSelectionType(line)
{}
tclPattern::~tclPattern(){}
const generic_string& tclPattern::getSearchText() const{
return mSearchText;
}
const generic_string& tclPattern::getComment() const{
return mComment;
}
generic_string tclPattern::getReplaceText() const{
return mReplaceText;
}
void tclPattern::setSearchText(const generic_string& thisSearchText){
mSearchText = thisSearchText;
}
void tclPattern::setComment(const generic_string& thisComment){
mComment = thisComment;
}
void tclPattern::setReplaceText(const generic_string& thisReplaceText){
mReplaceText = thisReplaceText;
}
generic_string tclPattern::getSearchTypeStr() const {
return generic_string(transSearchType[mSearchType]);
}
void tclPattern::setSearchTypeStr(const generic_string& type) {
for(int i=0; i<max_searchType;i++) {
if(type == transSearchType[i]) {
mSearchType =(teSearchType)i;
break;
}
}
}
void tclPattern::setSearchType(int type) {
mSearchType =(teSearchType)type;
}
generic_string tclPattern::getBoldStr() const {
return transBool[mBold];
}
void tclPattern::setBold(bool isBold) {
mBold =isBold;
}
generic_string tclPattern::getItalicStr() const {
return transBool[mItalic];
}
void tclPattern::setItalic(bool isItalic) {
mItalic =isItalic;
}
generic_string tclPattern::getUnderlinedStr() const {
return transBool[mUnderlined];
}
void tclPattern::setUnderlined(bool isUnderlined) {
mUnderlined =isUnderlined;
}
generic_string tclPattern::getColorStr()const{
return tclColor::getColStr(mColor);
}
generic_string tclPattern::getBgColorStr()const{
return tclColor::getColStr(mBgColor);
}
unsigned long tclPattern::convColorStr2Rgb(const generic_string& color) {
return tclColor::convColorStr2Rgb(color);
}
tColor tclPattern::convColorNum2Enum(unsigned long color) {
return tclColor::convColorNum2Enum(color);
}
void tclPattern::setColorStr(const generic_string& color) {
tclColor::setColStr(mColor, color);
}
void tclPattern::setBgColorStr(const generic_string& color) {
tclColor::setColStr(mBgColor, color);
}
void tclPattern::setColor(tColor color) {
mColor = color;
}
void tclPattern::setBgColor(tColor color) {
mBgColor = color;
}
tColor tclPattern::getDefColorNum(int e) {
return tclColor::getDefColorNum(e);
}
tColor tclPattern::getColorNum() const {
return tclColor::getColRgb(mColor);
}
tColor tclPattern::getBgColorNum() const {
return tclColor::getColRgb(mBgColor);
}
generic_string tclPattern::getHideTextStr()const{
return generic_string(transBool[mHideText]);
}
generic_string tclPattern::getIsReplaceTextStr()const{
return generic_string(transBool[mDoReplace]);
}
void tclPattern::setHideText(bool isHideText) {
mHideText = isHideText;
}
void tclPattern::setIsReplaceText(bool isReplaceText) {
mDoReplace = isReplaceText;
}
generic_string tclPattern::getSelectionTypeStr()const{
return generic_string(transSelectionType[mSelectionType]);
}
bool tclPattern::convBool(const generic_string& val) const {
int i=0;
for(; i < 2 ;i++) { // 0 false 1 true
if(val ==transBool[i]) {
return i?true:false;
}
}
return false;
}
void tclPattern::setSelectionType(int selectionType) {
mSelectionType =(teSelectionType)selectionType;
}
void tclPattern::setSelectionTypeStr(const generic_string& type){
for(int i=0; i<max_selectionType;i++) {
if(type ==transSelectionType[i]) {
mSelectionType =(teSelectionType)i;
break;
}
}
}
generic_string tclPattern::convertExtendedToString() const
{ // IN query OUT result IN length
//query may equal to result, since it always gets smaller
const TCHAR* query = mSearchText.c_str();
int length = (int)mSearchText.size();
generic_string result;
result.reserve(length);
int i = 0, j = 0;
int charLeft = length;
bool isGood = true;
TCHAR current;
while(i < length) { //because the backslash escape quences always reduce the size of the string, no overflow checks have to be made for target, assuming parameters are correct
current = query[i];
charLeft--;
if (current == '\\' && charLeft) { //possible escape sequence
i++;
charLeft--;
current = query[i];
switch(current) {
case 'r':
result += '\r';
break;
case 'n':
result += '\n';
break;
case '0':
result += (TCHAR)'\0';
break;
case 't':
result += '\t';
break;
case '\\':
result += '\\';
break;
case 'b':
case 'd':
case 'o':
case 'x': {
int size = 0, base = 0;
if (current == 'b') { //11111111
size = 8, base = 2;
} else if (current == 'o') { //377
size = 3, base = 8;
} else if (current == 'd') { //255
size = 3, base = 10;
} else if (current == 'x') { //0xFF
size = 2, base = 16;
}
if (charLeft >= size) {
int res = 0;
if (readBase(query+(i+1), &res, base, size)) {
result += (char)res;
i+=size;
break;
}
}
//not enough chars to make parameter, use default method as fallback
}
default: { //unknown sequence, treat as regular text
result += '\\';
j++;
result += current;
isGood = false;
break;
}
}
} else {
result += query[i];
}
i++;
j++;
}
result += (TCHAR)'\0';
return result;
}
bool tclPattern::readBase(const TCHAR* string, int* value, int base, int size) const {
int i = 0, temp = 0;
*value = 0;
TCHAR mymax = '0' + (TCHAR)(base - 1);
TCHAR current;
while(i < size) {
current = string[i];
if (current >= '0' && current <= mymax) {
temp *= base;
temp += (current - '0');
} else {
return false;
}
i++;
}
*value = temp;
return true;
}
const TCHAR** tclPattern::getDefSelTypeList() const {
return transSelectionType;
}
const TCHAR** tclPattern::getDefSearchTypeList() const {
return transSearchType;
}