forked from Kitware/KWStyle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kwsParser.cxx
2075 lines (1872 loc) · 45.3 KB
/
kwsParser.cxx
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*=========================================================================
Program: KWStyle - Kitware Style Checker
Module: kwsParser.cxx
Copyright (c) Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "kwsParser.h"
#include <stdlib.h> // atoi
#include <string.h>
#include <kwssys/ios/sstream>
#include <boost/xpressive/xpressive.hpp>
using namespace boost::xpressive;
namespace kws {
/** Constructor */
Parser::Parser()
{
m_HeaderFilename = "";
m_Filename = "";
m_FixFile = false;
m_FixedPositions.clear();
for(unsigned int i=0;i<NUMBER_ERRORS;i++)
{
m_TestsDone[i] = false;
m_TestsDescription[i] += "NA";
}
}
/** Destructor */
Parser::~Parser()
{
}
/** To be able to use std::sort we provide the < operator */
bool Parser::operator<(const Parser& a) const
{
if(m_Filename.compare(a.m_Filename))
{
return false;
}
return true;
}
/** Given the name of the check to perform and the default value perform the check */
bool Parser::Check(const char* name, const char* value)
{
if(!strcmp(name,"LineLength"))
{
this->CheckLineLength(atoi(value));
return true;
}
else if(!strcmp(name,"DeclarationOrder"))
{
this->CheckDeclarationOrder(atoi(&value[0]),atoi(&value[2]),atoi(&value[4]));
return true;
}
else if(!strcmp(name,"Typedefs"))
{
bool alignment = true; // check alignment by default
std::string val = value;
long pos = val.find(",",0);
if(pos != -1)
{
std::string v1 = val.substr(0,pos);
// Check the alignment
long pos1 = val.find(",",pos+1);
std::string v2 = "";
if(pos1 == -1)
{
v2 = val.substr(pos+1,val.size()-pos-1);
}
else
{
v2 = val.substr(pos+1,pos1-pos-1);
}
if(!strcmp(v2.c_str(),"false") || !strcmp(v2.c_str(),"0"))
{
alignment = false;
}
val = v1;
}
this->CheckTypedefs(val.c_str(),alignment);
return true;
}
else if(!strcmp(name,"InternalVariables"))
{
bool alignment = true; // check alignment by default
bool checkProtected = false; // check protected by default
std::string val = value;
long pos = val.find(",",0);
if(pos != -1)
{
std::string v1 = val.substr(0,pos);
// Check the alignment
long pos1 = val.find(",",pos+1);
std::string v2 = "";
if(pos1 == -1)
{
v2 = val.substr(pos+1,val.size()-pos-1);
}
else
{
v2 = val.substr(pos+1,pos1-pos-1);
}
if(!strcmp(v2.c_str(),"false") || !strcmp(v2.c_str(),"0"))
{
alignment = false;
}
if(pos1 != -1)
{
// Check the protected
pos = val.find(",",pos1+1);
std::string v3 = "";
if(pos == -1)
{
v3 = val.substr(pos1+1,val.size()-pos1-1);
}
else
{
v3 = val.substr(pos1+1,pos-pos1-1);
}
if(!strcmp(v3.c_str(),"true") || !strcmp(v3.c_str(),"1"))
{
checkProtected = true;
}
}
val = v1;
}
this->CheckInternalVariables(val.c_str(),alignment,checkProtected);
return true;
}
else if(!strcmp(name,"Variables"))
{
this->CheckVariables(value);
return true;
}
else if(!strcmp(name,"Struct"))
{
this->CheckStruct(value);
return true;
}
else if(!strcmp(name,"MemberFunctions"))
{
std::string val = value;
std::string v1 = value;
std::string v2 = "0";
long pos = val.find(",",0);
if(pos != -1)
{
v1 = val.substr(0,pos);
v2 = val.substr(pos+1,val.size()-pos-1);
}
this->CheckMemberFunctions(v1.c_str(),atoi(v2.c_str()));
return true;
}
else if(!strcmp(name,"Functions"))
{
std::string val = value;
std::string v1 = value;
std::string v2 = "0";
long pos = val.find(",",0);
if(pos != -1)
{
v1 = val.substr(0,pos);
v2 = val.substr(pos+1,val.size()-pos-1);
}
this->CheckFunctions(v1.c_str(),atoi(v2.c_str()));
return true;
}
else if(!strcmp(name,"SemicolonSpace"))
{
this->CheckSemicolonSpace(atoi(value));
return true;
}
else if(!strcmp(name,"EndOfFileNewLine"))
{
this->CheckEndOfFileNewLine();
return true;
}
else if(!strcmp(name,"Tabs"))
{
this->CheckTabs();
return true;
}
else if(!strcmp(name,"Spaces"))
{
this->CheckExtraSpaces(atoi(value));
return true;
}
else if(!strcmp(name,"StatementPerLine"))
{
std::string val = value;
std::string v1 = value;
long pos = val.find(",",0);
bool checkInlineFunctions = true;
if(pos != -1)
{
v1 = val.substr(0,pos);
std::string v2 = val.substr(pos+1,val.size()-pos-1);
if(v2 == "0")
{
checkInlineFunctions = false;
}
}
this->CheckStatementPerLine(atoi(v1.c_str()),checkInlineFunctions);
return true;
}
else if(!strcmp(name,"BadCharacters"))
{
if(!strcmp(value,"true"))
{
this->CheckBadCharacters(true);
}
else
{
this->CheckBadCharacters(false);
}
return true;
}
else if(!strcmp(name,"VariablePerLine"))
{
this->CheckVariablePerLine(atoi(value));
return true;
}
else if(!strcmp(name,"Comments"))
{
std::string val = value;
long pos = val.find(",",0);
if(pos == -1)
{
std::cout << "Comments not defined correctly" << std::endl;
return false;
}
std::string v1 = val.substr(0,pos);
long int pos1 = val.find(",",pos+1);
if(pos1 == -1)
{
std::cout << "Comments not defined correctly" << std::endl;
return false;
}
std::string v2 = val.substr(pos+1,pos1-pos-1);
pos = val.find(",",pos1+1);
if(pos == -1)
{
std::cout << "Comments not defined correctly" << std::endl;
return false;
}
std::string v3 = val.substr(pos1+1,pos-pos1-1);
// Check if we allow empty lines before /class
pos1 = val.find(",",pos+1);
std::string v4 = "";
if(pos1 == -1)
{
v4 = val.substr(pos+1,val.length()-pos-1);
}
else
{
v4 = val.substr(pos+1,pos1-pos-1);
}
bool allowEmptyLine = false;
if(!strcmp(v4.c_str(),"true"))
{
allowEmptyLine = true;
}
// Check if we should check the comments misspeling
pos = val.find(",",pos1+1);
std::string v5 = "";
if(pos == -1)
{
v5 = val.substr(pos1+1,val.length()-pos1-1);
}
else
{
v5 = val.substr(pos1+1,pos-pos1-1);
}
bool checkWrongComment = true;
if(!strcmp(v5.c_str(),"false"))
{
checkWrongComment = false;
}
// Check if we should check the missing comments
pos1 = val.find(",",pos+1);
std::string v6 = "";
if(pos == -1)
{
v6 = val.substr(pos+1,val.length()-pos-1);
}
else
{
v6 = val.substr(pos+1,pos1-pos-1);
}
bool checkMissingComment = true;
if(!strcmp(v6.c_str(),"false"))
{
checkMissingComment = false;
}
this->CheckComments(v1.c_str(),v2.c_str(),v3.c_str(),allowEmptyLine,checkWrongComment,checkMissingComment);
return true;
}
// should be before CheckIndent
else if(!strcmp(name,"Header"))
{
std::string val = value;
long pos = val.find(",",0);
if(pos == -1)
{
std::cout << "Header not defined correctly" << std::endl;
return false;
}
std::string v1 = "";
if(pos>0)
{
v1 = val.substr(0,pos);
}
long int pos1 = val.find(",",pos+1);
if(pos1 == -1)
{
std::cout << "Header not defined correctly" << std::endl;
return false;
}
std::string v2 = val.substr(pos+1,pos1-pos-1);
std::string v3 = val.substr(pos1+1,val.length()-pos1-1);
bool spaceEndOfLine = false;
bool useCVS = false;
if(!strcmp(v2.c_str(),"true"))
{
spaceEndOfLine = true;
}
if(!strcmp(v3.c_str(),"true"))
{
useCVS = true;
}
if(v1.size()>0)
{
this->CheckHeader(v1.c_str(),spaceEndOfLine,useCVS);
}
}
else if(!strcmp(name,"Indent"))
{
std::string val = value;
long pos = val.find(",",0);
if(pos == -1)
{
std::cout << "Indent not defined correctly" << std::endl;
return false;
}
std::string v1 = val.substr(0,pos);
long int pos1 = val.find(",",pos+1);
if(pos1 == -1)
{
std::cout << "Indent not defined correctly" << std::endl;
return false;
}
std::string v2 = val.substr(pos+1,pos1-pos-1);
pos = val.find(",",pos1+1);
if(pos == -1)
{
std::cout << "Indent not defined correctly" << std::endl;
return false;
}
std::string v3 = val.substr(pos1+1,pos-pos1-1);
std::string v4 = val.substr(pos+1,val.length()-pos-1);
bool header = false;
if(!strcmp(v3.c_str(),"true"))
{
header = true;
}
bool blockline = false;
if(!strcmp(v4.c_str(),"true"))
{
blockline = true;
}
IndentType itype = kws::SPACE;
if(!strcmp(v1.c_str(),"TAB"))
{
itype = kws::TAB;
}
this->CheckIndent(itype,atoi(v2.c_str()),header,blockline);
}
else if(!strcmp(name,"Namespace"))
{
this->CheckNamespace(value);
}
else if(!strcmp(name,"NameOfClass"))
{
std::string val = value;
long pos = val.find(",",0);
if(pos == -1)
{
std::cout << "NameOfClass not defined correctly" << std::endl;
return false;
}
std::string v1 = val.substr(0,pos);
std::string v2 = val.substr(pos+1,val.length()-pos-1);
this->CheckNameOfClass(v1.c_str(),v2.c_str());
}
else if(!strcmp(name,"IfNDefDefine"))
{
this->CheckIfNDefDefine(value);
}
else if(!strcmp(name,"EmptyLines"))
{
this->CheckEmptyLines(atoi(value));
}
else if(!strcmp(name,"Template"))
{
this->CheckTemplate(value);
}
else if(!strcmp(name,"Operator"))
{
std::string val = value;
long pos = val.find(",",0);
if(pos == -1)
{
std::cout << "Operator not defined correctly" << std::endl;
return false;
}
std::string v1 = val.substr(0,pos);
std::string v2 = val.substr(pos+1,val.length()-pos-1);
this->CheckOperator(atoi(v1.c_str()),atoi(v2.c_str()));
}
else if(!strcmp(name,"BlackList"))
{
this->CheckBlackList(value);
}
return false;
}
/** Return if a test has been performed */
bool Parser::HasBeenPerformed(unsigned int test) const
{
return m_TestsDone[test];
}
/** Return the test description given the erro number) */
std::string Parser::GetTestDescription(unsigned int test) const
{
return m_TestsDescription[test];
}
/** Return the last errors as a string */
std::string Parser::GetLastErrors()
{
std::string output = "";
std::vector<Error>::const_iterator it = m_ErrorList.begin();
while(it != m_ErrorList.end())
{
output += "Error #";
char* val = new char[10];
sprintf(val,"%ld",(*it).number);
output += val;
delete [] val;
output += " (";
val = new char[10];
sprintf(val,"%ld",(*it).line);
output += val;
delete [] val;
output += ") ";
output += (*it).description;
output += "\n";
it++;
}
return output;
}
/** Return the error tag as string given the error number */
std::string Parser::GetErrorTag(unsigned long number) const
{
return ErrorTag[number];
}
/** Return the last warnings as a string */
std::string Parser::GetLastWarnings()
{
std::string output = "";
std::vector<Warning>::const_iterator it = m_WarningList.begin();
while(it != m_WarningList.end())
{
output += "Warning #";
char* val = new char[10];
sprintf(val,"%ld",(*it).number);
output += val;
delete [] val;
output += " (";
val = new char[10];
sprintf(val,"%ld",(*it).line);
output += val;
delete [] val;
output += ") ";
output += (*it).description;
output += "\n";
it++;
}
return output;
}
void Parser::ConvertBufferToWindowsFileType(std::string & buffer)
{
// replace logical newlines with windows newlines
sregex unixNewline = sregex::compile("\r?\n|\r");
std::string windowsNewline("\r\n");
buffer = regex_replace(buffer, unixNewline, windowsNewline);
}
/** Return the number of lines */
unsigned long Parser::GetNumberOfLines() const
{
unsigned long lines = 0;
long int pos = m_Buffer.find("\n",0);
while(pos != -1)
{
lines++;
pos = m_Buffer.find("\n",pos+1);
}
lines++; // the last line doesn't have any \n
return lines;
}
/** Return the line */
std::string Parser::GetLine(unsigned long i) const
{
unsigned long lines = 0;
long int prec = 0;
long int pos = m_Buffer.find("\n",0);
while(pos != -1)
{
if(lines == i)
{
if(pos-prec-1>0)
{
return m_Buffer.substr(prec,pos-prec-1);
}
}
lines++;
prec = pos;
pos = m_Buffer.find("\n",pos+1);
}
if(lines == i)
{
return m_Buffer.substr(prec,m_Buffer.size()-prec);
}
return "";
}
/** Find the previous word given a position */
std::string Parser::FindPreviousWord(size_t pos,bool withComments,std::string buffer) const
{
std::string stream = buffer;
if(buffer.size() == 0)
{
stream = m_BufferNoComment;
if(withComments)
{
stream = m_Buffer;
}
}
size_t i=pos;
while(stream[i] != ' ' && stream[i] != '\r' && i>0)
{
i--;
}
if(stream[i] == '\r' && i>1)
{
i--;
}
bool inWord = true;
bool first = false;
std::string ivar = "";
while(i != std::string::npos && inWord)
{
if(stream[i] != ' ' && stream[i] != '\n' && stream[i] != '\r')
{
std::string store = ivar;
ivar = stream[i];
ivar += store;
inWord = true;
first = true;
}
else // we have a space
{
if(stream[i] == '\r')
{
// do nothing
}
else if(first)
{
inWord = false;
}
}
i--;
}
return ivar;
}
/** Find the next word given a position */
std::string Parser::FindNextWord(size_t pos) const
{
size_t i=pos;
// we go to the next space
while(m_BufferNoComment[i] != ' ' && i<m_BufferNoComment.size())
{
i++;
}
bool inWord = true;
bool first = false;
std::string ivar = "";
while(i<m_BufferNoComment.size() && inWord)
{
if(m_BufferNoComment[i] != ' ' && m_BufferNoComment[i] != '\r')
{
ivar += m_BufferNoComment[i];
inWord = true;
first = true;
}
else // we have a space
{
if(first)
{
inWord = false;
}
}
i++;
}
return ivar;
}
/** Return the position in the line given the position in the text */
size_t Parser::GetPositionInLine(size_t pos)
{
size_t begin = pos;
while(begin != std::string::npos && m_BufferNoComment[begin]!='\n')
{
begin--;
}
return pos-begin;
}
/** Given the position without comments return the position with the comments */
size_t Parser::GetPositionWithComments(size_t pos) const
{
std::vector<PairType>::const_iterator it = m_CommentPositions.begin();
while(it != m_CommentPositions.end())
{
if((pos>=(*it).first))
{
pos += ((*it).second-(*it).first);
}
else
{
break;
}
it++;
}
return pos;
}
/** Given the position with comments return the position without the comments */
size_t Parser::GetPositionWithoutComments(size_t pos) const
{
size_t pos2 = pos;
std::vector<PairType>::const_iterator it = m_CommentPositions.begin();
while(it != m_CommentPositions.end())
{
if((pos>=(*it).first))
{
pos2 -= ((*it).second-(*it).first);
}
else
{
break;
}
it++;
}
return pos2;
}
/** Return if the dept of the current class
* This function works on m_BufferNoComments! */
int Parser::IsInClass(size_t position) const
{
int inClass = 0;
size_t classPos = this->GetClassPosition(0);
while(classPos!=std::string::npos)
{
size_t i=classPos;
while(i!=std::string::npos && i<m_BufferNoComment.size())
{
if(m_BufferNoComment[i] == '{')
{
break;
}
i++;
}
size_t classEnd = this->FindClosingChar('{','}',i+1,true);
if(position>classPos && position<classEnd)
{
inClass++;
}
classPos = this->GetClassPosition(classPos+1);
}
return inClass;
}
/** Return the line number in the source code given the character position */
long int Parser::GetLineNumber(size_t pos,bool withoutComments) const
{
// if we have comments we add them to the list
if(withoutComments)
{
pos = this->GetPositionWithComments(pos);
}
unsigned int i=0;
std::vector<size_t>::const_iterator it = m_Positions.begin();
while(it != m_Positions.end())
{
if(pos<=(*it))
{
return i;
}
i++;
it++;
}
return 0;
}
/** Find public area in source code. */
void Parser::FindPublicArea(size_t &before, size_t &after, size_t startPos) const
{
before = 0;
after = 0;
// First look if public is before protected and private
size_t pub = this->FindArea("public", startPos);
size_t priv = this->FindArea("private", startPos);
size_t protect = this->FindArea("protected", startPos);
if(pub == std::string::npos)
{
// ok we don't have any public area
before = std::string::npos;
after = std::string::npos;
return;
pub = MAX_CHAR;
}
if(priv == std::string::npos)
{
priv = MAX_CHAR;
}
if(protect == std::string::npos)
{
protect = MAX_CHAR;
}
if(pub>priv || pub>protect)
{
if(pub>=priv && pub<=protect)
{
before = priv;
after = protect;
}
else if(pub<=priv && pub>=protect)
{
before = pub;
after = priv;
}
else
{
before = pub;
size_t eoc = this->FindEndOfClass(pub);
if(eoc != std::string::npos)
{
after = eoc;
}
else
{
after = pub; // end of class
}
}
}
else
{
before = pub;
if(priv<protect)
{
after = priv;
}
else
{
after = protect;
}
}
// If there is nothing after we point to the end of the class
if(after == MAX_CHAR)
{
size_t classpos = this->GetClassPosition(startPos);
if(classpos != std::string::npos)
{
size_t posBrace = m_BufferNoComment.find("{",classpos);
if(posBrace != std::string::npos)
{
size_t end = this->FindClosingChar('{','}',posBrace,true);
if(end != std::string::npos)
{
after = end;
}
}
}
}
}
/** Find the correct area given its name
* This looks for public: or public : */
size_t Parser::FindArea(const char* name,size_t startPos) const
{
size_t pos = m_BufferNoComment.find(name, startPos);
while(pos != std::string::npos)
{
if(m_BufferNoComment[pos+strlen(name)]==':' || this->FindNextWord(pos) == ":")
{
return pos;
}
pos = m_BufferNoComment.find(name, pos+1);
}
return std::string::npos;
}
/** Find protected area in source code. */
void Parser::FindProtectedArea(size_t &before, size_t &after, size_t startPos) const
{
before = 0;
after = 0;
// First look if public is before protected and private
size_t pub = this->FindArea("public", startPos);
size_t priv = this->FindArea("private", startPos);
size_t protect = this->FindArea("protected", startPos);
if(priv == std::string::npos)
{
priv = MAX_CHAR;
}
if(protect == std::string::npos)
{
protect = MAX_CHAR;
}
if(pub == std::string::npos)
{
pub = MAX_CHAR;
}
if(protect>priv || protect>pub)
{
if(protect>=priv && protect<=pub)
{
before = protect;
after = pub;
}
else if(protect<=priv && protect>=pub)
{
before = protect;
after = priv;
}
else
{
before = protect;
size_t eoc = this->FindEndOfClass(protect);
if(eoc != std::string::npos)
{
after = eoc;
}
else
{
after = protect; // end of class
}
}
}
else
{
before = protect;
if(priv<pub)
{
after = priv;
}
else
{
after = pub;
}
}
// If there is nothing after we point to the end of the class
if(after == MAX_CHAR)
{
size_t classpos = this->GetClassPosition(startPos);
if(classpos != std::string::npos)
{
size_t posBrace = m_BufferNoComment.find("{",classpos);
if(posBrace != std::string::npos)
{
size_t end = this->FindClosingChar('{','}',posBrace,true);
if(end != std::string::npos)
{
after = end;
}
}
}
}
}
/** Find the end of the class */
size_t Parser::FindEndOfClass(size_t position) const
{
if(position == std::string::npos)
{
position = 0;
}
// Try to find the end of the class
size_t endclass = m_BufferNoComment.find("}",position);
while(endclass != std::string::npos)
{
bool isClass = true;
// if the next char is not a semicolon this cannot be a class
for(size_t i=endclass+1;i<m_BufferNoComment.size();i++)
{
if( (m_BufferNoComment[i] != ' ') && (m_BufferNoComment[i] != '\r')
&& (m_BufferNoComment[i] != '\n') && (m_BufferNoComment[i] != ';')
)
{
isClass = false;
break;
}
if(m_BufferNoComment[i] == ';')
{
break;
}