GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixCore/src/PString.cpp
Date: 2025-03-14 12:18:05
Exec Total Coverage
Lines: 370 373 99.2%
Branches: 302 324 93.2%

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 12 PString phoenix_charToString(const char * ch){
15
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
12 if(ch != NULL){
16
1/1
✓ Branch 1 taken 10 times.
10 PString str(ch);
17
1/1
✓ Branch 1 taken 10 times.
10 return str;
18 10 }else{
19 2 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 137 bool phoenix_isCharUpperCase(char ch){
28
4/4
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 68 times.
✓ Branch 3 taken 61 times.
137 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 6 bool phoenix_isCharNumber(char ch){
44
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 1 times.
6 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 1 void eraseFirstLastChar(PVecString & vecOut, const PVecString & vecStr, const PString & vecChar){
53
2/2
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
2 for(PVecString::const_iterator it(vecStr.begin()); it != vecStr.end(); ++it){
54
2/2
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
1 vecOut.push_back(it->eraseFirstLastChar(vecChar));
55 }
56 1 }
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 1 PVecString eraseFirstLastChar(const PVecString & vecStr, const PString & vecChar){
64 1 PVecString vecOut;
65
1/1
✓ Branch 1 taken 1 times.
1 eraseFirstLastChar(vecOut, vecStr, vecChar);
66 1 return vecOut;
67 }
68
69 ///Default constructor of PString
70 5354 PString::PString()
71
1/1
✓ Branch 2 taken 5354 times.
5354 :std::string("")
72 {
73
1/1
✓ Branch 1 taken 5354 times.
5354 initialisationPString();
74 5354 }
75
76 ///Default constructor of PString
77 /** @param str : pointer to initialise the PString
78 */
79 17770 PString::PString(const char * str)
80
1/1
✓ Branch 2 taken 17770 times.
17770 :std::string(str)
81 {
82
1/1
✓ Branch 1 taken 17770 times.
17770 initialisationPString();
83 17770 }
84
85 ///Default constructor of PString
86 /** @param str : string to initialise the PString
87 */
88 1317 PString::PString(const std::string & str)
89 1317 :std::string(str)
90 {
91
1/1
✓ Branch 1 taken 1317 times.
1317 initialisationPString();
92 1317 }
93
94 ///Copy constructor of PString
95 /** @param other : class to copy
96 */
97 4544 PString::PString(const PString & other)
98 4544 :std::string()
99 {
100
1/1
✓ Branch 1 taken 4544 times.
4544 copyPString(other);
101 4544 }
102
103 ///Destructeur of PString
104 55948 PString::~PString(){
105
106 }
107
108 ///Definition of equal operator of PString
109 /** @param other : class to copy
110 * @return copied class
111 */
112 15488 PString & PString::operator = (const PString & other){
113 15488 copyPString(other);
114 15488 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 199 PString & PString::operator = (const std::string & other){
122 199 copyPString(other);
123 199 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 293 PString & PString::operator += (const PString & other){
131 293 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 204 PString & PString::operator += (const std::string & other){
139 204 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 38947 PString & PString::operator += (char ch){
147 38947 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 294 PString & PString::add(const PString & other){
155 294 concatenatePString(other);
156 294 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 204 PString & PString::add(const std::string & other){
164 204 concatenatePString(other);
165 204 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 38947 PString & PString::add(char ch){
173 38947 std::string str;
174
1/1
✓ Branch 1 taken 38947 times.
38947 str+= ch;
175
1/1
✓ Branch 1 taken 38947 times.
38947 concatenatePString(str);
176 38947 return *this;
177 38947 }
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 2 PString & PString::add(const char * str){
184
1/1
✓ Branch 2 taken 2 times.
2 concatenatePString(phoenix_charToString(str));
185 2 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 70 PString PString::replace(const PString & pattern, const PString & replaceStr) const{
205 70 size_t sizePatern(pattern.size());
206 70 const PString & src = *this;
207
3/8
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 70 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 70 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
70 if(sizePatern == 0lu || src.size() == 0lu) return *this;
208
1/1
✓ Branch 1 taken 70 times.
70 PString out(""); //on évite les petits désagréments
209 70 size_t sizeSrc(src.size());
210 70 size_t beginTest(0lu), nbMatch(0lu);
211
2/2
✓ Branch 0 taken 3956 times.
✓ Branch 1 taken 70 times.
4026 for(size_t i(0lu); i < sizeSrc; ++i){
212
2/2
✓ Branch 2 taken 1988 times.
✓ Branch 3 taken 1968 times.
3956 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 114 times.
✓ Branch 1 taken 1874 times.
1988 if(nbMatch == 0lu){ //c'est le premier qu'on teste
214 114 beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
215 }
216 1988 ++nbMatch; //la prochaîne fois on testera le caractère suivant
217
2/2
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 1919 times.
1988 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 69 times.
69 out += replaceStr; //on a trouver le motif pattern, donc on le remplace par le motif replaceStr
219 69 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
220 69 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 1923 times.
✓ Branch 1 taken 45 times.
1968 if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant
224
1/1
✓ Branch 2 taken 1923 times.
1923 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 45 times.
45 out += src[beginTest];
227 45 i = beginTest;
228 }
229 1968 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
230 1968 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 70 times.
70 return out;
235 70 }
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 532 bool PString::isSameBegining(const PString & beginStr) const{
307 532 const PString & src = *this;
308
2/2
✓ Branch 2 taken 298 times.
✓ Branch 3 taken 234 times.
532 if(src.size() < beginStr.size()) return false;
309 234 std::string::const_iterator it = src.begin();
310 234 std::string::const_iterator it2 = beginStr.begin();
311
6/6
✓ Branch 2 taken 2255 times.
✓ Branch 3 taken 21 times.
✓ Branch 6 taken 2160 times.
✓ Branch 7 taken 95 times.
✓ Branch 8 taken 2160 times.
✓ Branch 9 taken 116 times.
2276 while(it != src.end() && it2 != beginStr.end()){
312
2/2
✓ Branch 2 taken 118 times.
✓ Branch 3 taken 2042 times.
2160 if(*it != *it2){ return false;}
313 2042 it++;
314 2042 it2++;
315 }
316 116 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 10 size_t PString::count(char ch) const{
324 10 const PString & str(*this);
325 10 size_t nbChar(0lu);
326 10 std::string::const_iterator it(str.begin());
327
2/2
✓ Branch 2 taken 180 times.
✓ Branch 3 taken 10 times.
190 while(it != str.end()){
328
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 171 times.
180 if(*it == ch) nbChar++;
329 180 it++;
330 }
331 10 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 5117 bool PString::find(char ch) const{
372 5117 PString::const_iterator it = begin();
373
2/2
✓ Branch 2 taken 36974 times.
✓ Branch 3 taken 3148 times.
40122 while(it != end()){
374
2/2
✓ Branch 1 taken 1969 times.
✓ Branch 2 taken 35005 times.
36974 if(*it == ch) return true;
375 35005 ++it;
376 }
377 3148 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 79 std::vector<PString> PString::split(char separator) const{
421 79 std::vector<PString> vec;
422
1/1
✓ Branch 1 taken 79 times.
79 PString buffer = "";
423
2/2
✓ Branch 4 taken 2988 times.
✓ Branch 5 taken 79 times.
3067 for(PString::const_iterator it = begin(); it != end(); ++it){
424
2/2
✓ Branch 1 taken 2828 times.
✓ Branch 2 taken 160 times.
2988 if(*it != separator){
425
1/1
✓ Branch 2 taken 2828 times.
2828 buffer += *it;
426 }else{
427
1/1
✓ Branch 1 taken 160 times.
160 vec.push_back(buffer);
428
1/1
✓ Branch 1 taken 160 times.
160 buffer = "";
429 }
430 }
431
4/4
✓ Branch 1 taken 79 times.
✓ Branch 3 taken 78 times.
✓ Branch 4 taken 1 times.
✓ Branch 6 taken 78 times.
79 if(buffer != ""){vec.push_back(buffer);}
432 158 return vec;
433 79 }
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 11034 PString PString::eraseChar(char ch) const{
479 11034 PString buffer = "";
480
2/2
✓ Branch 4 taken 33416 times.
✓ Branch 5 taken 11034 times.
44450 for(PString::const_iterator it = begin(); it != end(); it++){
481
3/3
✓ Branch 1 taken 33338 times.
✓ Branch 2 taken 78 times.
✓ Branch 5 taken 33338 times.
33416 if(*it != ch) buffer += *it;
482 }
483 11034 return buffer;
484 }
485
486 ///Erase char ch of current string
487 /** @param vecChar : chars to be removed
488 * @return modified PString
489 */
490 226 PString PString::eraseChar(const PString & vecChar) const{
491 226 PString buffer(*this);
492
2/2
✓ Branch 3 taken 11032 times.
✓ Branch 4 taken 226 times.
11258 for(PString::const_iterator it = vecChar.begin(); it != vecChar.end(); it++){
493
2/2
✓ Branch 2 taken 11032 times.
✓ Branch 5 taken 11032 times.
11032 buffer = buffer.eraseChar(*it);
494 }
495 226 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 60 PString PString::eraseFirstChar(const PString & vecChar) const{
503
1/1
✓ Branch 1 taken 60 times.
60 PString buffer(*this);
504 60 bool continuer = true;
505 60 PString::iterator it = buffer.begin();
506 //Let's remove the first chars
507
5/6
✓ Branch 2 taken 174 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 114 times.
✓ Branch 5 taken 60 times.
✓ Branch 6 taken 114 times.
✓ Branch 7 taken 60 times.
174 while(it != buffer.end() && continuer){
508
4/4
✓ Branch 2 taken 114 times.
✓ Branch 4 taken 54 times.
✓ Branch 5 taken 60 times.
✓ Branch 8 taken 54 times.
114 if(vecChar.find(*it)){it = buffer.erase(it);}
509 else{
510 60 continuer = false;
511 60 it++;
512 }
513 }
514 120 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 62 PString PString::eraseLastChar(const PString & vecChar) const{
522
2/2
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 2 times.
62 if(size() > 0lu){
523 60 size_t nbCharToRemove(0lu);
524 60 PString::const_reverse_iterator it(rbegin());
525
3/3
✓ Branch 2 taken 115 times.
✓ Branch 4 taken 55 times.
✓ Branch 5 taken 60 times.
115 while(vecChar.find(*it)){
526 55 ++it;
527 55 ++nbCharToRemove;
528 }
529
530
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 48 times.
60 if(nbCharToRemove == 0lu){
531
1/1
✓ Branch 1 taken 12 times.
12 return *this;
532 }else{
533
2/2
✓ Branch 2 taken 48 times.
✓ Branch 5 taken 48 times.
48 PString buffer(substr(0, size() - nbCharToRemove));
534
1/1
✓ Branch 1 taken 48 times.
48 return buffer;
535 48 }
536 }else{
537 2 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 56 PString PString::eraseFirstLastChar(const PString & vecChar) const{
546
1/1
✓ Branch 1 taken 56 times.
56 PString buffer(eraseFirstChar(vecChar));
547
1/1
✓ Branch 1 taken 56 times.
112 return buffer.eraseLastChar(vecChar);
548 56 }
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 3 bool PString::isNumber() const{
584
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
3 if(size() == 0lu){return false;}
585 2 const PString & str = *this;
586 2 bool isNumber(true);
587 2 size_t i(0lu);
588
6/6
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 2 times.
8 while(i < str.size() && isNumber){
589 6 isNumber = phoenix_isCharNumber(str[i]);
590 6 ++i;
591 }
592 2 return isNumber;
593 }
594
595 ///Convert PString in lower case
596 /** @return lower case PString
597 */
598 17 PString PString::toLower() const{
599
3/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 16 times.
✓ Branch 4 taken 1 times.
17 if(size() == 0lu){return *this;}
600 16 const PString & str = *this;
601
1/1
✓ Branch 2 taken 16 times.
16 std::string strOut("");
602 char currentChar;
603 16 long unsigned int size(str.size());
604
2/2
✓ Branch 0 taken 95 times.
✓ Branch 1 taken 16 times.
111 for(long unsigned int i(0lu); i < size; ++i){
605 95 currentChar = str[i];
606
3/3
✓ Branch 1 taken 95 times.
✓ Branch 3 taken 45 times.
✓ Branch 4 taken 50 times.
95 if(phoenix_isCharUpperCase(currentChar)){
607
1/1
✓ Branch 1 taken 45 times.
45 strOut += currentChar + (char)32;
608 }else{
609
1/1
✓ Branch 1 taken 50 times.
50 strOut += currentChar;
610 }
611 }
612
1/1
✓ Branch 1 taken 16 times.
16 return strOut;
613 16 }
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 467 times.
✓ Branch 2 taken 8 times.
475 for(size_t i(0lu); i < src.size(); ++i){
694 467 char ch = src[i];
695
3/3
✓ Branch 1 taken 467 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 460 times.
467 if(strCharToEscape.find(ch)){
696
1/1
✓ Branch 1 taken 7 times.
7 out += escapeSeq;
697 }
698
1/1
✓ Branch 1 taken 467 times.
467 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 20154 void PString::copyPString(const PString & other){
707 20154 resize(other.size());
708 20154 memcpy((char*)data(), other.data(), other.size());
709 20154 }
710
711 ///Copy function of PString
712 /** @param other : class to copy
713 */
714 1386 void PString::copyPString(const std::string & other){
715 1386 resize(other.size());
716 1386 memcpy((char*)data(), other.data(), other.size());
717 1386 }
718
719 ///Concatenate a PString into the current PString
720 /** @param other : PString to be added
721 */
722 296 void PString::concatenatePString(const PString & other){
723
1/1
✓ Branch 1 taken 296 times.
296 std::string tmp(*this);
724
1/1
✓ Branch 3 taken 296 times.
296 resize(tmp.size() + other.size());
725 296 memcpy((char*)data(), tmp.data(), tmp.size());
726 296 memcpy((char*)data() + tmp.size(), other.data(), other.size());
727 296 }
728
729 ///Concatenate a std::string into the current PString
730 /** @param other : std::string to be added
731 */
732 39194 void PString::concatenatePString(const std::string & other){
733
1/1
✓ Branch 1 taken 39194 times.
39194 std::string tmp(*this);
734
1/1
✓ Branch 3 taken 39194 times.
39194 resize(tmp.size() + other.size());
735 39194 memcpy((char*)data(), tmp.data(), tmp.size());
736 39194 memcpy((char*)data() + tmp.size(), other.data(), other.size());
737 39194 }
738
739 ///Initialisation function of the class PString
740 24441 void PString::initialisationPString(){
741
742 24441 }
743
744
745
746
747
748