FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
AnalysePlugin/FindConfigDoc.cpp at master · chcg/AnalysePlugin · GitHub
chcg
/
AnalysePlugin
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
8
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
AnalysePlugin
/
FindConfigDoc.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
303 lines (289 loc) · 10.9 KB
Breadcrumbs
AnalysePlugin
/
FindConfigDoc.cpp
Copy path
File metadata and controls
303 lines (289 loc) · 10.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
292
293
294
295
296
297
298
299
300
301
302
303
/*
-------------------------------------
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/>.
-------------------------------------
*/
//
#include "stdafx.h"
#
include
"
FindConfigDoc.h
"
#
include
"
tinyxml.h
"
#
include
"
tclPattern.h
"
#
define
FNDDOC_XMLNS
TEXT
(
"
xmlns:xsi
"
)
#
define
FNDDOC_XMLNS_VALUE
TEXT
(
"
http://www.w3.org/2001/XMLSchema-instance
"
)
#
define
FNDDOC_XSD_LOCATION
TEXT
(
"
xsi:noNamespaceSchemaLocation
"
)
#
define
FNDDOC_XSD_LOCATION_VALUE
TEXT
(
"
./AnalyseDoc.xsd
"
)
#
define
FNDDOC_ANALYSE_DOC
TEXT
(
"
AnalyseDoc
"
)
#
define
FNDDOC_HEADLINE
TEXT
(
"
Headline
"
)
//
on even w/o FEATURE_HEADLINE to be able to read the doc
#
define
FNDDOC_SEARCH_TEXT
TEXT
(
"
SearchText
"
)
#
define
FNDDOC_SEARCH_TYPE
TEXT
(
"
searchType
"
)
#
define
FNDDOC_DO_SEARCH
TEXT
(
"
doSearch
"
)
#
define
FNDDOC_MATCHCASE
TEXT
(
"
matchCase
"
)
#
define
FNDDOC_WHOLEWORD
TEXT
(
"
wholeWord
"
)
#
define
FNDDOC_SELECT
TEXT
(
"
select
"
)
#
define
FNDDOC_HIDE
TEXT
(
"
hide
"
)
#
define
FNDDOC_BOLD
TEXT
(
"
bold
"
)
#
define
FNDDOC_ITALIC
TEXT
(
"
italic
"
)
#
define
FNDDOC_UNDERLINED
TEXT
(
"
underlined
"
)
#
define
FNDDOC_COLOR
TEXT
(
"
color
"
)
#
define
FNDDOC_BGCOLOR
TEXT
(
"
bgColor
"
)
#
define
FNDDOC_COMMENT
TEXT
(
"
comment
"
)
#
define
FNDDOC_GROUP
TEXT
(
"
group
"
)
#
define
FNDDOC_HITS
TEXT
(
"
hits
"
)
#
define
FNDDOC_ORDER_NUM
TEXT
(
"
orderNum
"
)
FindConfigDoc::FindConfigDoc(
const
TCHAR
* filename)
: mDoc(
0
)
{
mDoc
=
new
TiXmlDocument
(filename);
if
(
mDoc
) {
//
avoid removal of multiple tabs and spaces in searchstring, as they may be intentional
mDoc
->
SetCondenseWhiteSpace
(
false
);
mDoc
->
LoadFile
();
}
}
FindConfigDoc::~FindConfigDoc
(
void
)
{
if
(
mDoc
) {
delete
mDoc
;
mDoc
=
0
;
}
}
bool
FindConfigDoc::getError
(generic_string& msg)
const
{
bool
bRes = (
mDoc
&&
mDoc
->
Error
() ||
0
==
mDoc
);
if
(bRes &&
mDoc
) {
TCHAR
row[
10
];
msg =
mDoc
->
ErrorDesc
();
msg +=
TEXT
(
"
in line
"
);
msg +=
generic_itoa
(
mDoc
->
ErrorRow
(), row,
10
);
msg +=
TEXT
(
"
"
);
}
return
bRes;
}
bool
FindConfigDoc::readPatternList
(tclPatternList& pl,
bool
bAppend,
bool
bLoadNew){
bool
bRes=
false
;
if
(
mDoc
&& !
mDoc
->
Error
()) {
TiXmlNode* node =
mDoc
->
FirstChild
(
FNDDOC_ANALYSE_DOC
);
if
(node) {
TiXmlNode* node2 = node->
FirstChild
(
FNDDOC_HEADLINE
);
if
(node2) {
TiXmlElement*
e3
= node2->
ToElement
();
node2 =
e3
->
FirstChild
();
if
(node2) {
#
ifdef
FEATURE_HEADLINE
mHeadline
= node2->
Value
();
#
endif
}
}
//
continue with patterns
if
(bAppend) {
node = node->
FirstChild
(
FNDDOC_SEARCH_TEXT
);
}
else
{
node = node->
LastChild
(
FNDDOC_SEARCH_TEXT
);
}
bRes =
true
;
if
(bLoadNew) {
pl.
clear
();
}
while
(node) {
TiXmlElement* elem = node->
ToElement
();
const
TCHAR
* pc =
0
;
if
(elem && elem->
FirstChild
()) {
tclPattern p;
generic_string
text
(elem->
FirstChild
()->
Value
());
p.
setSearchText
(text);
pc = elem->
Attribute
(
FNDDOC_ORDER_NUM
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setOrderNumStr
(pc);
}
pc = elem->
Attribute
(
FNDDOC_DO_SEARCH
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setDoSearchStr
(pc);
}
pc = elem->
Attribute
(
FNDDOC_SEARCH_TYPE
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setSearchTypeStr
(pc);
}
pc = elem->
Attribute
(
FNDDOC_MATCHCASE
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setMatchCaseStr
(pc);
}
pc = elem->
Attribute
(
FNDDOC_WHOLEWORD
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setWholeWordStr
(pc);
}
pc = elem->
Attribute
(
FNDDOC_SELECT
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setSelectionTypeStr
(pc);
}
pc = elem->
Attribute
(
FNDDOC_HIDE
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setHideTextStr
(pc);
}
pc = elem->
Attribute
(
FNDDOC_BOLD
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setBoldStr
(pc);
}
pc = elem->
Attribute
(
FNDDOC_ITALIC
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setItalicStr
(pc);
}
pc = elem->
Attribute
(
FNDDOC_UNDERLINED
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setUnderlinedStr
(pc);
}
pc = elem->
Attribute
(
FNDDOC_COLOR
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setColorStr
(pc);
}
pc = elem->
Attribute
(
FNDDOC_BGCOLOR
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setBgColorStr
(pc);
}
pc = elem->
Attribute
(
FNDDOC_COMMENT
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setComment
(pc);
}
pc = elem->
Attribute
(
FNDDOC_GROUP
);
if
(pc !=
0
&& *pc !=
0
) {
p.
setGroup
(pc);
}
if
(bAppend) {
pl.
push_back
(p);
}
else
{
pl.
insert
(pl.
begin
().
getPatId
(), p);
}
}
//
search string available
if
(elem) {
if
(bAppend) {
node = elem->
NextSibling
(
FNDDOC_SEARCH_TEXT
);
}
else
{
node = elem->
PreviousSibling
(
FNDDOC_SEARCH_TEXT
);
}
}
}
//
while
}
//
if FirstChild(FNDDOC_ANALYSE_DOC)
else
{
bRes =
false
;
}
}
//
mDoc != 0
return
bRes;
}
bool
FindConfigDoc::writePatternList
(tclPatternList& pl){
bool
bRes =
false
;
if
(
mDoc
==
0
) {
return
bRes;
}
mDoc
->
Clear
();
TiXmlNode* n =
mDoc
->
InsertEndChild
(
TiXmlDeclaration
(
TEXT
(
"
1.0
"
),
TEXT
(
"
UTF-8
"
),
TEXT
(
"
"
)));
//
<?xml version="1.0" encoding="UTF-8"?>
n =
mDoc
->
InsertEndChild
(
TiXmlElement
(
FNDDOC_ANALYSE_DOC
));
if
(n) {
TiXmlElement* e = n->
ToElement
();
//
must work because we added e just before
e->
SetAttribute
(
FNDDOC_XMLNS
,
FNDDOC_XMLNS_VALUE
);
e->
SetAttribute
(
FNDDOC_XSD_LOCATION
,
FNDDOC_XSD_LOCATION_VALUE
);
TiXmlNode* n2 =
0
;
#
ifdef
FEATURE_HEADLINE
n2 = e->
InsertEndChild
(
TiXmlElement
(
FNDDOC_HEADLINE
));
if
(n2) {
n2->
ToElement
()->
InsertEndChild
(
TiXmlText
(
mHeadline
.
c_str
()));
}
#
endif
tclPattern defP;
for
(
unsigned
i =
0
; i < pl.
size
();++i) {
const
tclPattern& rp = pl.
getPattern
(pl.
getPatternId
(i));
n2 = e->
InsertEndChild
(
TiXmlElement
(
FNDDOC_SEARCH_TEXT
));
if
(n2) {
TiXmlElement*
e2
= n2->
ToElement
();
e2
->
InsertEndChild
(
TiXmlText
(rp.
getSearchText
().
c_str
()));
//
save attributes only if different from default value
if
(rp.
getOrderNumStr
() != defP.
getOrderNumStr
()) {
e2
->
SetAttribute
(
FNDDOC_ORDER_NUM
, rp.
getOrderNumStr
().
c_str
());
}
if
(rp.
getDoSearch
() != defP.
getDoSearch
()) {
e2
->
SetAttribute
(
FNDDOC_DO_SEARCH
, rp.
getDoSearchStr
().
c_str
());
}
if
(rp.
getSearchType
() != defP.
getSearchType
()) {
e2
->
SetAttribute
(
FNDDOC_SEARCH_TYPE
, rp.
getSearchTypeStr
().
c_str
());
}
if
(rp.
getSearchType
() != defP.
getSearchType
()) {
e2
->
SetAttribute
(
FNDDOC_SEARCH_TYPE
, rp.
getSearchTypeStr
().
c_str
());
}
if
(rp.
getIsMatchCase
() != defP.
getIsMatchCase
()) {
e2
->
SetAttribute
(
FNDDOC_MATCHCASE
, rp.
getMatchCaseStr
().
c_str
());
}
if
(rp.
getIsWholeWord
() != defP.
getIsWholeWord
()) {
e2
->
SetAttribute
(
FNDDOC_WHOLEWORD
, rp.
getWholeWordStr
().
c_str
());
}
if
(rp.
getSelectionType
() != defP.
getSelectionType
()) {
e2
->
SetAttribute
(
FNDDOC_SELECT
, rp.
getSelectionTypeStr
().
c_str
());
}
if
(rp.
getIsHideText
() != defP.
getIsHideText
()) {
e2
->
SetAttribute
(
FNDDOC_HIDE
, rp.
getHideTextStr
().
c_str
());
}
if
(rp.
getIsBold
() != defP.
getIsBold
()) {
e2
->
SetAttribute
(
FNDDOC_BOLD
, rp.
getBoldStr
().
c_str
());
}
if
(rp.
getIsItalic
() != defP.
getIsItalic
()) {
e2
->
SetAttribute
(
FNDDOC_ITALIC
, rp.
getItalicStr
().
c_str
());
}
if
(rp.
getIsUnderlined
() != defP.
getIsUnderlined
()) {
e2
->
SetAttribute
(
FNDDOC_UNDERLINED
, rp.
getUnderlinedStr
().
c_str
());
}
if
(rp.
getColor
() != defP.
getColor
()) {
e2
->
SetAttribute
(
FNDDOC_COLOR
, rp.
getColorStr
().
c_str
());
}
if
(rp.
getBgColor
() != defP.
getBgColor
()) {
e2
->
SetAttribute
(
FNDDOC_BGCOLOR
, rp.
getBgColorStr
().
c_str
());
}
if
(!rp.
getComment
().
empty
()) {
e2
->
SetAttribute
(
FNDDOC_COMMENT
, rp.
getComment
().
c_str
());
}
if
(!rp.
getGroup
().
empty
()) {
e2
->
SetAttribute
(
FNDDOC_GROUP
, rp.
getGroup
().
c_str
());
}
}
}
//
for
bRes =
mDoc
->
SaveFile
();
}
else
{
bRes =
false
;
}
return
bRes;
}
bool
FindConfigDoc::writePatternHitsList
(tclResultList& rl) {
bool
bRet =
writePatternList
(rl);
bool
bRet2 =
false
;
TiXmlNode* n;
TiXmlElement* e;
n =
mDoc
->
FirstChildElement
();
if
(n &&
generic_string
(n->
Value
()) ==
FNDDOC_ANALYSE_DOC
) {
n = n->
FirstChildElement
();
}
if
(n && (
generic_string
(n->
Value
()) ==
FNDDOC_HEADLINE
)) {
n = n->
NextSiblingElement
();
}
for
(
unsigned
i =
0
; i < rl.
size
(); ++i) {
const
tclResult& rr = rl.
refResult
(rl.
getPatternId
(i));
if
(!rr.
getIsDirty
()) {
unsigned
u = rr.
size
();
if
(n &&
generic_string
(n->
Value
()) ==
FNDDOC_SEARCH_TEXT
) {
e = n->
ToElement
();
bRet2 =
true
;
e->
SetAttribute
(
FNDDOC_HITS
, u);
n = n->
NextSiblingElement
();
}
}
}
if
(bRet2) {
bRet2 =
mDoc
->
SaveFile
();
}
return
bRet && bRet2;
}
Back
|
FazBrowse Home
|
New Git URL