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