GCC Code Coverage Report


Directory: ./
File: src/PFileParser.cpp
Date: 2025-11-27 16:44:16
Exec Total Coverage
Lines: 374 422 88.6%
Functions: 53 58 91.4%
Branches: 370 495 74.7%

Line Branch Exec Source
1
2 /***************************************
3 Auteur : Pierre Aubert
4 Mail : pierre.aubert@lapp.in2p3.fr
5 Licence : CeCILL-C
6 ****************************************/
7
8 #include "PFileParser.h"
9
10 ///Constructeur de PFileParser
11
3/3
✓ Branch 0 (3→4) taken 73 times.
✓ Branch 2 (4→5) taken 73 times.
✓ Branch 4 (5→6) taken 73 times.
73 PFileParser::PFileParser(){
12
1/1
✓ Branch 0 (8→9) taken 73 times.
73 initialisationPFileParser();
13 73 }
14
15 ///Destructeur de PFileParser
16 77 PFileParser::~PFileParser(){
17
18 77 }
19
20 ///Fonction qui ouvre le fichier que l'on va parser
21 /** @param fileName : nom du fichier à ouvrir
22 * @return true si la fonction à réussie, false sinon
23 */
24 25 bool PFileParser::open(const PPath & fileName){
25 25 p_fileName = fileName;
26
2/2
✓ Branch 0 (3→4) taken 25 times.
✓ Branch 2 (4→5) taken 25 times.
25 p_fileContent = fileName.loadFileContent();
27 25 p_nbTotalChar = p_fileContent.size();
28 25 return (p_fileContent != "");
29 }
30
31 ///Initialise la liste des caractères blancs
32 /** @param whiteSpace : liste des caractères blancs
33 * Se sont les caractères que l'on ne prend jamais en compte
34 */
35 35 void PFileParser::setWhiteSpace(const PString & whiteSpace){
36 35 p_listWhiteSpace = whiteSpace;
37 35 }
38
39 ///Initialise la liste des caractères séparateurs
40 /** @param separator : liste des caractères séparateurs
41 * Se sont les caractères que l'on ne prend en compte un par un
42 */
43 39 void PFileParser::setSeparator(const PString & separator){
44 39 p_listSeparator = separator;
45 39 }
46
47 ///Set the file content
48 /** @param fileContent : file content
49 */
50 49 void PFileParser::setFileContent(const PString & fileContent){
51 49 p_fileContent = fileContent;
52 49 p_nbTotalChar = p_fileContent.size();
53 49 }
54
55 ///Sets the escape character of the PFileParser
56 /** @param escapeChar : escape character of the PFileParser
57 */
58 30 void PFileParser::setEscapeChar(char escapeChar){
59 30 p_echapChar = escapeChar;
60 30 }
61
62 ///Set the current location of the PFileParser
63 /** @param location : current location of the PFileParser
64 */
65 1 void PFileParser::setLocation(const PLocation & location){
66 1 setLine(location.getLine());
67 1 setColumn(location.getColumn());
68 1 p_fileName = location.getFileName();
69 1 }
70
71 ///Set the index of the current char
72 /** @param index : index of the current char
73 */
74 8 void PFileParser::setCurrentCharIdx(size_t index){
75 8 p_currentChar = index;
76 8 }
77
78 ///Set the current line of the PFileParser
79 /** @param currentLine : current line of the PFileParser
80 */
81 2 void PFileParser::setLine(size_t currentLine){
82 2 p_currentLine = currentLine;
83 2 }
84
85 ///Set the current column of the PFileParser
86 /** @param currentCol : current column of the PFileParser
87 */
88 2 void PFileParser::setColumn(size_t currentCol){
89 2 p_currentLineFirstColumn = currentCol;
90 2 }
91
92 ///Dit si on est à la fin du fichier
93 /** @return true si on est à la fin du fichier, false sinon
94 */
95 2424 bool PFileParser::isEndOfFile() const{
96 2424 return (p_currentChar >= p_nbTotalChar);
97 }
98
99 ///Remember the current position of the PFileParser in the current file
100 120 void PFileParser::pushPosition(){
101 120 p_vecPosition.push_back(p_currentChar);
102 120 p_vecLine.push_back(p_currentLine);
103 120 }
104
105 ///Get to the last saved position of the PFileParser in the current file
106 99 void PFileParser::popPosition(){
107
2/2
✓ Branch 0 (3→4) taken 1 times.
✓ Branch 1 (3→5) taken 98 times.
99 if(p_vecPosition.size() == 0lu){
108 1 return;
109 }
110 98 p_currentChar = p_vecPosition.back();
111 98 p_currentLine = p_vecLine.back();
112 98 p_vecPosition.pop_back();
113 98 p_vecLine.pop_back();
114 }
115
116 ///Clear the save position of the parser in ther current file
117 21 void PFileParser::clearPosition(){
118 21 p_vecPosition.clear();
119 21 p_vecLine.clear();
120 21 }
121
122 ///Dis si le caractère courant est un caractère blanc
123 /** @return true si caractère courant est un caractère blanc
124 */
125 3 bool PFileParser::isChSpace() const{
126
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 3 times.
3 if(isEndOfFile()) return false;
127 3 return p_listWhiteSpace.find(p_fileContent[p_currentChar]);
128 }
129
130 ///Dis si le caractère courant est un séparateur
131 /** @return true si caractère courant est un séparateur
132 */
133 3 bool PFileParser::isChSeparator() const{
134
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 3 times.
3 if(isEndOfFile()) return false;
135 3 return p_listSeparator.find(p_fileContent[p_currentChar]);
136 }
137
138 ///Gets the escape character of the PFileParser
139 /** @return escape character of the PFileParser
140 */
141 1 char PFileParser::getEscapeChar() const{
142 1 return p_echapChar;
143 }
144
145 ///Fonction qui renvoie le nom du fichier que l'on a ouvert
146 /** @return nom du fichier que l'on a ouvert
147 */
148 2 PPath PFileParser::getFileName() const{
149 2 return p_fileName;
150 }
151
152 ///Get the next token
153 /** @return next token
154 */
155 22 PString PFileParser::getNextToken(){
156
1/1
✓ Branch 0 (2→3) taken 22 times.
22 PString dummySkipedStr("");
157
1/1
✓ Branch 0 (3→4) taken 22 times.
44 return getNextToken(dummySkipedStr);
158 22 }
159
160 ///Get the next token and return also the skipped characters until the next token
161 /** @param[out] skippedStr : string of skipped characters
162 * @return next token
163 */
164 26 PString PFileParser::getNextToken(PString & skippedStr){
165
4/4
✓ Branch 0 (2→3) taken 26 times.
✓ Branch 2 (3→4) taken 12 times.
✓ Branch 3 (3→6) taken 14 times.
✓ Branch 4 (4→5) taken 12 times.
26 if(isEndOfFile()) return "";
166
1/1
✓ Branch 0 (6→7) taken 14 times.
14 char ch = p_fileContent[p_currentChar];
167
7/8
✓ Branch 0 (16→17) taken 18 times.
✓ Branch 2 (17→18) taken 18 times.
✗ Branch 3 (17→21) not taken.
✓ Branch 4 (18→19) taken 18 times.
✓ Branch 6 (19→20) taken 4 times.
✓ Branch 7 (19→21) taken 14 times.
✓ Branch 8 (22→8) taken 4 times.
✓ Branch 9 (22→23) taken 14 times.
18 while(!isEndOfFile() && p_listWhiteSpace.find(ch)){
168
1/1
✓ Branch 0 (8→9) taken 4 times.
4 skippedStr += ch;
169
1/1
✓ Branch 0 (9→10) taken 4 times.
4 incrementCurrentChar();
170
2/4
✓ Branch 0 (10→11) taken 4 times.
✗ Branch 2 (11→12) not taken.
✓ Branch 3 (11→14) taken 4 times.
✗ Branch 4 (12→13) not taken.
4 if(isEndOfFile()) return "";
171
1/1
✓ Branch 0 (14→15) taken 4 times.
4 ch = p_fileContent[p_currentChar];
172 }
173 //We are sur ethe current char is not a white character
174
7/8
✓ Branch 0 (23→24) taken 14 times.
✓ Branch 2 (24→25) taken 7 times.
✓ Branch 3 (24→28) taken 7 times.
✓ Branch 4 (25→26) taken 7 times.
✓ Branch 6 (26→27) taken 7 times.
✗ Branch 7 (26→28) not taken.
✓ Branch 8 (29→30) taken 7 times.
✓ Branch 9 (29→37) taken 7 times.
14 if(p_listSeparator.find(ch) && !isEndOfFile()){ //If is it a separator, we stop
175
1/1
✓ Branch 0 (30→31) taken 7 times.
7 incrementCurrentChar();
176
1/1
✓ Branch 0 (31→32) taken 7 times.
7 PString s("");
177
1/1
✓ Branch 0 (32→33) taken 7 times.
7 s += ch;
178
1/1
✓ Branch 0 (33→34) taken 7 times.
7 return s;
179 7 }
180 //If not we get all characters until the next white character or separator character
181
1/1
✓ Branch 0 (37→38) taken 7 times.
7 PString buf("");
182
9/11
✓ Branch 0 (47→48) taken 15 times.
✓ Branch 2 (48→49) taken 15 times.
✗ Branch 3 (48→54) not taken.
✓ Branch 4 (49→50) taken 15 times.
✓ Branch 6 (50→51) taken 12 times.
✓ Branch 7 (50→54) taken 3 times.
✓ Branch 8 (51→52) taken 12 times.
✓ Branch 10 (52→53) taken 12 times.
✗ Branch 11 (52→54) not taken.
✓ Branch 12 (55→39) taken 12 times.
✓ Branch 13 (55→56) taken 3 times.
15 while(!isEndOfFile() && !p_listWhiteSpace.find(ch) && !p_listSeparator.find(ch)){
183
1/1
✓ Branch 0 (39→40) taken 12 times.
12 buf += ch;
184
1/1
✓ Branch 0 (40→41) taken 12 times.
12 incrementCurrentChar();
185
4/4
✓ Branch 0 (41→42) taken 12 times.
✓ Branch 2 (42→43) taken 4 times.
✓ Branch 3 (42→45) taken 8 times.
✓ Branch 4 (43→44) taken 4 times.
12 if(isEndOfFile()){return buf;}
186
1/1
✓ Branch 0 (45→46) taken 8 times.
8 ch = p_fileContent[p_currentChar];
187 }
188
1/1
✓ Branch 0 (56→57) taken 3 times.
3 return buf;
189 7 }
190
191 ///Fonction qui renvoie le prochain caractère du fichier courant
192 /** @return prochain caractère du fichier courant ou le caractère NULL si on est à la fin
193 */
194 7 char PFileParser::getNextChar(){
195 7 incrementCurrentChar();
196
1/2
✓ Branch 0 (3→4) taken 7 times.
✗ Branch 1 (3→6) not taken.
7 if(p_currentChar < p_nbTotalChar){
197 7 char ch = p_fileContent[p_currentChar];
198 7 return ch;
199 }else{
200 p_currentChar = p_nbTotalChar;
201 return '\0';
202 }
203 }
204
205 ///Renvoie la chaine de caractère du caractère courant jusqu'à patern comprise
206 /** @param patern : séquence d'arrêt
207 * @return chaine de caractère du caractère courant jusqu'à patern comprise
208 */
209 48 PString PFileParser::getUntilKey(const PString & patern){
210
6/8
✓ Branch 0 (3→4) taken 47 times.
✓ Branch 1 (3→7) taken 1 times.
✓ Branch 2 (4→5) taken 47 times.
✗ Branch 3 (4→7) not taken.
✗ Branch 4 (6→7) not taken.
✓ Branch 5 (6→8) taken 47 times.
✓ Branch 6 (9→10) taken 1 times.
✓ Branch 7 (9→11) taken 47 times.
48 if(patern == "" || p_nbTotalChar == 0lu || isEndOfFile()) return "";
211
3/3
✓ Branch 0 (11→12) taken 47 times.
✓ Branch 2 (12→13) taken 47 times.
✓ Branch 4 (13→14) taken 47 times.
94 return getUntilKeyWithoutPatern(patern) + patern;
212 }
213
214 ///Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu
215 /** @param patern : séquence d'arrêt
216 * @return chaine de caractère du caractère courant jusqu'à patern exclu
217 */
218 129 PString PFileParser::getUntilKeyWithoutPatern(const PString & patern){
219
9/11
✓ Branch 0 (2→3) taken 129 times.
✓ Branch 2 (3→4) taken 129 times.
✗ Branch 3 (3→7) not taken.
✓ Branch 4 (4→5) taken 129 times.
✗ Branch 5 (4→7) not taken.
✓ Branch 6 (5→6) taken 129 times.
✓ Branch 8 (6→7) taken 1 times.
✓ Branch 9 (6→8) taken 128 times.
✓ Branch 10 (9→10) taken 1 times.
✓ Branch 11 (9→12) taken 128 times.
✓ Branch 12 (10→11) taken 1 times.
129 if(patern == "" || p_nbTotalChar == 0lu || isEndOfFile()) return "";
220 128 size_t sizePatern(patern.size());
221
1/1
✓ Branch 0 (15→16) taken 128 times.
128 std::string out(""); //on évite les petits désagréments
222 128 size_t sizeSrc(p_nbTotalChar - p_currentChar);
223 128 size_t beginTest(0lu), beginLine(0lu), beginI(0lu), nbMatch(0lu);
224
2/2
✓ Branch 0 (40→18) taken 644 times.
✓ Branch 1 (40→41) taken 2 times.
646 for(size_t i(0lu); i < sizeSrc; ++i){
225
6/7
✓ Branch 0 (18→19) taken 644 times.
✓ Branch 2 (20→21) taken 142 times.
✓ Branch 3 (20→23) taken 502 times.
✓ Branch 4 (21→22) taken 142 times.
✗ Branch 5 (21→23) not taken.
✓ Branch 6 (24→25) taken 142 times.
✓ Branch 7 (24→31) taken 502 times.
644 if(p_fileContent[p_currentChar] == patern[nbMatch] && !p_currentCharEchaped){ //si le caractère i est le même que le caractère nbMatch
226
2/2
✓ Branch 0 (25→26) taken 130 times.
✓ Branch 1 (25→27) taken 12 times.
142 if(nbMatch == 0lu){ //c'est le premier qu'on teste
227 130 beginTest = p_currentChar; //il faut donc se rappeler où on a commencer à faire le test
228 130 beginLine = p_currentLine;
229 130 beginI = i;
230 }
231 142 ++nbMatch; //la prochaîne fois on testera le caractère suivant
232
2/2
✓ Branch 0 (27→28) taken 126 times.
✓ Branch 1 (27→38) taken 16 times.
142 if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
233
1/1
✓ Branch 0 (28→29) taken 126 times.
126 incrementCurrentChar();
234
1/1
✓ Branch 0 (29→30) taken 126 times.
126 return out;
235 }
236 }else{ //si le caractère i n'est pas le même caractère que nbMatch
237
2/2
✓ Branch 0 (31→32) taken 498 times.
✓ Branch 1 (31→34) taken 4 times.
502 if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant
238
2/2
✓ Branch 0 (32→33) taken 498 times.
✓ Branch 2 (33→37) taken 498 times.
498 out += p_fileContent[p_currentChar]; //on ne change rien à ce caractère
239 }else{ //si on avais déjà tester des caractères avant
240
2/2
✓ Branch 0 (34→35) taken 4 times.
✓ Branch 2 (35→36) taken 4 times.
4 out += p_fileContent[beginTest];
241 4 p_currentChar = beginTest;
242 4 p_currentLine = beginLine;
243 4 i = beginI;
244 }
245 502 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
246 502 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
247 }
248
1/1
✓ Branch 0 (38→39) taken 518 times.
518 incrementCurrentChar();
249 }
250
1/1
✓ Branch 0 (41→42) taken 2 times.
2 return out;
251 128 }
252
253 ///Parse a string until the patern is found, only if it has not strNotBeforeEndPatern before it
254 /** @param patern : patern to be found
255 * @param strNotBeforeEndPatern : string which cannot be found before the patern, otherwise the patern is not considered as the end
256 * @return string unit patern, without it
257 */
258 1 PString PFileParser::getUntilKeyWithoutPaternExclude(const PString & patern, const PString & strNotBeforeEndPatern){
259
6/11
✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
✗ Branch 3 (3→7) not taken.
✓ Branch 4 (4→5) taken 1 times.
✗ Branch 5 (4→7) not taken.
✓ Branch 6 (5→6) taken 1 times.
✗ Branch 8 (6→7) not taken.
✓ Branch 9 (6→8) taken 1 times.
✗ Branch 10 (9→10) not taken.
✓ Branch 11 (9→12) taken 1 times.
✗ Branch 12 (10→11) not taken.
1 if(patern == "" || p_nbTotalChar == 0lu || isEndOfFile()) return "";
260
1/1
✓ Branch 0 (14→15) taken 1 times.
1 std::string out(""); //on évite les petits désagréments
261 1 bool prevSkipSpace(p_dontSkipSpace);
262 1 p_dontSkipSpace = true;
263 1 bool skiptNextEnd(false);
264
2/3
✓ Branch 0 (33→34) taken 34 times.
✓ Branch 2 (34→17) taken 34 times.
✗ Branch 3 (34→35) not taken.
34 while(!isEndOfFile()){
265
3/3
✓ Branch 0 (17→18) taken 34 times.
✓ Branch 2 (18→19) taken 1 times.
✓ Branch 3 (18→21) taken 33 times.
34 if(isMatch(strNotBeforeEndPatern)){
266
1/1
✓ Branch 0 (19→20) taken 1 times.
1 out += strNotBeforeEndPatern;
267 1 skiptNextEnd = true;
268
2/2
✓ Branch 0 (21→22) taken 1 times.
✓ Branch 1 (21→25) taken 32 times.
33 }else if(skiptNextEnd){
269 1 skiptNextEnd = false;
270
2/2
✓ Branch 0 (22→23) taken 1 times.
✓ Branch 2 (23→24) taken 1 times.
1 out += p_fileContent[p_currentChar];
271
1/1
✓ Branch 0 (24→32) taken 1 times.
1 incrementCurrentChar();
272
3/3
✓ Branch 0 (25→26) taken 32 times.
✓ Branch 2 (26→27) taken 1 times.
✓ Branch 3 (26→29) taken 31 times.
32 }else if(isMatch(patern)){
273 1 p_dontSkipSpace = prevSkipSpace;
274
1/1
✓ Branch 0 (27→28) taken 1 times.
1 return out;
275 }else{
276
2/2
✓ Branch 0 (29→30) taken 31 times.
✓ Branch 2 (30→31) taken 31 times.
31 out += p_fileContent[p_currentChar];
277
1/1
✓ Branch 0 (31→32) taken 31 times.
31 incrementCurrentChar();
278 }
279 }
280 p_dontSkipSpace = prevSkipSpace;
281 return out;
282 1 }
283
284 ///Get the string until end sequence and take account recursive patern (embeded strings)
285 /** @param patern : end patern
286 * @param beginPatern : definition of new embeded string
287 * @param allowedCharAfterBegin : characters allowed after the beginPatern
288 * @return output string
289 */
290 1 PString PFileParser::getUntilKeyWithoutPaternRecurse(const PString & patern, const PString & beginPatern,
291 const PString & allowedCharAfterBegin)
292 {
293
8/14
✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
✗ Branch 3 (3→9) not taken.
✓ Branch 4 (4→5) taken 1 times.
✓ Branch 6 (5→6) taken 1 times.
✗ Branch 7 (5→9) not taken.
✓ Branch 8 (6→7) taken 1 times.
✗ Branch 9 (6→9) not taken.
✓ Branch 10 (7→8) taken 1 times.
✗ Branch 12 (8→9) not taken.
✓ Branch 13 (8→10) taken 1 times.
✗ Branch 14 (11→12) not taken.
✓ Branch 15 (11→14) taken 1 times.
✗ Branch 16 (12→13) not taken.
1 if(patern == "" || beginPatern == "" || p_nbTotalChar == 0lu || isEndOfFile()) return "";
294 1 bool prevSkipSpace(p_dontSkipSpace);
295 1 p_dontSkipSpace = true;
296
1/1
✓ Branch 0 (16→17) taken 1 times.
1 std::string out("");
297 1 long int nbEmbeded(1lu);
298
2/3
✓ Branch 0 (36→37) taken 34 times.
✓ Branch 2 (37→19) taken 34 times.
✗ Branch 3 (37→38) not taken.
34 while(!isEndOfFile()){
299
3/3
✓ Branch 0 (19→20) taken 34 times.
✓ Branch 2 (20→21) taken 2 times.
✓ Branch 3 (20→25) taken 32 times.
34 if(isMatch(patern)){
300 2 --nbEmbeded;
301
2/2
✓ Branch 0 (21→22) taken 1 times.
✓ Branch 1 (21→24) taken 1 times.
2 if(nbEmbeded <= 0l){
302 1 p_dontSkipSpace = prevSkipSpace;
303
1/1
✓ Branch 0 (22→23) taken 1 times.
1 return out;
304 }else{
305
1/1
✓ Branch 0 (24→35) taken 1 times.
1 out += patern;
306 }
307
3/3
✓ Branch 0 (25→26) taken 32 times.
✓ Branch 2 (26→27) taken 1 times.
✓ Branch 3 (26→32) taken 31 times.
32 }else if(isMatch(beginPatern)){
308
3/4
✓ Branch 0 (27→28) taken 1 times.
✓ Branch 2 (28→29) taken 1 times.
✓ Branch 4 (29→30) taken 1 times.
✗ Branch 5 (29→35) not taken.
1 if(allowedCharAfterBegin.find(p_fileContent[p_currentChar])){
309
1/1
✓ Branch 0 (30→31) taken 1 times.
1 out += beginPatern;
310 1 ++nbEmbeded;
311 }
312 }else{
313
2/2
✓ Branch 0 (32→33) taken 31 times.
✓ Branch 2 (33→34) taken 31 times.
31 out += p_fileContent[p_currentChar];
314
1/1
✓ Branch 0 (34→35) taken 31 times.
31 incrementCurrentChar();
315 }
316 }
317 p_dontSkipSpace = prevSkipSpace;
318 return out;
319 1 }
320
321 ///Get the string until end sequence and take account recursive patern (embeded strings)
322 /** @param patern : end patern
323 * @param beginPatern : definition of new embeded string
324 * @param echapExpr : echap expression
325 * @return output string
326 */
327 2 PString PFileParser::getUntilKeyWithoutPaternRecurseExclude(const PString & patern, const PString & beginPatern,
328 const PString & echapExpr)
329 {
330
8/14
✓ Branch 0 (2→3) taken 2 times.
✓ Branch 2 (3→4) taken 2 times.
✗ Branch 3 (3→9) not taken.
✓ Branch 4 (4→5) taken 2 times.
✓ Branch 6 (5→6) taken 2 times.
✗ Branch 7 (5→9) not taken.
✓ Branch 8 (6→7) taken 2 times.
✗ Branch 9 (6→9) not taken.
✓ Branch 10 (7→8) taken 2 times.
✗ Branch 12 (8→9) not taken.
✓ Branch 13 (8→10) taken 2 times.
✗ Branch 14 (11→12) not taken.
✓ Branch 15 (11→14) taken 2 times.
✗ Branch 16 (12→13) not taken.
2 if(patern == "" || beginPatern == "" || p_nbTotalChar == 0lu || isEndOfFile()) return "";
331 2 bool prevSkipSpace(p_dontSkipSpace);
332 2 p_dontSkipSpace = true;
333
1/1
✓ Branch 0 (16→17) taken 2 times.
2 std::string out("");
334 2 long int nbEmbeded(1lu);
335 2 bool skiptNextEnd(false);
336
2/3
✓ Branch 0 (41→42) taken 32 times.
✓ Branch 2 (42→19) taken 32 times.
✗ Branch 3 (42→43) not taken.
32 while(!isEndOfFile()){
337
3/3
✓ Branch 0 (19→20) taken 32 times.
✓ Branch 2 (20→21) taken 2 times.
✓ Branch 3 (20→23) taken 30 times.
32 if(isMatch(echapExpr)){
338
1/1
✓ Branch 0 (21→22) taken 2 times.
2 out += echapExpr;
339 2 skiptNextEnd = true;
340
2/2
✓ Branch 0 (23→24) taken 2 times.
✓ Branch 1 (23→27) taken 28 times.
30 }else if(skiptNextEnd){
341 2 skiptNextEnd = false;
342
2/2
✓ Branch 0 (24→25) taken 2 times.
✓ Branch 2 (25→26) taken 2 times.
2 out += p_fileContent[p_currentChar];
343
1/1
✓ Branch 0 (26→40) taken 2 times.
2 incrementCurrentChar();
344
3/3
✓ Branch 0 (27→28) taken 28 times.
✓ Branch 2 (28→29) taken 2 times.
✓ Branch 3 (28→33) taken 26 times.
28 }else if(isMatch(patern)){
345 2 --nbEmbeded;
346
1/2
✓ Branch 0 (29→30) taken 2 times.
✗ Branch 1 (29→32) not taken.
2 if(nbEmbeded <= 0l){
347 2 p_dontSkipSpace = prevSkipSpace;
348
1/1
✓ Branch 0 (30→31) taken 2 times.
2 return out;
349 }else{
350 out += patern;
351 }
352
2/3
✓ Branch 0 (33→34) taken 26 times.
✗ Branch 2 (34→35) not taken.
✓ Branch 3 (34→37) taken 26 times.
26 }else if(isMatch(beginPatern)){
353 out += beginPatern;
354 ++nbEmbeded;
355 }else{
356
2/2
✓ Branch 0 (37→38) taken 26 times.
✓ Branch 2 (38→39) taken 26 times.
26 out += p_fileContent[p_currentChar];
357
1/1
✓ Branch 0 (39→40) taken 26 times.
26 incrementCurrentChar();
358 }
359 }
360 p_dontSkipSpace = prevSkipSpace;
361 return out;
362 2 }
363
364 ///Get the string until end sequence and take account recursive patern (embeded strings)
365 /** @param patern : end patern
366 * @param beginPatern : definition of new embeded string
367 * @return output string
368 */
369 2 PString PFileParser::getUntilKeyWithoutPaternRecurse(const PString & patern, const PString & beginPatern)
370 {
371
8/14
✓ Branch 0 (2→3) taken 2 times.
✓ Branch 2 (3→4) taken 2 times.
✗ Branch 3 (3→9) not taken.
✓ Branch 4 (4→5) taken 2 times.
✓ Branch 6 (5→6) taken 2 times.
✗ Branch 7 (5→9) not taken.
✓ Branch 8 (6→7) taken 2 times.
✗ Branch 9 (6→9) not taken.
✓ Branch 10 (7→8) taken 2 times.
✗ Branch 12 (8→9) not taken.
✓ Branch 13 (8→10) taken 2 times.
✗ Branch 14 (11→12) not taken.
✓ Branch 15 (11→14) taken 2 times.
✗ Branch 16 (12→13) not taken.
2 if(patern == "" || beginPatern == "" || p_nbTotalChar == 0lu || isEndOfFile()) return "";
372 2 bool prevSkipSpace(p_dontSkipSpace);
373 2 p_dontSkipSpace = true;
374
1/1
✓ Branch 0 (16→17) taken 2 times.
2 std::string out("");
375 2 long int nbEmbeded(1l);
376
2/3
✓ Branch 0 (33→34) taken 45 times.
✓ Branch 2 (34→19) taken 45 times.
✗ Branch 3 (34→35) not taken.
45 while(!isEndOfFile()){
377
3/3
✓ Branch 0 (19→20) taken 45 times.
✓ Branch 2 (20→21) taken 3 times.
✓ Branch 3 (20→25) taken 42 times.
45 if(isMatch(patern)){
378 3 --nbEmbeded;
379
2/2
✓ Branch 0 (21→22) taken 2 times.
✓ Branch 1 (21→24) taken 1 times.
3 if(nbEmbeded <= 0l){
380 2 p_dontSkipSpace = prevSkipSpace;
381
1/1
✓ Branch 0 (22→23) taken 2 times.
2 return out;
382 }else{
383
1/1
✓ Branch 0 (24→32) taken 1 times.
1 out += patern;
384 }
385
3/3
✓ Branch 0 (25→26) taken 42 times.
✓ Branch 2 (26→27) taken 1 times.
✓ Branch 3 (26→29) taken 41 times.
42 }else if(isMatch(beginPatern)){
386
1/1
✓ Branch 0 (27→28) taken 1 times.
1 out += beginPatern;
387 1 ++nbEmbeded;
388 }else{
389
2/2
✓ Branch 0 (29→30) taken 41 times.
✓ Branch 2 (30→31) taken 41 times.
41 out += p_fileContent[p_currentChar];
390
1/1
✓ Branch 0 (31→32) taken 41 times.
41 incrementCurrentChar();
391 }
392 }
393 p_dontSkipSpace = prevSkipSpace;
394 return out;
395 2 }
396
397 ///Get string composed of the characters in the string charset
398 /** @param charset : set of the available characters to get the current string
399 * @return corresponding string
400 */
401 67 PString PFileParser::getStrComposedOf(const PString & charset){
402
1/1
✓ Branch 0 (2→3) taken 67 times.
67 PString tmpWhiteSpace(p_listWhiteSpace.eraseChar(charset));
403
3/3
✓ Branch 0 (3→4) taken 67 times.
✓ Branch 2 (4→5) taken 53 times.
✓ Branch 3 (4→6) taken 14 times.
67 if(tmpWhiteSpace != ""){
404
1/1
✓ Branch 0 (5→6) taken 53 times.
53 skipChars(tmpWhiteSpace);
405 }
406
1/1
✓ Branch 0 (8→9) taken 67 times.
67 std::string out("");
407 67 bool isInCharSet(true);
408
7/7
✓ Branch 0 (17→18) taken 270 times.
✓ Branch 2 (18→19) taken 265 times.
✓ Branch 3 (18→21) taken 5 times.
✓ Branch 4 (19→20) taken 203 times.
✓ Branch 5 (19→21) taken 62 times.
✓ Branch 6 (22→11) taken 203 times.
✓ Branch 7 (22→23) taken 67 times.
270 while(!isEndOfFile() && isInCharSet){
409
1/1
✓ Branch 0 (11→12) taken 203 times.
203 char ch = p_fileContent[p_currentChar];
410
1/1
✓ Branch 0 (12→13) taken 203 times.
203 isInCharSet = charset.find(ch);
411
2/2
✓ Branch 0 (13→14) taken 141 times.
✓ Branch 1 (13→16) taken 62 times.
203 if(isInCharSet){
412
1/1
✓ Branch 0 (14→15) taken 141 times.
141 out += ch;
413
1/1
✓ Branch 0 (15→16) taken 141 times.
141 incrementCurrentChar();
414 }
415 }
416
1/1
✓ Branch 0 (23→24) taken 67 times.
134 return out;
417 67 }
418
419 ///Get the current parsed row
420 /** @return current parsed row
421 */
422 2 PString PFileParser::getCurrentRow() const{
423
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 2 times.
2 if(p_fileContent.empty()) return "";
424 2 size_t currentCharIndex(p_currentChar);
425 2 char ch = p_fileContent[currentCharIndex];
426 2 size_t indexBeginRow(currentCharIndex);
427 2 size_t indexEndRow(currentCharIndex);
428
1/2
✓ Branch 0 (6→7) taken 2 times.
✗ Branch 1 (6→16) not taken.
2 if(ch != '\n'){
429
5/6
✓ Branch 0 (10→11) taken 25 times.
✓ Branch 1 (10→14) taken 2 times.
✓ Branch 2 (12→13) taken 25 times.
✗ Branch 3 (12→14) not taken.
✓ Branch 4 (15→8) taken 25 times.
✓ Branch 5 (15→16) taken 2 times.
27 while(p_fileContent[indexEndRow] != '\n' && !isEndOfFile()){
430 25 ++indexEndRow;
431 }
432 }
433
1/4
✗ Branch 0 (16→17) not taken.
✓ Branch 1 (16→19) taken 2 times.
✗ Branch 2 (17→18) not taken.
✗ Branch 3 (17→19) not taken.
2 if(ch == '\n' && indexBeginRow != 0lu){
434 --indexBeginRow;
435 }
436
6/6
✓ Branch 0 (22→23) taken 6 times.
✓ Branch 1 (22→25) taken 1 times.
✓ Branch 2 (23→24) taken 5 times.
✓ Branch 3 (23→25) taken 1 times.
✓ Branch 4 (26→20) taken 5 times.
✓ Branch 5 (26→27) taken 2 times.
7 while(p_fileContent[indexBeginRow] != '\n' && indexBeginRow != 0lu){
437 5 --indexBeginRow;
438 }
439
2/2
✓ Branch 0 (28→29) taken 1 times.
✓ Branch 1 (28→30) taken 1 times.
2 if(p_fileContent[indexBeginRow] == '\n'){indexBeginRow++;}
440
2/2
✓ Branch 0 (30→31) taken 2 times.
✓ Branch 2 (31→32) taken 2 times.
2 return p_fileContent.substr(indexBeginRow, indexEndRow - indexBeginRow);
441 }
442
443 ///Says if the patern match with the current caracters of the PFileParser
444 /** @param patern : patern we want to check (this patern should not begin with white caracters)
445 * @return true if the patern match, false otherwise
446 * If the patern match, the current char will be in the next char of the patern
447 */
448 1325 bool PFileParser::isMatch(const PString & patern){
449
6/8
✓ Branch 0 (3→4) taken 1325 times.
✗ Branch 1 (3→7) not taken.
✓ Branch 2 (5→6) taken 1302 times.
✓ Branch 3 (5→7) taken 23 times.
✗ Branch 4 (6→7) not taken.
✓ Branch 5 (6→8) taken 1302 times.
✓ Branch 6 (9→10) taken 23 times.
✓ Branch 7 (9→11) taken 1302 times.
1325 if(patern == "" || isEndOfFile() || p_currentCharEchaped) return false;
450 1302 skipWhiteSpace();
451 1302 size_t nbCharPatern(patern.size());
452
2/2
✓ Branch 0 (13→14) taken 5 times.
✓ Branch 1 (13→15) taken 1297 times.
1302 if(p_currentChar + nbCharPatern > p_nbTotalChar){return false;}
453 1297 bool match = true;
454 1297 size_t i(0lu);
455
4/4
✓ Branch 0 (19→20) taken 1756 times.
✓ Branch 1 (19→21) taken 901 times.
✓ Branch 2 (20→16) taken 1360 times.
✓ Branch 3 (20→21) taken 396 times.
2657 while(match && i < nbCharPatern){
456 1360 match = (patern[i] == p_fileContent[p_currentChar + i]);
457 1360 ++i;
458 }
459
2/2
✓ Branch 0 (21→22) taken 396 times.
✓ Branch 1 (21→23) taken 901 times.
1297 if(match){
460 396 incrementCurrentChar(nbCharPatern);
461 }
462 1297 return match;
463 }
464
465 ///Do a isMatch and then go back at the previous position
466 /** @param patern : patern we want to check (this patern should not begin with white caracters)
467 * @return true if the patern match, false otherwise
468 * If the patern match, the current char will be in the next char of the patern
469 */
470 84 bool PFileParser::isMatchRewind(const PString & patern){
471 84 pushPosition();
472 84 bool b = isMatch(patern);
473 84 popPosition();
474 84 return b;
475 }
476
477 ///Match a sequence of token in a vector
478 /** @param patern : set of token to match in this order and totally
479 * @param alwaysPopBack : true to make the PFileParser at the exact same place before the check even is the sequence matches
480 * @return true if the full sequence matches, false otherwise
481 */
482 1 bool PFileParser::isMatchSeq(const PVecString & patern, bool alwaysPopBack){
483
1/1
✓ Branch 0 (2→3) taken 1 times.
1 pushPosition();
484 1 PVecString::const_iterator it(patern.begin());
485 1 bool matchPatern(true);
486
5/6
✓ Branch 0 (18→19) taken 4 times.
✓ Branch 1 (18→21) taken 1 times.
✓ Branch 2 (19→20) taken 4 times.
✗ Branch 3 (19→21) not taken.
✓ Branch 4 (22→5) taken 4 times.
✓ Branch 5 (22→23) taken 1 times.
10 while(it != patern.end() && matchPatern){
487
1/1
✓ Branch 0 (7→8) taken 4 times.
4 matchPatern = isMatch(*it);
488 ++it;
489 }
490
2/4
✓ Branch 0 (23→24) taken 1 times.
✗ Branch 1 (23→25) not taken.
✗ Branch 2 (24→25) not taken.
✓ Branch 3 (24→26) taken 1 times.
1 if(!matchPatern || alwaysPopBack){
491 popPosition();
492 }
493 1 return matchPatern;
494 }
495
496 ///Says if the patern match with the current caracters of the PFileParser
497 /** @param patern : patern we want to check (this patern should not begin with white caracters)
498 * @param forbiddenCharBefore : lisr of characters which cannot be just before the first character of the patern
499 * @return true if the patern match, false otherwise
500 * If the patern match, the current char will be in the next char of the patern
501 */
502 bool PFileParser::isMatch(const PString & patern, const PString & forbiddenCharBefore){
503 if(p_currentChar > 0lu){
504 //If we find a forbidden character before the current char, the patern is canceled
505 if(forbiddenCharBefore.find(p_fileContent[p_currentChar - 1lu])){
506 return false;
507 }
508 }
509 return isMatch(patern);
510 }
511
512 ///Says if the patern match with the current caracters of the PFileParser but treats the string as a token (cannot be part of a word)
513 /** @param patern : patern we want to check (this patern should not begin with white caracters)
514 * @return true if the patern match, false otherwise
515 * If the patern match, the current char will be in the next char of the patern
516 */
517 5 bool PFileParser::isMatchToken(const PString & patern){
518
1/1
✓ Branch 0 (2→3) taken 5 times.
5 pushPosition();
519
3/3
✓ Branch 0 (3→4) taken 5 times.
✓ Branch 2 (4→5) taken 3 times.
✓ Branch 3 (4→7) taken 2 times.
5 if(!isMatch(patern)){
520
1/1
✓ Branch 0 (5→6) taken 3 times.
3 popPosition();
521 3 return false;
522 }
523
1/1
✓ Branch 0 (7→8) taken 2 times.
2 PString letterNumberUnderscore("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
524
1/2
✗ Branch 0 (9→10) not taken.
✓ Branch 1 (9→16) taken 2 times.
2 if(p_currentChar > patern.size()){
525 if(letterNumberUnderscore.find(p_fileContent[p_currentChar - patern.size() - 1lu])){
526 popPosition();
527 return false;
528 }
529 }
530
1/2
✓ Branch 0 (16→17) taken 2 times.
✗ Branch 1 (16→22) not taken.
2 if(p_nbTotalChar > p_currentChar){
531
3/4
✓ Branch 0 (17→18) taken 2 times.
✓ Branch 2 (18→19) taken 2 times.
✗ Branch 4 (19→20) not taken.
✓ Branch 5 (19→22) taken 2 times.
2 if(letterNumberUnderscore.find(p_fileContent[p_currentChar])){
532 popPosition();
533 return false;
534 }
535 }
536 2 return true;
537 2 }
538
539 ///Check the matching between the current caracters and all the string in the vector
540 /** @param patern : vector of the patern we want to check
541 * @return matching patern if there is one, empty string otherwise
542 */
543 3 PString PFileParser::isMatch(const PVecString & patern){
544
3/3
✓ Branch 0 (3→4) taken 1 times.
✓ Branch 1 (3→6) taken 2 times.
✓ Branch 2 (4→5) taken 1 times.
3 if(patern.size() == 0lu) return "";
545 2 PVecString::const_iterator it(patern.begin());
546
2/2
✓ Branch 0 (26→8) taken 3 times.
✓ Branch 1 (26→27) taken 1 times.
8 while(it != patern.end()){
547
4/4
✓ Branch 0 (10→11) taken 3 times.
✓ Branch 2 (11→12) taken 1 times.
✓ Branch 3 (11→16) taken 2 times.
✓ Branch 4 (14→15) taken 1 times.
4 if(isMatch(*it)) return *it;
548 ++it;
549 }
550
1/1
✓ Branch 0 (27→28) taken 1 times.
1 return "";
551 }
552
553 ///Check the matching between the current caracters and all the string in the vector but treats the string as a token (cannot be part of a word)
554 /** @param patern : vector of the patern we want to check
555 * @return matching patern if there is one, empty string otherwise
556 */
557 3 PString PFileParser::isMatchToken(const PVecString & patern){
558
3/3
✓ Branch 0 (3→4) taken 1 times.
✓ Branch 1 (3→6) taken 2 times.
✓ Branch 2 (4→5) taken 1 times.
3 if(patern.size() == 0lu) return "";
559 2 PVecString::const_iterator it(patern.begin());
560
2/2
✓ Branch 0 (26→8) taken 3 times.
✓ Branch 1 (26→27) taken 1 times.
8 while(it != patern.end()){
561
4/4
✓ Branch 0 (10→11) taken 3 times.
✓ Branch 2 (11→12) taken 1 times.
✓ Branch 3 (11→16) taken 2 times.
✓ Branch 4 (14→15) taken 1 times.
4 if(isMatchToken(*it)) return *it;
562 ++it;
563 }
564
1/1
✓ Branch 0 (27→28) taken 1 times.
1 return "";
565 }
566
567 ///Check the matching between the current caracters and all the string in the list of list of string
568 /** @param patern : list of the list of the patern we want to check
569 * @return matching patern if there is one, empty string otherwise
570 */
571 3 PString PFileParser::isMatch(const std::vector<PVecString > & patern){
572
3/3
✓ Branch 0 (3→4) taken 1 times.
✓ Branch 1 (3→6) taken 2 times.
✓ Branch 2 (4→5) taken 1 times.
3 if(patern.size() == 0lu) return "";
573 2 std::vector<PVecString >::const_iterator itList(patern.begin());
574
2/2
✓ Branch 0 (43→8) taken 3 times.
✓ Branch 1 (43→44) taken 1 times.
8 while(itList != patern.end()){
575 3 PVecString::const_iterator it(itList->begin());
576
2/2
✓ Branch 0 (32→12) taken 4 times.
✓ Branch 1 (32→33) taken 2 times.
15 while(it != itList->end()){
577
4/4
✓ Branch 0 (14→15) taken 4 times.
✓ Branch 2 (15→16) taken 1 times.
✓ Branch 3 (15→20) taken 3 times.
✓ Branch 4 (18→19) taken 1 times.
5 if(isMatch(*it)) return *it;
578 ++it;
579 }
580 ++itList;
581 }
582
1/1
✓ Branch 0 (44→45) taken 1 times.
1 return "";
583 }
584
585 ///Check the matching of a sequence in the current file
586 /** @param seq : sequence to be checked
587 * @return matched string
588 */
589 2 PString PFileParser::isMatch(const PParseSeq & seq){
590
1/1
✓ Branch 0 (2→3) taken 2 times.
2 pushPosition();
591
1/1
✓ Branch 0 (3→4) taken 2 times.
2 PString body("");
592
1/1
✓ Branch 0 (4→5) taken 2 times.
2 const PVecParseStep & vecStep = seq.getVecStep();
593 2 PVecParseStep::const_iterator itStep(vecStep.begin());
594 2 bool isParseNextStep(true);
595
5/6
✓ Branch 0 (58→59) taken 5 times.
✓ Branch 1 (58→61) taken 2 times.
✓ Branch 2 (59→60) taken 5 times.
✗ Branch 3 (59→61) not taken.
✓ Branch 4 (62→7) taken 5 times.
✓ Branch 5 (62→63) taken 2 times.
14 while(itStep != vecStep.end() && isParseNextStep){
596
1/1
✓ Branch 0 (9→10) taken 5 times.
5 isParseNextStep = itStep->getIsOptional();
597
1/1
✓ Branch 0 (12→13) taken 5 times.
5 const PVecParseCmd & vecCmd = itStep->getVecCmd();
598 5 bool isMatchedCmd(false);
599 5 PVecParseCmd::const_iterator itCmd(vecCmd.begin());
600
6/6
✓ Branch 0 (43→44) taken 6 times.
✓ Branch 1 (43→46) taken 4 times.
✓ Branch 2 (44→45) taken 5 times.
✓ Branch 3 (44→46) taken 1 times.
✓ Branch 4 (47→15) taken 5 times.
✓ Branch 5 (47→48) taken 5 times.
20 while(itCmd != vecCmd.end() && !isMatchedCmd){
601
2/2
✓ Branch 0 (17→18) taken 5 times.
✓ Branch 2 (18→19) taken 5 times.
5 PString str(itCmd->getStr());
602
2/3
✓ Branch 0 (21→22) taken 5 times.
✓ Branch 2 (22→23) taken 5 times.
✗ Branch 3 (22→25) not taken.
5 if(itCmd->getIsMatch()){
603
1/1
✓ Branch 0 (23→24) taken 5 times.
5 isMatchedCmd = isMatch(str);
604
1/1
✓ Branch 0 (24→32) taken 5 times.
5 body += str;
605 }else{
606 PString res(getStrComposedOf(str));
607 if(res != ""){
608 body += res;
609 isMatchedCmd = true;
610 }
611 }
612 ++itCmd;
613 5 }
614 5 isParseNextStep |= isMatchedCmd;
615 ++itStep;
616 }
617
1/2
✗ Branch 0 (63→64) not taken.
✓ Branch 1 (63→66) taken 2 times.
2 if(!isParseNextStep){
618 popPosition();
619 body = "";
620 }
621 2 return body;
622 }
623
624 ///Says if the current char is a white space
625 /** @return true if the current char is a white space, false if not
626 * If it matchs, the current caracter will be put on a non white space caracter
627 */
628 1 bool PFileParser::isWhiteSpace(){
629
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 1 times.
1 if(isEndOfFile()) return false;
630
1/2
✓ Branch 0 (7→8) taken 1 times.
✗ Branch 1 (7→20) not taken.
1 if(p_listWhiteSpace.find(p_fileContent[p_currentChar])){
631 do{
632 1 incrementCurrentChar();
633
2/6
✗ Branch 0 (12→13) not taken.
✓ Branch 1 (12→16) taken 1 times.
✗ Branch 2 (14→15) not taken.
✗ Branch 3 (14→16) not taken.
✗ Branch 4 (17→18) not taken.
✓ Branch 5 (17→19) taken 1 times.
1 }while(p_listWhiteSpace.find(p_fileContent[p_currentChar]) && !isEndOfFile());
634 1 return true;
635 }else return false;
636 }
637
638 ///Skip the white space if there is at the current caracter position
639 1439 void PFileParser::skipWhiteSpace(){
640
2/2
✓ Branch 0 (2→3) taken 305 times.
✓ Branch 1 (2→4) taken 1134 times.
1439 if(p_dontSkipSpace){return;}
641
2/2
✓ Branch 0 (6→7) taken 190 times.
✓ Branch 1 (6→18) taken 944 times.
1134 if(p_listWhiteSpace.find(p_fileContent[p_currentChar])){
642 do{
643 274 incrementCurrentChar();
644
5/6
✓ Branch 0 (11→12) taken 84 times.
✓ Branch 1 (11→15) taken 190 times.
✓ Branch 2 (13→14) taken 84 times.
✗ Branch 3 (13→15) not taken.
✓ Branch 4 (16→17) taken 84 times.
✓ Branch 5 (16→18) taken 190 times.
274 }while(p_listWhiteSpace.find(p_fileContent[p_currentChar]) && !isEndOfFile());
645 }
646 }
647
648 ///Skip the characters in the given string
649 /** @param chToSkip : set of characters tb skip
650 */
651 53 void PFileParser::skipChars(const PString & chToSkip){
652
1/2
✗ Branch 0 (4→5) not taken.
✓ Branch 1 (4→16) taken 53 times.
53 if(chToSkip.find(p_fileContent[p_currentChar])){
653 do{
654 incrementCurrentChar();
655 }while(chToSkip.find(p_fileContent[p_currentChar]) && !isEndOfFile());
656 }
657 53 }
658
659 ///renvoie la liste des caractères blancs
660 /** @return liste des caractères blancs
661 */
662 PString PFileParser::getWhiteSpace() const{
663 return p_listWhiteSpace;
664 }
665
666 ///renvoie la liste des caractères séparateurs
667 /** @return liste des caractères séparateurs
668 */
669 1 PString PFileParser::getSeparator() const{
670 1 return p_listSeparator;
671 }
672
673 ///Renvoie le caractère courant
674 /** @return caractère courant
675 */
676 62 char PFileParser::getCurrentCh() const{
677
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 62 times.
62 if(isEndOfFile()) return '\0';
678 62 return p_fileContent[p_currentChar];
679 }
680
681 ///Renvoie le caractère courant
682 /** @return caractère courant
683 */
684 1 char PFileParser::getPrevCh() const{
685
2/6
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→6) taken 1 times.
✗ Branch 2 (4→5) not taken.
✗ Branch 3 (4→6) not taken.
✗ Branch 4 (7→8) not taken.
✓ Branch 5 (7→9) taken 1 times.
1 if(isEndOfFile() && p_currentChar > 0lu) return '\0';
686 1 return p_fileContent[p_currentChar - 1lu];
687 }
688
689 ///Get the char at the given index
690 /** @param index : index of the char to get
691 * @return corresponding char or nullchar if index is out of bound
692 */
693 4 char PFileParser::getChar(size_t index) const{
694
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 4 times.
4 if(index >= p_nbTotalChar) return '\0';
695 4 return p_fileContent[index];
696 }
697
698 ///Fonction qui renvoie le numéro de la ligne courante
699 /** @return numéro de la ligne courante
700 */
701 2 size_t PFileParser::getLine() const{
702 2 return p_currentLine;
703 }
704
705 ///Fonction qui renvoie le numéro de la colonne du caractère courant
706 /** @return colonne du caractère courant
707 */
708 75 size_t PFileParser::getColumn() const{
709
2/2
✓ Branch 0 (2→3) taken 72 times.
✓ Branch 1 (2→4) taken 3 times.
75 if(p_currentChar > p_currentLineFirstColumn){
710 72 return p_currentChar - p_currentLineFirstColumn;
711 3 }else{return 0lu;}
712 }
713
714 ///Return the number of characters in the current opened file
715 /** @return number of characters in the current opened file
716 */
717 size_t PFileParser::getNbTotalChar() const{
718 return p_nbTotalChar;
719 }
720
721 ///Return the index of the current character
722 /** @return index of the current character
723 */
724 25 size_t PFileParser::getCurrentCharIdx() const{
725 25 return p_currentChar;
726 }
727
728 ///Get the current line indentation
729 /** @return current line indentation
730 */
731 size_t PFileParser::getLineIndentation(){
732 //First, let's get the current column
733 size_t indentation(0lu), currentCharIdx(p_currentLineFirstColumn);
734 while(currentCharIdx < p_nbTotalChar && PString(" \t").find(p_fileContent[currentCharIdx])){
735 ++indentation;
736 ++currentCharIdx;
737 }
738 if(currentCharIdx > p_currentChar){
739 p_currentChar = currentCharIdx; //Anyway, it was just white character
740 }
741
742 return indentation;
743 }
744
745 ///Fonction qui renvoie la PLocation du PFileParser
746 /** @return PLocation du PFileParser
747 */
748 69 PLocation PFileParser::getLocation() const{
749 69 return PLocation(p_fileName, p_currentLine, getColumn());
750 }
751
752 ///Définition de l'opérateur de flux sortant
753 /** @param out : flux dans lequel il faut écrire
754 * @param other : PFileParser
755 * @return flux contenant le PFileParser
756 */
757 1 std::ostream & operator << (std::ostream & out, const PFileParser & other){
758
8/8
✓ Branch 0 (3→4) taken 1 times.
✓ Branch 2 (4→5) taken 1 times.
✓ Branch 4 (5→6) taken 1 times.
✓ Branch 6 (6→7) taken 1 times.
✓ Branch 8 (7→8) taken 1 times.
✓ Branch 10 (8→9) taken 1 times.
✓ Branch 12 (9→10) taken 1 times.
✓ Branch 14 (10→11) taken 1 times.
1 out << "file '" << other.getFileName() << "' line " << other.getLine() << ":" << other.getColumn();
759 1 return out;
760 }
761
762 ///Fonction d'initialisation du PFileParser
763 73 void PFileParser::initialisationPFileParser(){
764 73 p_currentChar = 0lu;
765 73 p_currentLine = 1lu;
766 73 p_currentLineFirstColumn = 0lu;
767 73 p_fileContent = "";
768 73 p_listWhiteSpace = " \t\n";
769 73 p_listSeparator = "()[]{}+=.;,:/*%<>#";
770 73 p_echapChar = '\0';
771 73 p_dontSkipSpace = false;
772 73 p_currentCharEchaped = false;
773 73 }
774
775 ///Increment the current line
776 118 void PFileParser::incrementCurrentLine(){
777 118 ++p_currentLine;
778 118 p_currentLineFirstColumn = p_currentChar + 1lu;
779 118 }
780
781 ///Increment the current caracter
782 /** @param nbChar : number of char to go ahead
783 */
784 1677 void PFileParser::incrementCurrentChar(size_t nbChar){
785
2/2
✓ Branch 0 (15→3) taken 1726 times.
✓ Branch 1 (15→16) taken 1677 times.
3403 for(size_t i(0lu); i < nbChar; ++i){
786
2/2
✓ Branch 0 (4→5) taken 118 times.
✓ Branch 1 (4→6) taken 1608 times.
1726 if(p_fileContent[p_currentChar] == '\n'){
787 118 incrementCurrentLine();
788 }
789
2/6
✓ Branch 0 (6→7) taken 1726 times.
✗ Branch 1 (6→11) not taken.
✗ Branch 2 (8→9) not taken.
✓ Branch 3 (8→11) taken 1726 times.
✗ Branch 4 (9→10) not taken.
✗ Branch 5 (9→11) not taken.
1726 p_currentCharEchaped = !p_currentCharEchaped && p_fileContent[p_currentChar] == p_echapChar && p_echapChar != '\0';
790
1/2
✓ Branch 0 (12→13) taken 1726 times.
✗ Branch 1 (12→14) not taken.
1726 if(p_currentChar < p_nbTotalChar){
791 1726 ++p_currentChar;
792 }
793 }
794 1677 }
795
796
797