GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixPresentation/tmp_project/PhoenixBeamerCreator/tmp_project/PhoenixCore/src/PString.cpp
Date: 2025-03-24 18:12:43
Exec Total Coverage
Lines: 370 373 99.2%
Branches: 306 323 94.7%

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 ///Default constructor of PString
70 196584527 PString::PString()
71
1/1
✓ Branch 2 taken 196584527 times.
196584527 :std::string("")
72 {
73
1/1
✓ Branch 1 taken 196584527 times.
196584527 initialisationPString();
74 196584527 }
75
76 ///Default constructor of PString
77 /** @param str : pointer to initialise the PString
78 */
79 337282296 PString::PString(const char * str)
80
1/1
✓ Branch 2 taken 337282296 times.
337282296 :std::string(str)
81 {
82
1/1
✓ Branch 1 taken 337282296 times.
337282296 initialisationPString();
83 337282296 }
84
85 ///Default constructor of PString
86 /** @param str : string to initialise the PString
87 */
88 16005727 PString::PString(const std::string & str)
89 16005727 :std::string(str)
90 {
91
1/1
✓ Branch 1 taken 16005727 times.
16005727 initialisationPString();
92 16005727 }
93
94 ///Copy constructor of PString
95 /** @param other : class to copy
96 */
97 58459806 PString::PString(const PString & other)
98 58459806 :std::string()
99 {
100
1/1
✓ Branch 1 taken 58459806 times.
58459806 copyPString(other);
101 58459806 }
102
103 ///Destructeur of PString
104 1216662706 PString::~PString(){
105
106 }
107
108 ///Definition of equal operator of PString
109 /** @param other : class to copy
110 * @return copied class
111 */
112 436418755 PString & PString::operator = (const PString & other){
113 436418755 copyPString(other);
114 436418755 return *this;
115 }
116
117 ///Definition of equal operator of PString and std::string
118 /** @param other : class to copy
119 * @return copied class
120 */
121 3477 PString & PString::operator = (const std::string & other){
122 3477 copyPString(other);
123 3477 return *this;
124 }
125
126 ///Add a PString to an other
127 /** @param other : PString to be added to the current one
128 * @return PString
129 */
130 6656713 PString & PString::operator += (const PString & other){
131 6656713 return add(other);
132 }
133
134 ///Add a std::string to an other
135 /** @param other : std::string to be added to the current one
136 * @return PString
137 */
138 355141 PString & PString::operator += (const std::string & other){
139 355141 return add(other);
140 }
141
142 ///Add a char to an other
143 /** @param ch : char to be added to the current one
144 * @return PString
145 */
146 245082640 PString & PString::operator += (char ch){
147 245082640 return add(ch);
148 }
149
150 ///Add a PString to an other
151 /** @param other : PString to be added to the current one
152 * @return PString
153 */
154 6656783 PString & PString::add(const PString & other){
155 6656783 concatenatePString(other);
156 6656783 return *this;
157 }
158
159 ///Add a std::string to an other
160 /** @param other : std::string to be added to the current one
161 * @return PString
162 */
163 355141 PString & PString::add(const std::string & other){
164 355141 concatenatePString(other);
165 355141 return *this;
166 }
167
168 ///Add a char to an other
169 /** @param ch : char to be added to the current one
170 * @return PString
171 */
172 245082640 PString & PString::add(char ch){
173 245082640 std::string str;
174
1/1
✓ Branch 1 taken 245082640 times.
245082640 str+= ch;
175
1/1
✓ Branch 1 taken 245082640 times.
245082640 concatenatePString(str);
176 245082640 return *this;
177 245082640 }
178
179 ///Add a char pointer to an other
180 /** @param str : char pointer to be added to the current one
181 * @return PString
182 */
183 342 PString & PString::add(const char * str){
184
1/1
✓ Branch 2 taken 342 times.
342 concatenatePString(phoenix_charToString(str));
185 342 return *this;
186 }
187
188 ///Concatenate 2 PString together
189 /** @param other1 : left PString
190 * @param other2 : right PString
191 * @return concatenated PString
192 */
193 8 PString operator + (const PString & other1, const PString & other2){
194 8 PString res(other1);
195
1/1
✓ Branch 1 taken 8 times.
8 res += other2;
196 8 return res;
197 }
198
199 ///Replace a PString into an other PString
200 /** @param pattern : pattern to be replaced
201 * @param replaceStr : string to replace
202 * @return modified PString
203 */
204 18084643 PString PString::replace(const PString & pattern, const PString & replaceStr) const{
205 18084643 size_t sizePatern(pattern.size());
206 18084643 const PString & src = *this;
207
6/7
✓ Branch 0 taken 18084643 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 481 times.
✓ Branch 4 taken 18084162 times.
✓ Branch 5 taken 481 times.
✓ Branch 6 taken 18084162 times.
✓ Branch 8 taken 481 times.
18084643 if(sizePatern == 0lu || src.size() == 0lu) return *this;
208
1/1
✓ Branch 1 taken 18084162 times.
18084162 PString out(""); //on évite les petits désagréments
209 18084162 size_t sizeSrc(src.size());
210 18084162 size_t beginTest(0lu), nbMatch(0lu);
211
2/2
✓ Branch 0 taken 163224625 times.
✓ Branch 1 taken 18084162 times.
181308787 for(size_t i(0lu); i < sizeSrc; ++i){
212
2/2
✓ Branch 2 taken 698139 times.
✓ Branch 3 taken 162526486 times.
163224625 if(src[i] == pattern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch
213
2/2
✓ Branch 0 taken 489206 times.
✓ Branch 1 taken 208933 times.
698139 if(nbMatch == 0lu){ //c'est le premier qu'on teste
214 489206 beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
215 }
216 698139 ++nbMatch; //la prochaîne fois on testera le caractère suivant
217
2/2
✓ Branch 0 taken 114193 times.
✓ Branch 1 taken 583946 times.
698139 if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
218
1/1
✓ Branch 1 taken 114193 times.
114193 out += replaceStr; //on a trouver le motif pattern, donc on le remplace par le motif replaceStr
219 114193 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
220 114193 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
221 }
222 }else{ //si le caractère i n'est pas le même caractère que nbMatch
223
2/2
✓ Branch 0 taken 162151473 times.
✓ Branch 1 taken 375013 times.
162526486 if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant
224
1/1
✓ Branch 2 taken 162151473 times.
162151473 out += src[i]; //on ne change rien à ce caractère
225 }else{ //si on avais déjà tester des caractères avant
226
1/1
✓ Branch 2 taken 375013 times.
375013 out += src[beginTest];
227 375013 i = beginTest;
228 }
229 162526486 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
230 162526486 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
231 }
232 }
233 //We are potentially at the end of the source, so no more test
234
1/1
✓ Branch 1 taken 18084162 times.
18084162 return out;
235 18084162 }
236
237 ///Replace a PString into an other PString
238 /** @param pattern : pattern to be replaced
239 * @param replaceStr : string to replace
240 * @param maxNbReplace : maximum number of replace to perform in the string
241 * @return modified PString
242 */
243 6 PString PString::replace(const PString & pattern, const PString & replaceStr, size_t maxNbReplace) const{
244 6 size_t sizePatern(pattern.size());
245 6 const PString & src = *this;
246
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;
247
1/1
✓ Branch 1 taken 5 times.
5 PString out(""); //on évite les petits désagréments
248 5 size_t sizeSrc(src.size());
249 5 size_t beginTest(0lu), nbMatch(0lu), nbReplace(0lu);
250
2/2
✓ Branch 0 taken 165 times.
✓ Branch 1 taken 5 times.
170 for(size_t i(0lu); i < sizeSrc; ++i){
251
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
252
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 17 times.
22 if(nbMatch == 0lu){ //c'est le premier qu'on teste
253 5 beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
254 }
255 22 ++nbMatch; //la prochaîne fois on testera le caractère suivant
256
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
257
1/1
✓ Branch 1 taken 5 times.
5 out += replaceStr; //on a trouver le motif pattern, donc on le remplace par le motif replaceStr
258 5 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
259 5 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
260 5 ++nbReplace;
261 }
262 }else{ //si le caractère i n'est pas le même caractère que nbMatch
263
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
264
1/1
✓ Branch 2 taken 143 times.
143 out += src[i]; //on ne change rien à ce caractère
265 }else{ //si on avais déjà tester des caractères avant
266 out += src[beginTest];
267 i = beginTest;
268 }
269 143 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
270 143 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
271 }
272 }
273 //We are potentially at the end of the source, so no more test
274
1/1
✓ Branch 1 taken 5 times.
5 return out;
275 5 }
276
277 ///Replace characters in vecChar by replaceStr
278 /** @param vecChar : set of characters to be replaced
279 * @param replaceStr : replacement string
280 * @return modified PString
281 */
282 1 PString PString::replaceChar(const PString & vecChar, const PString & replaceStr) const{
283 1 PString out;
284
2/2
✓ Branch 4 taken 32 times.
✓ Branch 5 taken 1 times.
33 for(PString::const_iterator it(begin()); it != end(); ++it){
285
3/3
✓ Branch 2 taken 32 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 27 times.
32 if(vecChar.find(*it)){
286
1/1
✓ Branch 1 taken 5 times.
5 out += replaceStr;
287 }else{
288
1/1
✓ Branch 2 taken 27 times.
27 out += *it;
289 }
290 }
291 1 return out;
292 }
293
294 ///Replace first {} with arg
295 /** @param arg : PString to be replaced
296 * @return modified PString
297 */
298 2 PString PString::format(const PString & arg) const{
299
1/1
✓ Branch 2 taken 2 times.
2 return replace("{}", arg, 1lu);
300 }
301
302 ///Say if the current PString has the same begining of beginStr
303 /** @param beginStr : begining string to check
304 * @return true if the current PString has the same begining of beginStr, false otherhwise
305 */
306 7454 bool PString::isSameBegining(const PString & beginStr) const{
307 7454 const PString & src = *this;
308
2/2
✓ Branch 2 taken 4018 times.
✓ Branch 3 taken 3436 times.
7454 if(src.size() < beginStr.size()) return false;
309 3436 std::string::const_iterator it = src.begin();
310 3436 std::string::const_iterator it2 = beginStr.begin();
311
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()){
312
2/2
✓ Branch 2 taken 3297 times.
✓ Branch 3 taken 3955 times.
7252 if(*it != *it2){ return false;}
313 3955 it++;
314 3955 it2++;
315 }
316 139 return true;
317 }
318
319 ///Count the number of char ch in the current PString
320 /** @param ch : char to be counted
321 * @return number of char ch in the current PString
322 */
323 317 size_t PString::count(char ch) const{
324 317 const PString & str(*this);
325 317 size_t nbChar(0lu);
326 317 std::string::const_iterator it(str.begin());
327
2/2
✓ Branch 2 taken 68379 times.
✓ Branch 3 taken 317 times.
68696 while(it != str.end()){
328
2/2
✓ Branch 1 taken 2221 times.
✓ Branch 2 taken 66158 times.
68379 if(*it == ch) nbChar++;
329 68379 it++;
330 }
331 317 return nbChar;
332 }
333
334 ///Count the number of patern in string
335 /** @param patern : patern to be serached
336 * @return number of occurence of patern in src
337 */
338 5 size_t PString::count(const PString & patern) const{
339 5 const PString & src = *this;
340 5 long unsigned int sizePatern(patern.size()), sizeSrc(src.size());
341
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;}
342 2 size_t nbPaternFound(0lu);
343
344 2 long unsigned int beginTest(0lu), nbMatch(0lu);
345
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 2 times.
45 for(long unsigned int i(0lu); i < sizeSrc; ++i){
346
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
347
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9 times.
12 if(nbMatch == 0lu){ //c'est le premier qu'on teste
348 3 beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
349 }
350 12 ++nbMatch; //la prochaîne fois on testera le caractère suivant
351
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
352 3 ++nbPaternFound;
353 3 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
354 3 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
355 }
356 }else{ //si le caractère i n'est pas le même caractère que nbMatch
357
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
358 i = beginTest;
359 }
360 31 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
361 31 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
362 }
363 }
364 2 return nbPaternFound;
365 }
366
367 ///Find a char in a string
368 /** @param ch : char to be searched
369 * @return true if the char has been found, false otherwise
370 */
371 80147252 bool PString::find(char ch) const{
372 80147252 PString::const_iterator it = begin();
373
2/2
✓ Branch 2 taken 535628959 times.
✓ Branch 3 taken 58402643 times.
594031602 while(it != end()){
374
2/2
✓ Branch 1 taken 21744609 times.
✓ Branch 2 taken 513884350 times.
535628959 if(*it == ch) return true;
375 513884350 ++it;
376 }
377 58402643 return false;
378 }
379
380 ///Find multiple chars in a string
381 /** @param listChar : chars to be searched
382 * @return true if one of the chars has been found, false otherwise
383 */
384 50 bool PString::find(const PString & listChar) const{
385
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;}
386 48 bool foundChar = false;
387 48 long unsigned int i(0lu), size(listChar.size());
388
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){
389 265 foundChar = find(listChar[i]);
390 265 ++i;
391 }
392 48 return foundChar;
393 }
394
395 ///Get the common begining between the current PString and other
396 /** @param other : string
397 * @return common begining between the current PString and other
398 */
399 5 PString PString::getCommonBegining(const PString & other) const{
400
1/1
✓ Branch 1 taken 5 times.
5 PString out("");
401 5 const PString & str1(*this);
402 5 PString::const_iterator it = str1.begin();
403 5 PString::const_iterator it2 = other.begin();
404
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()){
405
2/2
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 2 times.
6 if(*it == *it2){
406
1/1
✓ Branch 2 taken 4 times.
4 out += *it;
407 }else{
408 2 break;
409 }
410 4 it++;
411 4 it2++;
412 }
413 10 return out;
414 }
415
416 ///Cut a PString on the given separator char
417 /** @param separator : separtor char
418 * @return vector of PString
419 */
420 2365 std::vector<PString> PString::split(char separator) const{
421 2365 std::vector<PString> vec;
422
1/1
✓ Branch 1 taken 2365 times.
2365 PString buffer = "";
423
2/2
✓ Branch 4 taken 94262 times.
✓ Branch 5 taken 2365 times.
96627 for(PString::const_iterator it = begin(); it != end(); ++it){
424
2/2
✓ Branch 1 taken 86278 times.
✓ Branch 2 taken 7984 times.
94262 if(*it != separator){
425
1/1
✓ Branch 2 taken 86278 times.
86278 buffer += *it;
426 }else{
427
1/1
✓ Branch 1 taken 7984 times.
7984 vec.push_back(buffer);
428
1/1
✓ Branch 1 taken 7984 times.
7984 buffer = "";
429 }
430 }
431
4/4
✓ Branch 1 taken 2365 times.
✓ Branch 3 taken 1399 times.
✓ Branch 4 taken 966 times.
✓ Branch 6 taken 1399 times.
2365 if(buffer != ""){vec.push_back(buffer);}
432 4730 return vec;
433 2365 }
434
435 ///Split the PString on any given characters of vecSeparator
436 /** @param vecSeparator : PString of separator characters
437 * @return split PString
438 */
439 4 std::vector<PString> PString::split(const PString & vecSeparator) const{
440 4 std::vector<PString> vec;
441
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){
442
1/1
✓ Branch 1 taken 1 times.
1 PString buffer("");
443
2/2
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 1 times.
21 for(PString::const_iterator it(begin()); it != end(); ++it){
444
3/3
✓ Branch 2 taken 20 times.
✓ Branch 4 taken 17 times.
✓ Branch 5 taken 3 times.
20 if(!vecSeparator.find(*it)){
445
1/1
✓ Branch 2 taken 17 times.
17 buffer += *it;
446 }else{
447
2/3
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
3 if(buffer != ""){
448
1/1
✓ Branch 1 taken 3 times.
3 vec.push_back(buffer);
449
1/1
✓ Branch 1 taken 3 times.
3 buffer = "";
450 }
451 }
452 }
453
3/4
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
1 if(buffer != "") vec.push_back(buffer);
454 1 }
455 4 return vec;
456 }
457
458
459 ///Merge a set of PString
460 /** @param vecStr : vector of PString ot be merged
461 * @param separator : separator between PString
462 * @return corresponding PString
463 */
464 2 PString & PString::merge(const std::vector<PString> & vecStr, const PString & separator){
465
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 PString out(""), comma("");;
466
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){
467
2/2
✓ Branch 2 taken 8 times.
✓ Branch 5 taken 8 times.
8 out += comma + (*it);
468
1/1
✓ Branch 1 taken 8 times.
8 comma = separator;
469 }
470
1/1
✓ Branch 1 taken 2 times.
2 *this = out;
471 2 return *this;
472 2 }
473
474 ///Erase char ch of current string
475 /** @param ch : char to be removed
476 * @return modified PString
477 */
478 222443213 PString PString::eraseChar(char ch) const{
479 222443213 PString buffer = "";
480
2/2
✓ Branch 4 taken 80752414 times.
✓ Branch 5 taken 222443213 times.
303195627 for(PString::const_iterator it = begin(); it != end(); it++){
481
3/3
✓ Branch 1 taken 80748828 times.
✓ Branch 2 taken 3586 times.
✓ Branch 5 taken 80748828 times.
80752414 if(*it != ch) buffer += *it;
482 }
483 222443213 return buffer;
484 }
485
486 ///Erase char ch of current string
487 /** @param vecChar : chars to be removed
488 * @return modified PString
489 */
490 3418316 PString PString::eraseChar(const PString & vecChar) const{
491 3418316 PString buffer(*this);
492
2/2
✓ Branch 3 taken 222442506 times.
✓ Branch 4 taken 3418316 times.
225860822 for(PString::const_iterator it = vecChar.begin(); it != vecChar.end(); it++){
493
2/2
✓ Branch 2 taken 222442506 times.
✓ Branch 5 taken 222442506 times.
222442506 buffer = buffer.eraseChar(*it);
494 }
495 3418316 return buffer;
496 }
497
498 ///Erase first char in a string
499 /** @param vecChar : chars to be searched and removed
500 * @return modifed string
501 */
502 14258 PString PString::eraseFirstChar(const PString & vecChar) const{
503
1/1
✓ Branch 1 taken 14258 times.
14258 PString buffer(*this);
504 14258 bool continuer = true;
505 14258 PString::iterator it = buffer.begin();
506 //Let's remove the first chars
507
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){
508
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);}
509 else{
510 11924 continuer = false;
511 11924 it++;
512 }
513 }
514 28516 return buffer;
515 }
516
517 ///Erase first and last char in a string
518 /** @param vecChar : chars to be searched and removed
519 * @return modifed string
520 */
521 13777 PString PString::eraseLastChar(const PString & vecChar) const{
522
2/2
✓ Branch 1 taken 11556 times.
✓ Branch 2 taken 2221 times.
13777 if(size() > 0lu){
523 11556 size_t nbCharToRemove(0lu);
524 11556 PString::const_reverse_iterator it(rbegin());
525
3/3
✓ Branch 2 taken 14248 times.
✓ Branch 4 taken 2692 times.
✓ Branch 5 taken 11556 times.
14248 while(vecChar.find(*it)){
526 2692 ++it;
527 2692 ++nbCharToRemove;
528 }
529
530
2/2
✓ Branch 0 taken 9098 times.
✓ Branch 1 taken 2458 times.
11556 if(nbCharToRemove == 0lu){
531
1/1
✓ Branch 1 taken 9098 times.
9098 return *this;
532 }else{
533
2/2
✓ Branch 2 taken 2458 times.
✓ Branch 5 taken 2458 times.
2458 PString buffer(substr(0, size() - nbCharToRemove));
534
1/1
✓ Branch 1 taken 2458 times.
2458 return buffer;
535 2458 }
536 }else{
537 2221 return *this;
538 }
539 }
540
541 ///Erase first and last char in a string
542 /** @param vecChar : chars to be searched and removed
543 * @return modifed string
544 */
545 13465 PString PString::eraseFirstLastChar(const PString & vecChar) const{
546
1/1
✓ Branch 1 taken 13465 times.
13465 PString buffer(eraseFirstChar(vecChar));
547
1/1
✓ Branch 1 taken 13465 times.
26930 return buffer.eraseLastChar(vecChar);
548 13465 }
549
550 ///Say if the given PString is in uppercase
551 /** @return true if the PString is in uppercase, false if not
552 */
553 3 bool PString::isUpperCase() const{
554
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
3 if(size() == 0lu){return false;}
555 2 const PString & str = *this;
556 2 bool isUpper(true);
557 2 size_t i(0lu);
558
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){
559 18 isUpper = phoenix_isCharUpperCase(str[i]);
560 18 ++i;
561 }
562 2 return isUpper;
563 }
564
565 ///Say if the given PString is in lowercase
566 /** @return true if the PString is in lowercase, false if not
567 */
568 3 bool PString::isLowerCase() const{
569
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
3 if(size() == 0lu){return false;}
570 2 const PString & str = *this;
571 2 bool isLower(true);
572 2 size_t i(0lu);
573
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){
574 17 isLower = phoenix_isCharLowerCase(str[i]);
575 17 ++i;
576 }
577 2 return isLower;
578 }
579
580 ///Say if the given PString is composed of numbers
581 /** @return true if the PString is composed of numbers, false if not
582 */
583 38 bool PString::isNumber() const{
584
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 37 times.
38 if(size() == 0lu){return false;}
585 37 const PString & str = *this;
586 37 bool isNumber(true);
587 37 size_t i(0lu);
588
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){
589 41 isNumber = phoenix_isCharNumber(str[i]);
590 41 ++i;
591 }
592 37 return isNumber;
593 }
594
595 ///Convert PString in lower case
596 /** @return lower case PString
597 */
598 2985 PString PString::toLower() const{
599
3/3
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2981 times.
✓ Branch 4 taken 4 times.
2985 if(size() == 0lu){return *this;}
600 2981 const PString & str = *this;
601
1/1
✓ Branch 2 taken 2981 times.
2981 std::string strOut("");
602 char currentChar;
603 2981 long unsigned int size(str.size());
604
2/2
✓ Branch 0 taken 10447 times.
✓ Branch 1 taken 2981 times.
13428 for(long unsigned int i(0lu); i < size; ++i){
605 10447 currentChar = str[i];
606
3/3
✓ Branch 1 taken 10447 times.
✓ Branch 3 taken 582 times.
✓ Branch 4 taken 9865 times.
10447 if(phoenix_isCharUpperCase(currentChar)){
607
1/1
✓ Branch 1 taken 582 times.
582 strOut += currentChar + (char)32;
608 }else{
609
1/1
✓ Branch 1 taken 9865 times.
9865 strOut += currentChar;
610 }
611 }
612
1/1
✓ Branch 1 taken 2981 times.
2981 return strOut;
613 2981 }
614
615 ///Convert std::string in lower case and space in '_'
616 /** @return std::string in lower case and space in '_'
617 */
618 3 PString PString::toLowerUnderscore() const{
619
3/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 times.
3 if(size() == 0lu){return *this;}
620 2 const PString & str = *this;
621
1/1
✓ Branch 2 taken 2 times.
2 std::string strOut("");
622 char currentChar;
623 2 long unsigned int size(str.size());
624
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 2 times.
23 for(long unsigned int i(0lu); i < size; ++i){
625 21 currentChar = str[i];
626
3/3
✓ Branch 1 taken 21 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 17 times.
21 if(phoenix_isCharUpperCase(currentChar)){
627
1/1
✓ Branch 1 taken 4 times.
4 strOut += currentChar + (char)32;
628 }else{
629
3/3
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16 times.
✓ Branch 3 taken 1 times.
17 if(currentChar == ' '){strOut += '_';}
630
1/1
✓ Branch 1 taken 16 times.
16 else{strOut += currentChar;}
631 }
632 }
633
1/1
✓ Branch 1 taken 2 times.
2 return strOut;
634 2 }
635
636 ///Convert std::string in upper case
637 /** @return lower case std::string
638 */
639 4 PString PString::toUpper() const{
640
3/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 4 taken 1 times.
4 if(size() == 0lu){return *this;}
641 3 const PString & str = *this;
642
1/1
✓ Branch 2 taken 3 times.
3 std::string strOut("");
643 char currentChar;
644 3 long unsigned int size(str.size());
645
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 3 times.
45 for(long unsigned int i(0); i < size; ++i){
646 42 currentChar = str[i];
647
3/3
✓ Branch 1 taken 42 times.
✓ Branch 3 taken 32 times.
✓ Branch 4 taken 10 times.
42 if(phoenix_isCharLowerCase(currentChar)){
648
1/1
✓ Branch 1 taken 32 times.
32 strOut += currentChar - (char)32;
649 }else{
650
1/1
✓ Branch 1 taken 10 times.
10 strOut += currentChar;
651 }
652 }
653
1/1
✓ Branch 1 taken 3 times.
3 return strOut;
654 3 }
655
656 ///Convert first letter of the PString in lower case
657 /** @return PString with first letter of the PString in lower case
658 */
659 4 PString PString::firstToLower() const{
660
3/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 4 taken 1 times.
4 if(size() == 0lu){return *this;}
661 3 const PString & str = *this;
662
1/1
✓ Branch 1 taken 3 times.
3 std::string strOut(str);
663
1/1
✓ Branch 1 taken 3 times.
3 char currentChar = strOut[0lu];
664
3/3
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
3 if(phoenix_isCharUpperCase(currentChar)){
665
1/1
✓ Branch 1 taken 2 times.
2 strOut[0lu] = currentChar + (char)32;
666 }
667
1/1
✓ Branch 1 taken 3 times.
3 return strOut;
668 3 }
669
670 ///Convert first letter of the PString in upper case
671 /** @return PString with first letter of the PString in upper case
672 */
673 5 PString PString::firstToUpper() const{
674
3/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 1 times.
5 if(size() == 0lu){return *this;}
675 4 const PString & str = *this;
676
1/1
✓ Branch 1 taken 4 times.
4 std::string strOut(str);
677
1/1
✓ Branch 1 taken 4 times.
4 char currentChar = strOut[0lu];
678
3/3
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
4 if(phoenix_isCharLowerCase(currentChar)){
679
1/1
✓ Branch 1 taken 2 times.
2 strOut[0lu] = currentChar - (char)32;
680 }
681
1/1
✓ Branch 1 taken 4 times.
4 return strOut;
682 4 }
683
684 ///Escape given string with passed characters
685 /** @param strCharToEscape : list of the characters to be escaped
686 * @param escapeSeq : escape sequence (could be one char)
687 * @return escaped string
688 */
689 8 PString PString::escapeStr(const PString & strCharToEscape, const PString & escapeSeq) const{
690
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;}
691 8 const PString & src = *this;
692
1/1
✓ Branch 2 taken 8 times.
8 std::string out("");
693
2/2
✓ Branch 1 taken 668 times.
✓ Branch 2 taken 8 times.
676 for(size_t i(0lu); i < src.size(); ++i){
694 668 char ch = src[i];
695
3/3
✓ Branch 1 taken 668 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 661 times.
668 if(strCharToEscape.find(ch)){
696
1/1
✓ Branch 1 taken 7 times.
7 out += escapeSeq;
697 }
698
1/1
✓ Branch 1 taken 668 times.
668 out += ch;
699 }
700
1/1
✓ Branch 1 taken 8 times.
8 return out;
701 8 }
702
703 ///Copy function of PString
704 /** @param other : class to copy
705 */
706 494884807 void PString::copyPString(const PString & other){
707 494884807 resize(other.size());
708 494884807 memcpy((char*)data(), other.data(), other.size());
709 494884807 }
710
711 ///Copy function of PString
712 /** @param other : class to copy
713 */
714 7037822 void PString::copyPString(const std::string & other){
715 7037822 resize(other.size());
716 7037822 memcpy((char*)data(), other.data(), other.size());
717 7037822 }
718
719 ///Concatenate a PString into the current PString
720 /** @param other : PString to be added
721 */
722 6657125 void PString::concatenatePString(const PString & other){
723
1/1
✓ Branch 1 taken 6657125 times.
6657125 std::string tmp(*this);
724
1/1
✓ Branch 3 taken 6657125 times.
6657125 resize(tmp.size() + other.size());
725 6657125 memcpy((char*)data(), tmp.data(), tmp.size());
726 6657125 memcpy((char*)data() + tmp.size(), other.data(), other.size());
727 6657125 }
728
729 ///Concatenate a std::string into the current PString
730 /** @param other : std::string to be added
731 */
732 245785829 void PString::concatenatePString(const std::string & other){
733
1/1
✓ Branch 1 taken 245785829 times.
245785829 std::string tmp(*this);
734
1/1
✓ Branch 3 taken 245785829 times.
245785829 resize(tmp.size() + other.size());
735 245785829 memcpy((char*)data(), tmp.data(), tmp.size());
736 245785829 memcpy((char*)data() + tmp.size(), other.data(), other.size());
737 245785829 }
738
739 ///Initialisation function of the class PString
740 549872550 void PString::initialisationPString(){
741
742 549872550 }
743
744
745
746
747
748