GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixPresentation/tmp_project/PhoenixBeamerCreator/tmp_project/PhoenixCore/src/PString.cpp
Date: 2025-07-04 20:24:11
Exec Total Coverage
Lines: 407 413 98.5%
Branches: 344 366 94.0%

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 "PString.h"
9
10 ///Convert a char pointer into a string (event if the char pointer is NULL)
11 /** @param ch : char pointer to be converted into a string
12 * @return corresponding string, or empty string if the input char pointer is NULL
13 */
14 699 PString phoenix_charToString(const char * ch){
15
2/2
✓ Branch 0 taken 694 times.
✓ Branch 1 taken 5 times.
699 if(ch != NULL){
16
1/1
✓ Branch 1 taken 694 times.
694 PString str(ch);
17
1/1
✓ Branch 1 taken 694 times.
694 return str;
18 694 }else{
19 5 return "";
20 }
21 }
22
23 ///Tels if the character is upper case letter
24 /** @param ch : caractère à tester
25 * @return true if character is upper case letter, false otherwise
26 */
27 10489 bool phoenix_isCharUpperCase(char ch){
28
4/4
✓ Branch 0 taken 10427 times.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 605 times.
✓ Branch 3 taken 9822 times.
10489 return (ch >= 65 && ch <= 90);
29 }
30
31 ///Tels if the character is lower case letter
32 /** @param ch : caractère à tester
33 * @return true if the character is lower case letter, false otherwise
34 */
35 63 bool phoenix_isCharLowerCase(char ch){
36
3/4
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
63 return (ch >= 97 && ch <= 122);
37 }
38
39 ///Tels if the character is a number or not
40 /** @param ch : character to be analysed
41 * @return true if it is a number, false otherwise
42 */
43 41 bool phoenix_isCharNumber(char ch){
44
3/4
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 24 times.
41 return (ch >= 48 && ch <= 57);
45 }
46
47 ///Erase first and last characters of all PString in given vector
48 /** @param[out] vecOut : output vector of PString
49 * @param vecStr : input PString
50 * @param vecChar : set of characters to be removed
51 */
52 278 void eraseFirstLastChar(PVecString & vecOut, const PVecString & vecStr, const PString & vecChar){
53
2/2
✓ Branch 3 taken 348 times.
✓ Branch 4 taken 278 times.
626 for(PVecString::const_iterator it(vecStr.begin()); it != vecStr.end(); ++it){
54
2/2
✓ Branch 2 taken 348 times.
✓ Branch 5 taken 348 times.
348 vecOut.push_back(it->eraseFirstLastChar(vecChar));
55 }
56 278 }
57
58 ///Erase first and last characters of all PString in given vector
59 /** @param vecStr : input PString
60 * @param vecChar : set of characters to be removed
61 * @return output vector of PString
62 */
63 278 PVecString eraseFirstLastChar(const PVecString & vecStr, const PString & vecChar){
64 278 PVecString vecOut;
65
1/1
✓ Branch 1 taken 278 times.
278 eraseFirstLastChar(vecOut, vecStr, vecChar);
66 278 return vecOut;
67 }
68
69 ///Find a string in a vector of string
70 /** @param vecStr : vector of string
71 * @param str : string to be searched
72 * @return true if the string has been found, false otherwise
73 */
74 9 bool findInVectorString(const PVecString & vecStr, const PString & str){
75
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;}
76 7 bool isSearch(true);
77 7 PVecString::const_iterator it(vecStr.begin());
78
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){
79 14 isSearch = *it != str;
80 14 ++it;
81 }
82 7 return !isSearch;
83 }
84
85 ///Default constructor of PString
86 202261500 PString::PString()
87
1/1
✓ Branch 2 taken 202261500 times.
202261500 :std::string("")
88 {
89
1/1
✓ Branch 1 taken 202261500 times.
202261500 initialisationPString();
90 202261500 }
91
92 ///Default constructor of PString
93 /** @param str : pointer to initialise the PString
94 */
95 349334723 PString::PString(const char * str)
96
1/1
✓ Branch 2 taken 349334723 times.
349334723 :std::string(str)
97 {
98
1/1
✓ Branch 1 taken 349334723 times.
349334723 initialisationPString();
99 349334723 }
100
101 ///Default constructor of PString
102 /** @param str : string to initialise the PString
103 */
104 16601412 PString::PString(const std::string & str)
105 16601412 :std::string(str)
106 {
107
1/1
✓ Branch 1 taken 16601412 times.
16601412 initialisationPString();
108 16601412 }
109
110 ///Copy constructor of PString
111 /** @param other : class to copy
112 */
113 59409148 PString::PString(const PString & other)
114 59409148 :std::string()
115 {
116
1/1
✓ Branch 1 taken 59409148 times.
59409148 copyPString(other);
117 59409148 }
118
119 ///Destructeur of PString
120 1255211560 PString::~PString(){
121
122 }
123
124 ///Definition of equal operator of PString
125 /** @param other : class to copy
126 * @return copied class
127 */
128 451111016 PString & PString::operator = (const PString & other){
129 451111016 copyPString(other);
130 451111016 return *this;
131 }
132
133 ///Definition of equal operator of PString and std::string
134 /** @param other : class to copy
135 * @return copied class
136 */
137 3495 PString & PString::operator = (const std::string & other){
138 3495 copyPString(other);
139 3495 return *this;
140 }
141
142 ///Add a PString to an other
143 /** @param other : PString to be added to the current one
144 * @return PString
145 */
146 6893869 PString & PString::operator += (const PString & other){
147 6893869 return add(other);
148 }
149
150 ///Add a std::string to an other
151 /** @param other : std::string to be added to the current one
152 * @return PString
153 */
154 355125 PString & PString::operator += (const std::string & other){
155 355125 return add(other);
156 }
157
158 ///Add a char to an other
159 /** @param ch : char to be added to the current one
160 * @return PString
161 */
162 257843800 PString & PString::operator += (char ch){
163 257843800 return add(ch);
164 }
165
166 ///Add a PString to an other
167 /** @param other : PString to be added to the current one
168 * @return PString
169 */
170 6893939 PString & PString::add(const PString & other){
171 6893939 concatenatePString(other);
172 6893939 return *this;
173 }
174
175 ///Add a std::string to an other
176 /** @param other : std::string to be added to the current one
177 * @return PString
178 */
179 355125 PString & PString::add(const std::string & other){
180 355125 concatenatePString(other);
181 355125 return *this;
182 }
183
184 ///Add a char to an other
185 /** @param ch : char to be added to the current one
186 * @return PString
187 */
188 257843800 PString & PString::add(char ch){
189 257843800 std::string str;
190
1/1
✓ Branch 1 taken 257843800 times.
257843800 str+= ch;
191
1/1
✓ Branch 1 taken 257843800 times.
257843800 concatenatePString(str);
192 257843800 return *this;
193 257843800 }
194
195 ///Add a char pointer to an other
196 /** @param str : char pointer to be added to the current one
197 * @return PString
198 */
199 342 PString & PString::add(const char * str){
200
1/1
✓ Branch 2 taken 342 times.
342 concatenatePString(phoenix_charToString(str));
201 342 return *this;
202 }
203
204 ///Concatenate 2 PString together
205 /** @param other1 : left PString
206 * @param other2 : right PString
207 * @return concatenated PString
208 */
209 8 PString operator + (const PString & other1, const PString & other2){
210 8 PString res(other1);
211
1/1
✓ Branch 1 taken 8 times.
8 res += other2;
212 8 return res;
213 }
214
215 ///Get the index of the first character of the given pattern
216 /** @param pattern : pattern to be searched
217 * @param offset : offset where to start searching the pattern (0 by default)
218 * @return index of the first character of the pattern, or size of the PString if the pattern wasn't found
219 */
220 8 size_t PString::findPatternIndex(const PString & pattern, size_t offset) const{
221 8 size_t sizePatern(pattern.size());
222 8 const PString & src = *this;
223
6/6
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 6 times.
8 if(sizePatern == 0lu || src.size() < offset + sizePatern){return size();}
224
225 6 size_t sizeSrc(src.size());
226 6 size_t beginTest(0lu), nbMatch(0lu);
227
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
59 for(size_t i(offset); i < sizeSrc; ++i){
228
2/2
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 41 times.
59 if(src[i] == pattern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch
229
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 if(nbMatch == 0lu){ //c'est le premier qu'on teste
230 6 beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
231 }
232 18 ++nbMatch; //la prochaîne fois on testera le caractère suivant
233
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
234 6 return beginTest; //on a trouver le motif pattern, donc on le remplace par le motif replaceStr
235 }
236 }else{ //si le caractère i n'est pas le même caractère que nbMatch
237
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if(nbMatch != 0lu){ //si on avais déjà tester des caractères avant
238 i = beginTest; //On revient là où l'on avait fait le premier test
239 }
240 41 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
241 41 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
242 }
243 }
244 return sizeSrc;
245 }
246
247 ///Get the PString between delimiter
248 /** @param beginPattern : pattern before the PString we want to get
249 * @param endPattern : pattern after the PString we want to get
250 * @return PString between beginPattern and endPattern or empty string if one of them is not found
251 */
252 2 PString PString::getBetweenDelimiter(const PString & beginPattern, const PString & endPattern) const{
253 2 size_t indexBeginPattern(findPatternIndex(beginPattern) + beginPattern.size());
254 2 size_t indexEndPattern(findPatternIndex(endPattern, indexBeginPattern));
255
3/6
✓ 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.
2 if(indexBeginPattern != size() && indexEndPattern != size()){
256
1/1
✓ Branch 2 taken 2 times.
4 return substr(indexBeginPattern, indexEndPattern - indexBeginPattern);
257 }else{
258 return "";
259 }
260 }
261
262 ///Replace a PString into an other PString
263 /** @param pattern : pattern to be replaced
264 * @param replaceStr : string to replace
265 * @return modified PString
266 */
267 18901245 PString PString::replace(const PString & pattern, const PString & replaceStr) const{
268 18901245 size_t sizePatern(pattern.size());
269 18901245 const PString & src = *this;
270
6/7
✓ Branch 0 taken 18901245 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 481 times.
✓ Branch 4 taken 18900764 times.
✓ Branch 5 taken 481 times.
✓ Branch 6 taken 18900764 times.
✓ Branch 8 taken 481 times.
18901245 if(sizePatern == 0lu || src.size() == 0lu) return *this;
271
1/1
✓ Branch 1 taken 18900764 times.
18900764 PString out(""); //on évite les petits désagréments
272 18900764 size_t sizeSrc(src.size());
273 18900764 size_t beginTest(0lu), nbMatch(0lu);
274
2/2
✓ Branch 0 taken 175152925 times.
✓ Branch 1 taken 18900764 times.
194053689 for(size_t i(0lu); i < sizeSrc; ++i){
275
2/2
✓ Branch 2 taken 709866 times.
✓ Branch 3 taken 174443059 times.
175152925 if(src[i] == pattern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch
276
2/2
✓ Branch 0 taken 493697 times.
✓ Branch 1 taken 216169 times.
709866 if(nbMatch == 0lu){ //c'est le premier qu'on teste
277 493697 beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
278 }
279 709866 ++nbMatch; //la prochaîne fois on testera le caractère suivant
280
2/2
✓ Branch 0 taken 116617 times.
✓ Branch 1 taken 593249 times.
709866 if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
281
1/1
✓ Branch 1 taken 116617 times.
116617 out += replaceStr; //on a trouver le motif pattern, donc on le remplace par le motif replaceStr
282 116617 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
283 116617 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
284 }
285 }else{ //si le caractère i n'est pas le même caractère que nbMatch
286
2/2
✓ Branch 0 taken 174065979 times.
✓ Branch 1 taken 377080 times.
174443059 if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant
287
1/1
✓ Branch 2 taken 174065979 times.
174065979 out += src[i]; //on ne change rien à ce caractère
288 }else{ //si on avais déjà tester des caractères avant
289
1/1
✓ Branch 2 taken 377080 times.
377080 out += src[beginTest];
290 377080 i = beginTest;
291 }
292 174443059 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
293 174443059 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
294 }
295 }
296 //We are potentially at the end of the source, so no more test
297
1/1
✓ Branch 1 taken 18900764 times.
18900764 return out;
298 18900764 }
299
300 ///Replace a PString into an other PString
301 /** @param pattern : pattern to be replaced
302 * @param replaceStr : string to replace
303 * @param maxNbReplace : maximum number of replace to perform in the string
304 * @return modified PString
305 */
306 6 PString PString::replace(const PString & pattern, const PString & replaceStr, size_t maxNbReplace) const{
307 6 size_t sizePatern(pattern.size());
308 6 const PString & src = *this;
309
7/9
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 5 times.
✓ Branch 10 taken 1 times.
6 if(sizePatern == 0lu || src.size() == 0lu || maxNbReplace == 0lu) return *this;
310
1/1
✓ Branch 1 taken 5 times.
5 PString out(""); //on évite les petits désagréments
311 5 size_t sizeSrc(src.size());
312 5 size_t beginTest(0lu), nbMatch(0lu), nbReplace(0lu);
313
2/2
✓ Branch 0 taken 165 times.
✓ Branch 1 taken 5 times.
170 for(size_t i(0lu); i < sizeSrc; ++i){
314
6/6
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 137 times.
✓ Branch 4 taken 22 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 22 times.
✓ Branch 7 taken 143 times.
165 if(src[i] == pattern[nbMatch] && nbReplace < maxNbReplace){ //si le caractère i est le même que le caractère nbMatch
315
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 17 times.
22 if(nbMatch == 0lu){ //c'est le premier qu'on teste
316 5 beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
317 }
318 22 ++nbMatch; //la prochaîne fois on testera le caractère suivant
319
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 17 times.
22 if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
320
1/1
✓ Branch 1 taken 5 times.
5 out += replaceStr; //on a trouver le motif pattern, donc on le remplace par le motif replaceStr
321 5 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
322 5 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
323 5 ++nbReplace;
324 }
325 }else{ //si le caractère i n'est pas le même caractère que nbMatch
326
1/2
✓ Branch 0 taken 143 times.
✗ Branch 1 not taken.
143 if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant
327
1/1
✓ Branch 2 taken 143 times.
143 out += src[i]; //on ne change rien à ce caractère
328 }else{ //si on avais déjà tester des caractères avant
329 out += src[beginTest];
330 i = beginTest;
331 }
332 143 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
333 143 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
334 }
335 }
336 //We are potentially at the end of the source, so no more test
337
1/1
✓ Branch 1 taken 5 times.
5 return out;
338 5 }
339
340 ///Replace characters in vecChar by replaceStr
341 /** @param vecChar : set of characters to be replaced
342 * @param replaceStr : replacement string
343 * @return modified PString
344 */
345 1 PString PString::replaceChar(const PString & vecChar, const PString & replaceStr) const{
346 1 PString out;
347
2/2
✓ Branch 4 taken 32 times.
✓ Branch 5 taken 1 times.
33 for(PString::const_iterator it(begin()); it != end(); ++it){
348
3/3
✓ Branch 2 taken 32 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 27 times.
32 if(vecChar.find(*it)){
349
1/1
✓ Branch 1 taken 5 times.
5 out += replaceStr;
350 }else{
351
1/1
✓ Branch 2 taken 27 times.
27 out += *it;
352 }
353 }
354 1 return out;
355 }
356
357 ///Replace first {} with arg
358 /** @param arg : PString to be replaced
359 * @return modified PString
360 */
361 2 PString PString::format(const PString & arg) const{
362
1/1
✓ Branch 2 taken 2 times.
2 return replace("{}", arg, 1lu);
363 }
364
365 ///Say if the current PString has the same begining of beginStr
366 /** @param beginStr : begining string to check
367 * @return true if the current PString has the same begining of beginStr, false otherhwise
368 */
369 7454 bool PString::isSameBegining(const PString & beginStr) const{
370 7454 const PString & src = *this;
371
2/2
✓ Branch 2 taken 4018 times.
✓ Branch 3 taken 3436 times.
7454 if(src.size() < beginStr.size()) return false;
372 3436 std::string::const_iterator it = src.begin();
373 3436 std::string::const_iterator it2 = beginStr.begin();
374
6/6
✓ Branch 2 taken 7370 times.
✓ Branch 3 taken 21 times.
✓ Branch 6 taken 7252 times.
✓ Branch 7 taken 118 times.
✓ Branch 8 taken 7252 times.
✓ Branch 9 taken 139 times.
7391 while(it != src.end() && it2 != beginStr.end()){
375
2/2
✓ Branch 2 taken 3297 times.
✓ Branch 3 taken 3955 times.
7252 if(*it != *it2){ return false;}
376 3955 it++;
377 3955 it2++;
378 }
379 139 return true;
380 }
381
382 ///Count the number of char ch in the current PString
383 /** @param ch : char to be counted
384 * @return number of char ch in the current PString
385 */
386 317 size_t PString::count(char ch) const{
387 317 const PString & str(*this);
388 317 size_t nbChar(0lu);
389 317 std::string::const_iterator it(str.begin());
390
2/2
✓ Branch 2 taken 68379 times.
✓ Branch 3 taken 317 times.
68696 while(it != str.end()){
391
2/2
✓ Branch 1 taken 2221 times.
✓ Branch 2 taken 66158 times.
68379 if(*it == ch) nbChar++;
392 68379 it++;
393 }
394 317 return nbChar;
395 }
396
397 ///Count the number of patern in string
398 /** @param patern : patern to be serached
399 * @return number of occurence of patern in src
400 */
401 5 size_t PString::count(const PString & patern) const{
402 5 const PString & src = *this;
403 5 long unsigned int sizePatern(patern.size()), sizeSrc(src.size());
404
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
5 if(sizePatern == 0lu || sizeSrc == 0lu){return 0lu;}
405 2 size_t nbPaternFound(0lu);
406
407 2 long unsigned int beginTest(0lu), nbMatch(0lu);
408
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 2 times.
45 for(long unsigned int i(0lu); i < sizeSrc; ++i){
409
2/2
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 31 times.
43 if(src[i] == patern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch
410
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9 times.
12 if(nbMatch == 0lu){ //c'est le premier qu'on teste
411 3 beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
412 }
413 12 ++nbMatch; //la prochaîne fois on testera le caractère suivant
414
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9 times.
12 if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
415 3 ++nbPaternFound;
416 3 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
417 3 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
418 }
419 }else{ //si le caractère i n'est pas le même caractère que nbMatch
420
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 if(nbMatch != 0lu){ //si on avais déjà tester des caractères avant
421 i = beginTest;
422 }
423 31 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
424 31 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
425 }
426 }
427 2 return nbPaternFound;
428 }
429
430 ///Find a char in a string
431 /** @param ch : char to be searched
432 * @return true if the char has been found, false otherwise
433 */
434 81920333 bool PString::find(char ch) const{
435 81920333 PString::const_iterator it = begin();
436
2/2
✓ Branch 2 taken 555839412 times.
✓ Branch 3 taken 59329930 times.
615169342 while(it != end()){
437
2/2
✓ Branch 1 taken 22590403 times.
✓ Branch 2 taken 533249009 times.
555839412 if(*it == ch) return true;
438 533249009 ++it;
439 }
440 59329930 return false;
441 }
442
443 ///Find multiple chars in a string
444 /** @param listChar : chars to be searched
445 * @return true if one of the chars has been found, false otherwise
446 */
447 50 bool PString::find(const PString & listChar) const{
448
6/6
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 48 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 48 times.
50 if(size() == 0lu || listChar.size() == 0lu){return false;}
449 48 bool foundChar = false;
450 48 long unsigned int i(0lu), size(listChar.size());
451
4/4
✓ Branch 0 taken 309 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 265 times.
✓ Branch 3 taken 44 times.
313 while(!foundChar && i < size){
452 265 foundChar = find(listChar[i]);
453 265 ++i;
454 }
455 48 return foundChar;
456 }
457
458 ///Keep only the characters in the given listChar
459 /** @param listChar : list of characters to be kept
460 * @return PString which contains only characters in listChar
461 */
462 2 PString PString::keepChar(const PString & listChar) const{
463
3/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 1 times.
2 if(listChar.size() == 0lu){return "";}
464
1/1
✓ Branch 1 taken 1 times.
1 PString out;
465
2/2
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 1 times.
10 for(PString::const_iterator it = begin(); it != end(); ++it){
466
3/3
✓ Branch 2 taken 9 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 3 times.
9 if(listChar.find(*it)){
467
1/1
✓ Branch 2 taken 6 times.
6 out += *it;
468 }
469 }
470
1/1
✓ Branch 1 taken 1 times.
1 return out;
471 1 }
472
473 ///Get the common begining between the current PString and other
474 /** @param other : string
475 * @return common begining between the current PString and other
476 */
477 5 PString PString::getCommonBegining(const PString & other) const{
478
1/1
✓ Branch 1 taken 5 times.
5 PString out("");
479 5 const PString & str1(*this);
480 5 PString::const_iterator it = str1.begin();
481 5 PString::const_iterator it2 = other.begin();
482
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 != other.end()){
483
2/2
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2 times.
6 if(*it == *it2){
484
1/1
✓ Branch 2 taken 4 times.
4 out += *it;
485 }else{
486 2 break;
487 }
488 4 it++;
489 4 it2++;
490 }
491 10 return out;
492 }
493
494 ///Cut a PString on the given separator char
495 /** @param separator : separtor char
496 * @return vector of PString
497 */
498 2367 std::vector<PString> PString::split(char separator) const{
499 2367 std::vector<PString> vec;
500
1/1
✓ Branch 1 taken 2367 times.
2367 PString buffer = "";
501
2/2
✓ Branch 4 taken 95086 times.
✓ Branch 5 taken 2367 times.
97453 for(PString::const_iterator it = begin(); it != end(); ++it){
502
2/2
✓ Branch 1 taken 87096 times.
✓ Branch 2 taken 7990 times.
95086 if(*it != separator){
503
1/1
✓ Branch 2 taken 87096 times.
87096 buffer += *it;
504 }else{
505
1/1
✓ Branch 1 taken 7990 times.
7990 vec.push_back(buffer);
506
1/1
✓ Branch 1 taken 7990 times.
7990 buffer = "";
507 }
508 }
509
3/3
✓ Branch 1 taken 1399 times.
✓ Branch 2 taken 968 times.
✓ Branch 4 taken 1399 times.
2367 if(buffer != ""){vec.push_back(buffer);}
510 4734 return vec;
511 2367 }
512
513 ///Split the PString on any given characters of vecSeparator
514 /** @param vecSeparator : PString of separator characters
515 * @return split PString
516 */
517 4 std::vector<PString> PString::split(const PString & vecSeparator) const{
518 4 std::vector<PString> vec;
519
6/6
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 3 times.
4 if(size() != 0lu && vecSeparator.size() != 0lu){
520
1/1
✓ Branch 1 taken 1 times.
1 PString buffer("");
521
2/2
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 1 times.
21 for(PString::const_iterator it(begin()); it != end(); ++it){
522
3/3
✓ Branch 2 taken 20 times.
✓ Branch 4 taken 17 times.
✓ Branch 5 taken 3 times.
20 if(!vecSeparator.find(*it)){
523
1/1
✓ Branch 2 taken 17 times.
17 buffer += *it;
524 }else{
525
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if(buffer != ""){
526
1/1
✓ Branch 1 taken 3 times.
3 vec.push_back(buffer);
527
1/1
✓ Branch 1 taken 3 times.
3 buffer = "";
528 }
529 }
530 }
531
2/3
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
1 if(buffer != "") vec.push_back(buffer);
532 1 }
533 4 return vec;
534 }
535
536
537 ///Merge a set of PString
538 /** @param vecStr : vector of PString ot be merged
539 * @param separator : separator between PString
540 * @return corresponding PString
541 */
542 2 PString & PString::merge(const std::vector<PString> & vecStr, const PString & separator){
543
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 PString out(""), comma("");;
544
2/2
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 2 times.
10 for(std::vector<PString>::const_iterator it(vecStr.begin()); it != vecStr.end(); ++it){
545
2/2
✓ Branch 2 taken 8 times.
✓ Branch 5 taken 8 times.
8 out += comma + (*it);
546
1/1
✓ Branch 1 taken 8 times.
8 comma = separator;
547 }
548
1/1
✓ Branch 1 taken 2 times.
2 *this = out;
549 2 return *this;
550 2 }
551
552 ///Erase char ch of current string
553 /** @param ch : char to be removed
554 * @return modified PString
555 */
556 230471061 PString PString::eraseChar(char ch) const{
557 230471061 PString buffer = "";
558
2/2
✓ Branch 4 taken 81596180 times.
✓ Branch 5 taken 230471061 times.
312067241 for(PString::const_iterator it = begin(); it != end(); it++){
559
3/3
✓ Branch 1 taken 81592586 times.
✓ Branch 2 taken 3594 times.
✓ Branch 5 taken 81592586 times.
81596180 if(*it != ch) buffer += *it;
560 }
561 230471061 return buffer;
562 }
563
564 ///Erase char ch of current string
565 /** @param vecChar : chars to be removed
566 * @return modified PString
567 */
568 3540083 PString PString::eraseChar(const PString & vecChar) const{
569 3540083 PString buffer(*this);
570
2/2
✓ Branch 3 taken 230470352 times.
✓ Branch 4 taken 3540083 times.
234010435 for(PString::const_iterator it = vecChar.begin(); it != vecChar.end(); it++){
571
2/2
✓ Branch 2 taken 230470352 times.
✓ Branch 5 taken 230470352 times.
230470352 buffer = buffer.eraseChar(*it);
572 }
573 3540083 return buffer;
574 }
575
576 ///Erase first char in a string
577 /** @param vecChar : chars to be searched and removed
578 * @return modifed string
579 */
580 14258 PString PString::eraseFirstChar(const PString & vecChar) const{
581
1/1
✓ Branch 1 taken 14258 times.
14258 PString buffer(*this);
582 14258 bool continuer = true;
583 14258 PString::iterator it = buffer.begin();
584 //Let's remove the first chars
585
6/6
✓ Branch 2 taken 26655 times.
✓ Branch 3 taken 2495 times.
✓ Branch 4 taken 14892 times.
✓ Branch 5 taken 11763 times.
✓ Branch 6 taken 14892 times.
✓ Branch 7 taken 14258 times.
29150 while(it != buffer.end() && continuer){
586
4/4
✓ Branch 2 taken 14892 times.
✓ Branch 4 taken 2968 times.
✓ Branch 5 taken 11924 times.
✓ Branch 8 taken 2968 times.
14892 if(vecChar.find(*it)){it = buffer.erase(it);}
587 else{
588 11924 continuer = false;
589 11924 it++;
590 }
591 }
592 28516 return buffer;
593 }
594
595 ///Erase first and last char in a string
596 /** @param vecChar : chars to be searched and removed
597 * @return modifed string
598 */
599 13777 PString PString::eraseLastChar(const PString & vecChar) const{
600
2/2
✓ Branch 1 taken 11556 times.
✓ Branch 2 taken 2221 times.
13777 if(size() > 0lu){
601 11556 size_t nbCharToRemove(0lu);
602 11556 PString::const_reverse_iterator it(rbegin());
603
3/3
✓ Branch 2 taken 14248 times.
✓ Branch 4 taken 2692 times.
✓ Branch 5 taken 11556 times.
14248 while(vecChar.find(*it)){
604 2692 ++it;
605 2692 ++nbCharToRemove;
606 }
607
608
2/2
✓ Branch 0 taken 9098 times.
✓ Branch 1 taken 2458 times.
11556 if(nbCharToRemove == 0lu){
609
1/1
✓ Branch 1 taken 9098 times.
9098 return *this;
610 }else{
611
2/2
✓ Branch 2 taken 2458 times.
✓ Branch 5 taken 2458 times.
2458 PString buffer(substr(0, size() - nbCharToRemove));
612
1/1
✓ Branch 1 taken 2458 times.
2458 return buffer;
613 2458 }
614 }else{
615 2221 return *this;
616 }
617 }
618
619 ///Erase first and last char in a string
620 /** @param vecChar : chars to be searched and removed
621 * @return modifed string
622 */
623 13465 PString PString::eraseFirstLastChar(const PString & vecChar) const{
624
1/1
✓ Branch 1 taken 13465 times.
13465 PString buffer(eraseFirstChar(vecChar));
625
1/1
✓ Branch 1 taken 13465 times.
26930 return buffer.eraseLastChar(vecChar);
626 13465 }
627
628 ///Say if the given PString is in uppercase
629 /** @return true if the PString is in uppercase, false if not
630 */
631 3 bool PString::isUpperCase() const{
632
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
3 if(size() == 0lu){return false;}
633 2 const PString & str = *this;
634 2 bool isUpper(true);
635 2 size_t i(0lu);
636
6/6
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 18 times.
✓ Branch 6 taken 2 times.
20 while(i < str.size() && isUpper){
637 18 isUpper = phoenix_isCharUpperCase(str[i]);
638 18 ++i;
639 }
640 2 return isUpper;
641 }
642
643 ///Say if the given PString is in lowercase
644 /** @return true if the PString is in lowercase, false if not
645 */
646 3 bool PString::isLowerCase() const{
647
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
3 if(size() == 0lu){return false;}
648 2 const PString & str = *this;
649 2 bool isLower(true);
650 2 size_t i(0lu);
651
6/6
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 17 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 17 times.
✓ Branch 6 taken 2 times.
19 while(i < str.size() && isLower){
652 17 isLower = phoenix_isCharLowerCase(str[i]);
653 17 ++i;
654 }
655 2 return isLower;
656 }
657
658 ///Say if the given PString is composed of numbers
659 /** @return true if the PString is composed of numbers, false if not
660 */
661 38 bool PString::isNumber() const{
662
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 37 times.
38 if(size() == 0lu){return false;}
663 37 const PString & str = *this;
664 37 bool isNumber(true);
665 37 size_t i(0lu);
666
6/6
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 41 times.
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 41 times.
✓ Branch 6 taken 37 times.
78 while(i < str.size() && isNumber){
667 41 isNumber = phoenix_isCharNumber(str[i]);
668 41 ++i;
669 }
670 37 return isNumber;
671 }
672
673 ///Convert PString in lower case
674 /** @return lower case PString
675 */
676 2985 PString PString::toLower() const{
677
3/3
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2981 times.
✓ Branch 4 taken 4 times.
2985 if(size() == 0lu){return *this;}
678 2981 const PString & str = *this;
679
1/1
✓ Branch 2 taken 2981 times.
2981 std::string strOut("");
680 char currentChar;
681 2981 long unsigned int size(str.size());
682
2/2
✓ Branch 0 taken 10447 times.
✓ Branch 1 taken 2981 times.
13428 for(long unsigned int i(0lu); i < size; ++i){
683 10447 currentChar = str[i];
684
3/3
✓ Branch 1 taken 10447 times.
✓ Branch 3 taken 582 times.
✓ Branch 4 taken 9865 times.
10447 if(phoenix_isCharUpperCase(currentChar)){
685
1/1
✓ Branch 1 taken 582 times.
582 strOut += currentChar + (char)32;
686 }else{
687
1/1
✓ Branch 1 taken 9865 times.
9865 strOut += currentChar;
688 }
689 }
690
1/1
✓ Branch 1 taken 2981 times.
2981 return strOut;
691 2981 }
692
693 ///Convert std::string in lower case and space in '_'
694 /** @return std::string in lower case and space in '_'
695 */
696 3 PString PString::toLowerUnderscore() const{
697
3/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 times.
3 if(size() == 0lu){return *this;}
698 2 const PString & str = *this;
699
1/1
✓ Branch 2 taken 2 times.
2 std::string strOut("");
700 char currentChar;
701 2 long unsigned int size(str.size());
702
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 2 times.
23 for(long unsigned int i(0lu); i < size; ++i){
703 21 currentChar = str[i];
704
3/3
✓ Branch 1 taken 21 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 17 times.
21 if(phoenix_isCharUpperCase(currentChar)){
705
1/1
✓ Branch 1 taken 4 times.
4 strOut += currentChar + (char)32;
706 }else{
707
3/3
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16 times.
✓ Branch 3 taken 1 times.
17 if(currentChar == ' '){strOut += '_';}
708
1/1
✓ Branch 1 taken 16 times.
16 else{strOut += currentChar;}
709 }
710 }
711
1/1
✓ Branch 1 taken 2 times.
2 return strOut;
712 2 }
713
714 ///Convert std::string in upper case
715 /** @return lower case std::string
716 */
717 4 PString PString::toUpper() const{
718
3/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 4 taken 1 times.
4 if(size() == 0lu){return *this;}
719 3 const PString & str = *this;
720
1/1
✓ Branch 2 taken 3 times.
3 std::string strOut("");
721 char currentChar;
722 3 long unsigned int size(str.size());
723
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 3 times.
45 for(long unsigned int i(0); i < size; ++i){
724 42 currentChar = str[i];
725
3/3
✓ Branch 1 taken 42 times.
✓ Branch 3 taken 32 times.
✓ Branch 4 taken 10 times.
42 if(phoenix_isCharLowerCase(currentChar)){
726
1/1
✓ Branch 1 taken 32 times.
32 strOut += currentChar - (char)32;
727 }else{
728
1/1
✓ Branch 1 taken 10 times.
10 strOut += currentChar;
729 }
730 }
731
1/1
✓ Branch 1 taken 3 times.
3 return strOut;
732 3 }
733
734 ///Convert first letter of the PString in lower case
735 /** @return PString with first letter of the PString in lower case
736 */
737 4 PString PString::firstToLower() const{
738
3/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 4 taken 1 times.
4 if(size() == 0lu){return *this;}
739 3 const PString & str = *this;
740
1/1
✓ Branch 1 taken 3 times.
3 std::string strOut(str);
741
1/1
✓ Branch 1 taken 3 times.
3 char currentChar = strOut[0lu];
742
3/3
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
3 if(phoenix_isCharUpperCase(currentChar)){
743
1/1
✓ Branch 1 taken 2 times.
2 strOut[0lu] = currentChar + (char)32;
744 }
745
1/1
✓ Branch 1 taken 3 times.
3 return strOut;
746 3 }
747
748 ///Convert first letter of the PString in upper case
749 /** @return PString with first letter of the PString in upper case
750 */
751 5 PString PString::firstToUpper() const{
752
3/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 1 times.
5 if(size() == 0lu){return *this;}
753 4 const PString & str = *this;
754
1/1
✓ Branch 1 taken 4 times.
4 std::string strOut(str);
755
1/1
✓ Branch 1 taken 4 times.
4 char currentChar = strOut[0lu];
756
3/3
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
4 if(phoenix_isCharLowerCase(currentChar)){
757
1/1
✓ Branch 1 taken 2 times.
2 strOut[0lu] = currentChar - (char)32;
758 }
759
1/1
✓ Branch 1 taken 4 times.
4 return strOut;
760 4 }
761
762 ///Escape given string with passed characters
763 /** @param strCharToEscape : list of the characters to be escaped
764 * @param escapeSeq : escape sequence (could be one char)
765 * @return escaped string
766 */
767 8 PString PString::escapeStr(const PString & strCharToEscape, const PString & escapeSeq) const{
768
4/10
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
8 if(size() == 0lu || strCharToEscape.size() == 0lu || escapeSeq.size() == 0lu){return *this;}
769 8 const PString & src = *this;
770
1/1
✓ Branch 2 taken 8 times.
8 std::string out("");
771
2/2
✓ Branch 1 taken 668 times.
✓ Branch 2 taken 8 times.
676 for(size_t i(0lu); i < src.size(); ++i){
772 668 char ch = src[i];
773
3/3
✓ Branch 1 taken 668 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 661 times.
668 if(strCharToEscape.find(ch)){
774
1/1
✓ Branch 1 taken 7 times.
7 out += escapeSeq;
775 }
776
1/1
✓ Branch 1 taken 668 times.
668 out += ch;
777 }
778
1/1
✓ Branch 1 taken 8 times.
8 return out;
779 8 }
780
781 ///Copy function of PString
782 /** @param other : class to copy
783 */
784 510526410 void PString::copyPString(const PString & other){
785 510526410 resize(other.size());
786 510526410 memcpy((char*)data(), other.data(), other.size());
787 510526410 }
788
789 ///Copy function of PString
790 /** @param other : class to copy
791 */
792 7065476 void PString::copyPString(const std::string & other){
793 7065476 resize(other.size());
794 7065476 memcpy((char*)data(), other.data(), other.size());
795 7065476 }
796
797 ///Concatenate a PString into the current PString
798 /** @param other : PString to be added
799 */
800 6894281 void PString::concatenatePString(const PString & other){
801
1/1
✓ Branch 1 taken 6894281 times.
6894281 std::string tmp(*this);
802
1/1
✓ Branch 3 taken 6894281 times.
6894281 resize(tmp.size() + other.size());
803 6894281 memcpy((char*)data(), tmp.data(), tmp.size());
804 6894281 memcpy((char*)data() + tmp.size(), other.data(), other.size());
805 6894281 }
806
807 ///Concatenate a std::string into the current PString
808 /** @param other : std::string to be added
809 */
810 258548848 void PString::concatenatePString(const std::string & other){
811
1/1
✓ Branch 1 taken 258548848 times.
258548848 std::string tmp(*this);
812
1/1
✓ Branch 3 taken 258548848 times.
258548848 resize(tmp.size() + other.size());
813 258548848 memcpy((char*)data(), tmp.data(), tmp.size());
814 258548848 memcpy((char*)data() + tmp.size(), other.data(), other.size());
815 258548848 }
816
817 ///Initialisation function of the class PString
818 568197635 void PString::initialisationPString(){
819
820 568197635 }
821
822
823
824
825
826