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