GCC Code Coverage Report


Directory: ./
File: src/string_function.cpp
Date: 2024-11-14 16:05:39
Exec Total Coverage
Lines: 230 230 100.0%
Branches: 230 246 93.5%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7
8 #include "string_function.h"
9
10 ///Find a char in a string
11 /** @param str : string to be used
12 * @param ch : char to be searched
13 * @return true if the char has been found, false otherwise
14 */
15 93 bool findInString(const std::string& str, char ch){
16 93 std::string::const_iterator it = str.begin();
17
2/2
✓ Branch 2 taken 269 times.
✓ Branch 3 taken 52 times.
321 while(it != str.end()){
18
2/2
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 228 times.
269 if(*it == ch) return true;
19 228 ++it;
20 }
21 52 return false;
22 }
23
24 ///Find multiple chars in a string
25 /** @param str : string to be used
26 * @param chars : chars to be searched
27 * @return true if one of the chars has been found, false otherwise
28 */
29 15 bool findCharsInString(const std::string & str, const std::string & chars){
30
6/6
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 12 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 12 times.
15 if(str.size() == 0lu || chars.size() == 0lu){return false;}
31 12 bool foundChar = false;
32 12 long unsigned int i(0lu), size(chars.size());
33
4/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 3 times.
29 while(!foundChar && i < size){
34 17 foundChar = findInString(str, chars[i]);
35 17 ++i;
36 }
37 12 return foundChar;
38 }
39
40 ///Find a string in a list of string
41 /** @param listStr : list of string
42 * @param str : string to be searched
43 * @return true if the string has been found, false otherwise
44 */
45 9 bool findInListString(const std::list<std::string> & listStr, const std::string & str){
46
6/6
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 7 times.
9 if(listStr.size() == 0lu || str == ""){return false;}
47 7 bool isSearch(true);
48 7 std::list<std::string>::const_iterator it(listStr.begin());
49
6/6
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 14 times.
✓ Branch 7 taken 7 times.
21 while(it != listStr.end() && isSearch){
50 14 isSearch = *it != str;
51 14 ++it;
52 }
53 7 return !isSearch;
54 }
55
56 ///Find a string in a vector of string
57 /** @param vecStr : vector of string
58 * @param str : string to be searched
59 * @return true if the string has been found, false otherwise
60 */
61 9 bool findInVectorString(const std::vector<std::string> & vecStr, const std::string & str){
62
6/6
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 7 times.
9 if(vecStr.size() == 0lu || str == ""){return false;}
63 7 bool isSearch(true);
64 7 std::vector<std::string>::const_iterator it(vecStr.begin());
65
6/6
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 14 times.
✓ Branch 7 taken 7 times.
21 while(it != vecStr.end() && isSearch){
66 14 isSearch = *it != str;
67 14 ++it;
68 }
69 7 return !isSearch;
70 }
71
72 ///Erase first char in a string
73 /** @param str : string to be modifed
74 * @param chars : chars to be searched and removed
75 @return modifed string
76 */
77 8 std::string eraseFirstCharsInStr(const std::string& str, const std::string & chars){
78
1/1
✓ Branch 1 taken 8 times.
8 std::string buffer(str);
79 8 bool continuer = true;
80 8 std::string::iterator it = buffer.begin();
81 //Let's remove the first chars
82
5/6
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 18 times.
✓ Branch 7 taken 8 times.
26 while(it != buffer.end() && continuer){
83
4/4
✓ Branch 2 taken 18 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 8 times.
✓ Branch 8 taken 10 times.
18 if(findInString(chars, *it)){it = buffer.erase(it);}
84 else{
85 8 continuer = false;
86 8 it++;
87 }
88 }
89 16 return buffer;
90 }
91
92 ///Erase first and last char in a string
93 /** @param str : string to be modifed
94 * @param chars : chars to be searched and removed
95 @return modifed string
96 */
97 9 std::string eraseLastCharsInStr(const std::string& str, const std::string & chars){
98
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
9 if(str.size() > 0lu){
99 8 size_t nbCharToRemove(0lu);
100 8 std::string::const_reverse_iterator it(str.rbegin());
101
3/3
✓ Branch 2 taken 18 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 8 times.
18 while(findInString(chars, *it)){
102 10 ++it;
103 10 ++nbCharToRemove;
104 }
105
106
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if(nbCharToRemove == 0lu){
107
1/1
✓ Branch 1 taken 4 times.
4 return str;
108 }else{
109
1/1
✓ Branch 2 taken 4 times.
4 std::string buffer(str.substr(0, str.size() - nbCharToRemove));
110 4 return buffer;
111 4 }
112 }else{
113 1 return str;
114 }
115 }
116
117 ///Erase first and last char in a string
118 /** @param str : string to be modifed
119 * @param chars : chars to be searched and removed
120 @return modifed string
121 */
122 4 std::string eraseFirstLastChars(const std::string& str, const std::string & chars){
123
1/1
✓ Branch 1 taken 4 times.
4 std::string buffer(eraseFirstCharsInStr(str, chars));
124
1/1
✓ Branch 1 taken 4 times.
8 return eraseLastCharsInStr(buffer, chars);
125 4 }
126
127 ///Count number of chararacters ch in string
128 /** @param str : string to be used
129 * @param ch : character to be serached
130 * @return number of character ch in string
131 */
132 18 size_t countNbChar(const std::string & str, char ch){
133 18 size_t nbChar(0lu);
134 18 std::string::const_iterator it(str.begin());
135
2/2
✓ Branch 2 taken 304 times.
✓ Branch 3 taken 18 times.
322 while(it != str.end()){
136
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 284 times.
304 if(*it == ch) nbChar++;
137 304 it++;
138 }
139 18 return nbChar;
140 }
141
142 ///copie la string str en effaçant le caractère ch
143 /** @param str : chaîne à copier
144 @param ch : caractère à effacer
145 @return string sans le caractère ch
146 */
147 10 std::string eraseCharInStr(const std::string& str, char ch){
148
1/1
✓ Branch 2 taken 10 times.
10 std::string buffer = "";
149
2/2
✓ Branch 4 taken 234 times.
✓ Branch 5 taken 10 times.
244 for(std::string::const_iterator it = str.begin(); it != str.end(); it++){
150
3/3
✓ Branch 1 taken 226 times.
✓ Branch 2 taken 8 times.
✓ Branch 5 taken 226 times.
234 if(*it != ch) buffer += *it;
151 }
152 10 return buffer;
153 }
154
155 ///copie la string str en effaçant les caractères rmchs
156 /** @param str : chaîne à copier
157 @param rmchs : caractères à effacer
158 @return string sans les caractères rmchs
159 */
160 4 std::string eraseCharsInStr(const std::string& str, const std::string & rmchs){
161 4 std::string buffer = str;
162
2/2
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 4 times.
12 for(std::string::const_iterator it = rmchs.begin(); it != rmchs.end(); it++){
163
1/1
✓ Branch 2 taken 8 times.
8 buffer = eraseCharInStr(buffer, *it);
164 }
165 4 return buffer;
166 }
167
168 ///fonction qui remplace un caractère par un autre dans une string
169 /** @param str : string à modifier
170 * @param find : caractère à trouver dans la string
171 * @param replace : caractère à remplacer dans la string
172 * @return string modifiée
173 */
174 2 std::string replaceCharInStr(const std::string& str, char find, char replace){
175
1/1
✓ Branch 2 taken 2 times.
2 std::string buffer = "";
176
2/2
✓ Branch 4 taken 44 times.
✓ Branch 5 taken 2 times.
46 for(std::string::const_iterator it = str.begin(); it != str.end(); it++){
177
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 40 times.
44 if(*it == find){
178
1/1
✓ Branch 1 taken 4 times.
4 buffer += replace;
179 }else{
180
1/1
✓ Branch 2 taken 40 times.
40 buffer += *it;
181 }
182 }
183 2 return buffer;
184 }
185
186 ///Replace all char in the strFind by char replace
187 /** @param str : string to be modified
188 * @param strFind : string of the characters to be found
189 * @param replace : character to be found
190 * @return modified string
191 */
192 4 std::string replaceCharsInStr(const std::string & str, const std::string & strFind, char replace){
193
7/7
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 1 times.
✓ Branch 9 taken 3 times.
4 if(str == "" || strFind == "") return str;
194
1/1
✓ Branch 1 taken 1 times.
1 std::string out(str);
195
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
3 for(long unsigned int i(0lu); i < strFind.size(); ++i){
196
1/1
✓ Branch 2 taken 2 times.
2 out = replaceCharInStr(out, strFind[i], replace);
197 }
198 1 return out;
199 1 }
200
201 ///fonction qui remplace un caractère par un autre dans une string
202 /** @param str : string à modifier
203 * @param find : caractère à trouver dans la string
204 * @param replace : chaîne à remplacer dans la string
205 * @return string modifiée
206 */
207 1 std::string replaceCharInStr(const std::string& str, char find, const std::string& replace){
208
1/1
✓ Branch 2 taken 1 times.
1 std::string buffer = "";
209
2/2
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 1 times.
23 for(std::string::const_iterator it = str.begin(); it != str.end(); it++){
210
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 20 times.
22 if(*it == find){
211
1/1
✓ Branch 1 taken 2 times.
2 buffer += replace;
212 }else{
213
1/1
✓ Branch 2 taken 20 times.
20 buffer += *it;
214 }
215 }
216 1 return buffer;
217 }
218
219 ///Replace a patern by an other in the input string
220 /** @param[out] out : output string
221 * @param src : input string
222 * @param patern : patern to be searched
223 * @param replace : string which replace patern
224 */
225 11 void replaceStrInStr(std::string & out, const std::string & src, const std::string & patern, const std::string & replace){
226 11 long unsigned int sizePatern(patern.size());
227
6/6
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 8 times.
11 if(sizePatern == 0lu || src == "") return;
228 8 out = ""; //on évite les petits désagréments
229 8 long unsigned int sizeSrc(src.size());
230 8 long unsigned int beginTest(0lu), nbMatch(0lu);
231
2/2
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 8 times.
182 for(long unsigned int i(0lu); i < sizeSrc; ++i){
232
2/2
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 134 times.
174 if(src[i] == patern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch
233
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 26 times.
40 if(nbMatch == 0lu){ //c'est le premier qu'on teste
234 14 beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
235 }
236 40 ++nbMatch; //la prochaîne fois on testera le caractère suivant
237
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 32 times.
40 if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
238 8 out += replace; //on a trouver le motif patern, donc on le remplace par le motif replace
239 8 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
240 8 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
241 }
242 }else{ //si le caractère i n'est pas le même caractère que nbMatch
243
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 6 times.
134 if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant
244 128 out += src[i]; //on ne change rien à ce caractère
245 }else{ //si on avais déjà tester des caractères avant
246 // for(long unsigned int k(beginTest); k <= i; ++k){ //on rajoute tout les caractères qu'il ne faut pas modifier
247 // out += src[k];
248 // }
249 6 out += src[beginTest];
250 6 i = beginTest;
251 }
252 134 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
253 134 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
254 }
255 }
256 //We are potentially at the end of the source, so no more test
257 }
258
259 ///Replace a patern by an other in the input string
260 /** @param src : input string
261 * @param patern : patern to be searched
262 * @param replace : string which replace patern
263 * @return output string
264 */
265 11 std::string replaceStrInStr(const std::string & src, const std::string & patern, const std::string & replace){
266
1/1
✓ Branch 2 taken 11 times.
11 std::string result("");
267
1/1
✓ Branch 1 taken 11 times.
11 replaceStrInStr(result, src, patern, replace);
268 11 return result;
269 }
270
271 ///Replace a patern by an other in the input string in a vector of string
272 /** @param vecSrc : vector of input strings
273 * @param patern : patern to be searched
274 * @param replace : string which replace patern
275 * @return output string
276 */
277 1 std::vector<std::string> replaceStrInStr(const std::vector<std::string> & vecSrc, const std::string & patern, const std::string & replace){
278 1 std::vector<std::string> vecOut;
279
2/2
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
2 for(std::vector<std::string>::const_iterator it(vecSrc.begin()); it != vecSrc.end(); ++it){
280
2/2
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
1 vecOut.push_back(replaceStrInStr(*it, patern, replace));
281 }
282 1 return vecOut;
283 }
284
285 ///Replace all the vector patern in the string srcDest by the replace string
286 /** @param[out] srcDest : source and modified string
287 * @param vecPatern : vector of the paterns we want to search
288 * @param replace : string we want to replace
289 */
290 5 void replaceVectorStrInStr(std::string & srcDest, const std::vector<std::string> & vecPatern, const std::string & replace){
291
6/6
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 2 times.
5 if(srcDest == "" || vecPatern.size() == 0lu) return;
292
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 2 times.
5 for(std::vector<std::string>::const_iterator it(vecPatern.begin()); it != vecPatern.end(); ++it){
293
1/1
✓ Branch 2 taken 3 times.
3 srcDest = replaceStrInStr(srcDest, *it, replace);
294 }
295 }
296
297 ///Replace all the list patern in the string srcDest by the replace string
298 /** @param[out] srcDest : source and modified string
299 * @param listPatern : vector of the paterns we want to search
300 * @param replace : string we want to replace
301 */
302 5 void replaceListStrInStr(std::string & srcDest, const std::list<std::string> & listPatern, const std::string & replace){
303
6/6
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 2 times.
5 if(srcDest == "" || listPatern.size() == 0lu) return;
304
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 2 times.
5 for(std::list<std::string>::const_iterator it(listPatern.begin()); it != listPatern.end(); ++it){
305
1/1
✓ Branch 2 taken 3 times.
3 srcDest = replaceStrInStr(srcDest, *it, replace);
306 }
307 }
308
309 ///Replace all the vector patern in the string srcDest by the replace string
310 /** @param src : source string
311 * @param vecPatern : vector of the paterns we want to search
312 * @param replace : string we want to replace
313 * @return modified string
314 */
315 5 std::string replaceVectorStrInStr(const std::string & src, const std::vector<std::string> & vecPatern, const std::string & replace){
316 5 std::string result(src);
317
1/1
✓ Branch 1 taken 5 times.
5 replaceVectorStrInStr(result, vecPatern, replace);
318 5 return result;
319 }
320
321 ///Replace all the list patern in the string srcDest by the replace string
322 /** @param src : source string
323 * @param vecPatern : vector of the paterns we want to search
324 * @param replace : string we want to replace
325 * @return modified string
326 */
327 5 std::string replaceListStrInStr(const std::string & src, const std::list<std::string> & vecPatern, const std::string & replace){
328 5 std::string result(src);
329
1/1
✓ Branch 1 taken 5 times.
5 replaceListStrInStr(result, vecPatern, replace);
330 5 return result;
331 }
332
333 ///Escape given string with passed characters
334 /** @param src : string to be excaped
335 * @param strCharToEscape : list of the characters to be escaped
336 * @param escapeStr : escape sequence (could be one char)
337 * @return escaped string
338 */
339 1 std::string phoenix_escapeStr(const std::string & src, const std::string & strCharToEscape, const std::string & escapeStr){
340
1/1
✓ Branch 2 taken 1 times.
1 std::string out("");
341
2/2
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 1 times.
33 for(size_t i(0lu); i < src.size(); ++i){
342 32 char ch = src[i];
343
3/3
✓ Branch 1 taken 32 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 25 times.
32 if(findInString(strCharToEscape, ch)){
344
1/1
✓ Branch 1 taken 7 times.
7 out += escapeStr;
345 }
346
1/1
✓ Branch 1 taken 32 times.
32 out += ch;
347 }
348 1 return out;
349 }
350
351 ///Cut a string the the given separator char
352 /** @param str : string to be cut
353 @param separator : separtor char
354 @return list of string
355 */
356 20 std::list<std::string> cutStringList(const std::string & str, char separator){
357 20 std::list<std::string> liste;
358
1/1
✓ Branch 2 taken 20 times.
20 std::string buffer = "";
359
2/2
✓ Branch 4 taken 366 times.
✓ Branch 5 taken 20 times.
386 for(std::string::const_iterator it = str.begin(); it != str.end(); ++it){
360
2/2
✓ Branch 1 taken 302 times.
✓ Branch 2 taken 64 times.
366 if(*it != separator){
361
1/1
✓ Branch 2 taken 302 times.
302 buffer += *it;
362 }else{
363
1/1
✓ Branch 1 taken 64 times.
64 liste.push_back(buffer);
364
1/1
✓ Branch 1 taken 64 times.
64 buffer = "";
365 }
366 }
367
3/3
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 19 times.
20 if(buffer != ""){liste.push_back(buffer);}
368 40 return liste;
369 20 }
370
371 ///Cut a string the the given separator char
372 /** @param str : string to be cut
373 @param separator : separtor char
374 @return vector of string
375 */
376 2 std::vector<std::string> cutStringVector(const std::string & str, char separator){
377 2 std::vector<std::string> vec;
378
1/1
✓ Branch 2 taken 2 times.
2 std::string buffer = "";
379
2/2
✓ Branch 4 taken 57 times.
✓ Branch 5 taken 2 times.
59 for(std::string::const_iterator it = str.begin(); it != str.end(); ++it){
380
2/2
✓ Branch 1 taken 53 times.
✓ Branch 2 taken 4 times.
57 if(*it != separator){
381
1/1
✓ Branch 2 taken 53 times.
53 buffer += *it;
382 }else{
383
1/1
✓ Branch 1 taken 4 times.
4 vec.push_back(buffer);
384
1/1
✓ Branch 1 taken 4 times.
4 buffer = "";
385 }
386 }
387
3/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 1 times.
2 if(buffer != ""){vec.push_back(buffer);}
388 4 return vec;
389 2 }
390
391 ///Cut a string on white characters ('&#92;t' ou ' ')
392 /** @param str : string to be cut
393 @return list of string
394 */
395 1 std::list<std::string> cutStringOnSpacesList(const std::string& str){
396 1 std::list<std::string> liste;
397
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if(str.size() != 0lu){
398
1/1
✓ Branch 2 taken 1 times.
1 std::string buffer("");
399
2/2
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 1 times.
14 for(std::string::const_iterator it(str.begin()); it != str.end(); ++it){
400
6/8
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 2 times.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 11 times.
✓ Branch 10 taken 2 times.
13 if(*it != '\t' && *it != ' ' && *it !='\n'){
401
1/1
✓ Branch 2 taken 11 times.
11 buffer += *it;
402 }else{
403
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if(buffer != ""){
404
1/1
✓ Branch 1 taken 2 times.
2 liste.push_back(buffer);
405
1/1
✓ Branch 1 taken 2 times.
2 buffer = "";
406 }
407 }
408 }
409
2/3
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
1 if(buffer != "") liste.push_back(buffer);
410 1 }
411 1 return liste;
412 }
413
414 ///Cut a string on white characters ('&#92;t' ou ' ')
415 /** @param str : string to be cut
416 @return vector of string
417 */
418 1 std::vector<std::string> cutStringOnSpacesVector(const std::string& str){
419 1 std::vector<std::string> vec;
420
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if(str.size() != 0lu){
421
1/1
✓ Branch 2 taken 1 times.
1 std::string buffer("");
422
2/2
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 1 times.
14 for(std::string::const_iterator it(str.begin()); it != str.end(); ++it){
423
6/8
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 2 times.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 11 times.
✓ Branch 10 taken 2 times.
13 if(*it != '\t' && *it != ' ' && *it !='\n'){
424
1/1
✓ Branch 2 taken 11 times.
11 buffer += *it;
425 }else{
426
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if(buffer != ""){
427
1/1
✓ Branch 1 taken 2 times.
2 vec.push_back(buffer);
428
1/1
✓ Branch 1 taken 2 times.
2 buffer = "";
429 }
430 }
431 }
432
2/3
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
1 if(buffer != "") vec.push_back(buffer);
433 1 }
434 1 return vec;
435 }
436
437 ///Copy a string of nbCh starting from begin char
438 /** @param str : string to be copied
439 @param begin : first character index
440 @param nbCh : number of characters to be copied
441 @return sub string of input string
442 */
443 3 std::string copyStr(const std::string& str, long unsigned int begin, long unsigned int nbCh){
444
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
3 if(str.size() < begin) return "";
445
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if(str.size() < begin + nbCh) nbCh = str.size() - begin;
446
1/1
✓ Branch 2 taken 3 times.
3 std::string str2("");
447
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
18 for(long unsigned int i(begin); i < begin + nbCh; ++i){
448
1/1
✓ Branch 2 taken 15 times.
15 str2 += str[i];
449 }
450 3 return str2;
451 3 }
452
453
454 ///Check if two string start the same way
455 /** @param str : string to be tested
456 @param beginig : begining to be checked
457 @return true if str starts as beginig
458 */
459 5 bool isSameBegining(const std::string & str, const std::string & beginig){
460
2/2
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
5 if(str.size() < beginig.size()) return false;
461 3 std::string::const_iterator it = str.begin();
462 3 std::string::const_iterator it2 = beginig.begin();
463
6/6
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 7 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 7 times.
✓ Branch 9 taken 3 times.
10 while(it != str.end() && it2 != beginig.end()){
464
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
7 if(*it != *it2){ return false;}
465 7 it++;
466 7 it2++;
467 }
468 3 return true;
469 }
470
471 ///Convert a char pointer into a string (event if the char pointer is NULL)
472 /** @param ch : char pointer to be converted into a string
473 * @return corresponding string, or empty string if the input char pointer is NULL
474 */
475 2 std::string phoenix_charToString(const char * ch){
476
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if(ch != NULL){
477
1/1
✓ Branch 2 taken 1 times.
1 std::string str(ch);
478 1 return str;
479 1 }else{
480
1/1
✓ Branch 2 taken 1 times.
1 return "";
481 }
482 }
483
484 ///Get the common begining between str1 and str2
485 /** @param str1 : string
486 * @param str2 : string
487 * @return common begining between str1 and str2
488 */
489 5 std::string phoenix_getCommonBegining(const std::string & str1, const std::string & str2){
490
1/1
✓ Branch 2 taken 5 times.
5 std::string out("");
491 5 std::string::const_iterator it = str1.begin();
492 5 std::string::const_iterator it2 = str2.begin();
493
6/6
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 2 times.
✓ Branch 6 taken 6 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 3 times.
9 while(it != str1.end() && it2 != str2.end()){
494
2/2
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2 times.
6 if(*it == *it2){
495
1/1
✓ Branch 2 taken 4 times.
4 out += *it;
496 }else{
497 2 break;
498 }
499 4 it++;
500 4 it2++;
501 }
502 10 return out;
503 }
504
505