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