GCC Code Coverage Report


Directory: ./
File: tmp_project/PhoenixCore/src/PString.cpp
Date: 2025-03-14 11:56:07
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 84 bool phoenix_isCharUpperCase(char ch){
28
4/4
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 55 times.
✓ Branch 3 taken 24 times.
84 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 3766 PString::PString()
71
1/1
✓ Branch 2 taken 3766 times.
3766 :std::string("")
72 {
73
1/1
✓ Branch 1 taken 3766 times.
3766 initialisationPString();
74 3766 }
75
76 ///Default constructor of PString
77 /** @param str : pointer to initialise the PString
78 */
79 3700 PString::PString(const char * str)
80
1/1
✓ Branch 2 taken 3700 times.
3700 :std::string(str)
81 {
82
1/1
✓ Branch 1 taken 3700 times.
3700 initialisationPString();
83 3700 }
84
85 ///Default constructor of PString
86 /** @param str : string to initialise the PString
87 */
88 596 PString::PString(const std::string & str)
89 596 :std::string(str)
90 {
91
1/1
✓ Branch 1 taken 596 times.
596 initialisationPString();
92 596 }
93
94 ///Copy constructor of PString
95 /** @param other : class to copy
96 */
97 3449 PString::PString(const PString & other)
98 3449 :std::string()
99 {
100
1/1
✓ Branch 1 taken 3449 times.
3449 copyPString(other);
101 3449 }
102
103 ///Destructeur of PString
104 21016 PString::~PString(){
105
106 }
107
108 ///Definition of equal operator of PString
109 /** @param other : class to copy
110 * @return copied class
111 */
112 3393 PString & PString::operator = (const PString & other){
113 3393 copyPString(other);
114 3393 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 62 PString & PString::operator = (const std::string & other){
122 62 copyPString(other);
123 62 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 95 PString & PString::operator += (const PString & other){
131 95 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 130 PString & PString::operator += (const std::string & other){
139 130 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 5015 PString & PString::operator += (char ch){
147 5015 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 96 PString & PString::add(const PString & other){
155 96 concatenatePString(other);
156 96 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 130 PString & PString::add(const std::string & other){
164 130 concatenatePString(other);
165 130 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 5015 PString & PString::add(char ch){
173 5015 std::string str;
174
1/1
✓ Branch 1 taken 5015 times.
5015 str+= ch;
175
1/1
✓ Branch 1 taken 5015 times.
5015 concatenatePString(str);
176 5015 return *this;
177 5015 }
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 56 PString PString::replace(const PString & pattern, const PString & replaceStr) const{
205 56 size_t sizePatern(pattern.size());
206 56 const PString & src = *this;
207
3/8
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 56 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 56 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
56 if(sizePatern == 0lu || src.size() == 0lu) return *this;
208
1/1
✓ Branch 1 taken 56 times.
56 PString out(""); //on évite les petits désagréments
209 56 size_t sizeSrc(src.size());
210 56 size_t beginTest(0lu), nbMatch(0lu);
211
2/2
✓ Branch 0 taken 2324 times.
✓ Branch 1 taken 56 times.
2380 for(size_t i(0lu); i < sizeSrc; ++i){
212
2/2
✓ Branch 2 taken 1291 times.
✓ Branch 3 taken 1033 times.
2324 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 93 times.
✓ Branch 1 taken 1198 times.
1291 if(nbMatch == 0lu){ //c'est le premier qu'on teste
214 93 beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
215 }
216 1291 ++nbMatch; //la prochaîne fois on testera le caractère suivant
217
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 1235 times.
1291 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 56 times.
56 out += replaceStr; //on a trouver le motif pattern, donc on le remplace par le motif replaceStr
219 56 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
220 56 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 996 times.
✓ Branch 1 taken 37 times.
1033 if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant
224
1/1
✓ Branch 2 taken 996 times.
996 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 37 times.
37 out += src[beginTest];
227 37 i = beginTest;
228 }
229 1033 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
230 1033 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 56 times.
56 return out;
235 56 }
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 660 bool PString::isSameBegining(const PString & beginStr) const{
307 660 const PString & src = *this;
308
2/2
✓ Branch 2 taken 376 times.
✓ Branch 3 taken 284 times.
660 if(src.size() < beginStr.size()) return false;
309 284 std::string::const_iterator it = src.begin();
310 284 std::string::const_iterator it2 = beginStr.begin();
311
6/6
✓ Branch 2 taken 2319 times.
✓ Branch 3 taken 21 times.
✓ Branch 6 taken 2224 times.
✓ Branch 7 taken 95 times.
✓ Branch 8 taken 2224 times.
✓ Branch 9 taken 116 times.
2340 while(it != src.end() && it2 != beginStr.end()){
312
2/2
✓ Branch 2 taken 168 times.
✓ Branch 3 taken 2056 times.
2224 if(*it != *it2){ return false;}
313 2056 it++;
314 2056 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 613 bool PString::find(char ch) const{
372 613 PString::const_iterator it = begin();
373
2/2
✓ Branch 2 taken 3012 times.
✓ Branch 3 taken 555 times.
3567 while(it != end()){
374
2/2
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 2954 times.
3012 if(*it == ch) return true;
375 2954 ++it;
376 }
377 555 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 4 bool PString::find(const PString & listChar) const{
385
6/6
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 2 times.
4 if(size() == 0lu || listChar.size() == 0lu){return false;}
386 2 bool foundChar = false;
387 2 long unsigned int i(0lu), size(listChar.size());
388
4/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 times.
6 while(!foundChar && i < size){
389 4 foundChar = find(listChar[i]);
390 4 ++i;
391 }
392 2 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 50 std::vector<PString> PString::split(char separator) const{
421 50 std::vector<PString> vec;
422
1/1
✓ Branch 1 taken 50 times.
50 PString buffer = "";
423
2/2
✓ Branch 4 taken 2882 times.
✓ Branch 5 taken 50 times.
2932 for(PString::const_iterator it = begin(); it != end(); ++it){
424
2/2
✓ Branch 1 taken 2723 times.
✓ Branch 2 taken 159 times.
2882 if(*it != separator){
425
1/1
✓ Branch 2 taken 2723 times.
2723 buffer += *it;
426 }else{
427
1/1
✓ Branch 1 taken 159 times.
159 vec.push_back(buffer);
428
1/1
✓ Branch 1 taken 159 times.
159 buffer = "";
429 }
430 }
431
4/4
✓ Branch 1 taken 50 times.
✓ Branch 3 taken 49 times.
✓ Branch 4 taken 1 times.
✓ Branch 6 taken 49 times.
50 if(buffer != ""){vec.push_back(buffer);}
432 100 return vec;
433 50 }
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 13 PString PString::eraseChar(char ch) const{
479 13 PString buffer = "";
480
2/2
✓ Branch 4 taken 422 times.
✓ Branch 5 taken 13 times.
435 for(PString::const_iterator it = begin(); it != end(); it++){
481
3/3
✓ Branch 1 taken 413 times.
✓ Branch 2 taken 9 times.
✓ Branch 5 taken 413 times.
422 if(*it != ch) buffer += *it;
482 }
483 13 return buffer;
484 }
485
486 ///Erase char ch of current string
487 /** @param vecChar : chars to be removed
488 * @return modified PString
489 */
490 5 PString PString::eraseChar(const PString & vecChar) const{
491 5 PString buffer(*this);
492
2/2
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 5 times.
16 for(PString::const_iterator it = vecChar.begin(); it != vecChar.end(); it++){
493
2/2
✓ Branch 2 taken 11 times.
✓ Branch 5 taken 11 times.
11 buffer = buffer.eraseChar(*it);
494 }
495 5 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 9 PString PString::eraseFirstChar(const PString & vecChar) const{
503
1/1
✓ Branch 1 taken 9 times.
9 PString buffer(*this);
504 9 bool continuer = true;
505 9 PString::iterator it = buffer.begin();
506 //Let's remove the first chars
507
5/6
✓ Branch 2 taken 29 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 9 times.
✓ Branch 6 taken 20 times.
✓ Branch 7 taken 9 times.
29 while(it != buffer.end() && continuer){
508
4/4
✓ Branch 2 taken 20 times.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 9 times.
✓ Branch 8 taken 11 times.
20 if(vecChar.find(*it)){it = buffer.erase(it);}
509 else{
510 9 continuer = false;
511 9 it++;
512 }
513 }
514 18 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 11 PString PString::eraseLastChar(const PString & vecChar) const{
522
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 2 times.
11 if(size() > 0lu){
523 9 size_t nbCharToRemove(0lu);
524 9 PString::const_reverse_iterator it(rbegin());
525
3/3
✓ Branch 2 taken 21 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 9 times.
21 while(vecChar.find(*it)){
526 12 ++it;
527 12 ++nbCharToRemove;
528 }
529
530
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
9 if(nbCharToRemove == 0lu){
531
1/1
✓ Branch 1 taken 4 times.
4 return *this;
532 }else{
533
2/2
✓ Branch 2 taken 5 times.
✓ Branch 5 taken 5 times.
5 PString buffer(substr(0, size() - nbCharToRemove));
534
1/1
✓ Branch 1 taken 5 times.
5 return buffer;
535 5 }
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 5 PString PString::eraseFirstLastChar(const PString & vecChar) const{
546
1/1
✓ Branch 1 taken 5 times.
5 PString buffer(eraseFirstChar(vecChar));
547
1/1
✓ Branch 1 taken 5 times.
10 return buffer.eraseLastChar(vecChar);
548 5 }
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 4 PString PString::toLower() const{
599
3/3
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 4 taken 1 times.
4 if(size() == 0lu){return *this;}
600 3 const PString & str = *this;
601
1/1
✓ Branch 2 taken 3 times.
3 std::string strOut("");
602 char currentChar;
603 3 long unsigned int size(str.size());
604
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 3 times.
45 for(long unsigned int i(0lu); i < size; ++i){
605 42 currentChar = str[i];
606
3/3
✓ Branch 1 taken 42 times.
✓ Branch 3 taken 32 times.
✓ Branch 4 taken 10 times.
42 if(phoenix_isCharUpperCase(currentChar)){
607
1/1
✓ Branch 1 taken 32 times.
32 strOut += currentChar + (char)32;
608 }else{
609
1/1
✓ Branch 1 taken 10 times.
10 strOut += currentChar;
610 }
611 }
612
1/1
✓ Branch 1 taken 3 times.
3 return strOut;
613 3 }
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 491 times.
✓ Branch 2 taken 8 times.
499 for(size_t i(0lu); i < src.size(); ++i){
694 491 char ch = src[i];
695
3/3
✓ Branch 1 taken 491 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 484 times.
491 if(strCharToEscape.find(ch)){
696
1/1
✓ Branch 1 taken 7 times.
7 out += escapeSeq;
697 }
698
1/1
✓ Branch 1 taken 491 times.
491 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 6865 void PString::copyPString(const PString & other){
707 6865 resize(other.size());
708 6865 memcpy((char*)data(), other.data(), other.size());
709 6865 }
710
711 ///Copy function of PString
712 /** @param other : class to copy
713 */
714 870 void PString::copyPString(const std::string & other){
715 870 resize(other.size());
716 870 memcpy((char*)data(), other.data(), other.size());
717 870 }
718
719 ///Concatenate a PString into the current PString
720 /** @param other : PString to be added
721 */
722 98 void PString::concatenatePString(const PString & other){
723
1/1
✓ Branch 1 taken 98 times.
98 std::string tmp(*this);
724
1/1
✓ Branch 3 taken 98 times.
98 resize(tmp.size() + other.size());
725 98 memcpy((char*)data(), tmp.data(), tmp.size());
726 98 memcpy((char*)data() + tmp.size(), other.data(), other.size());
727 98 }
728
729 ///Concatenate a std::string into the current PString
730 /** @param other : std::string to be added
731 */
732 5182 void PString::concatenatePString(const std::string & other){
733
1/1
✓ Branch 1 taken 5182 times.
5182 std::string tmp(*this);
734
1/1
✓ Branch 3 taken 5182 times.
5182 resize(tmp.size() + other.size());
735 5182 memcpy((char*)data(), tmp.data(), tmp.size());
736 5182 memcpy((char*)data() + tmp.size(), other.data(), other.size());
737 5182 }
738
739 ///Initialisation function of the class PString
740 8062 void PString::initialisationPString(){
741
742 8062 }
743
744
745
746
747
748