GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
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 "string_function.h" |
||
9 |
|||
10 |
///Find a char in a string |
||
11 |
/** @param str : string to be used |
||
12 |
* @param ch : char to be searched |
||
13 |
* @return true if the char has been found, false otherwise |
||
14 |
*/ |
||
15 |
509 |
bool findInString(const std::string& str, char ch){ |
|
16 |
509 |
std::string::const_iterator it = str.begin(); |
|
17 |
✓✓ | 1967 |
while(it != str.end()){ |
18 |
✓✓ | 1505 |
if(*it == ch) return true; |
19 |
1458 |
++it; |
|
20 |
} |
||
21 |
462 |
return false; |
|
22 |
} |
||
23 |
|||
24 |
///Find multiple chars in a string |
||
25 |
/** @param str : string to be used |
||
26 |
* @param chars : chars to be searched |
||
27 |
* @return true if one of the chars has been found, false otherwise |
||
28 |
*/ |
||
29 |
15 |
bool findCharsInString(const std::string & str, const std::string & chars){ |
|
30 |
✓✓✓✓ ✓✓ |
15 |
if(str.size() == 0lu || chars.size() == 0lu){return false;} |
31 |
12 |
bool foundChar = false; |
|
32 |
12 |
long unsigned int i(0lu), size(chars.size()); |
|
33 |
✓✓✓✓ |
29 |
while(!foundChar && i < size){ |
34 |
17 |
foundChar = findInString(str, chars[i]); |
|
35 |
17 |
++i; |
|
36 |
} |
||
37 |
12 |
return foundChar; |
|
38 |
} |
||
39 |
|||
40 |
///Find a string in a list of string |
||
41 |
/** @param listStr : list of string |
||
42 |
* @param str : string to be searched |
||
43 |
* @return true if the string has been found, false otherwise |
||
44 |
*/ |
||
45 |
9 |
bool findInListString(const std::list<std::string> & listStr, const std::string & str){ |
|
46 |
✓✓✓✓ ✓✓ |
9 |
if(listStr.size() == 0lu || str == ""){return false;} |
47 |
7 |
bool isSearch(true); |
|
48 |
7 |
std::list<std::string>::const_iterator it(listStr.begin()); |
|
49 |
✓✓✓✓ ✓✓ |
21 |
while(it != listStr.end() && isSearch){ |
50 |
14 |
isSearch = *it != str; |
|
51 |
14 |
++it; |
|
52 |
} |
||
53 |
7 |
return !isSearch; |
|
54 |
} |
||
55 |
|||
56 |
///Find a string in a vector of string |
||
57 |
/** @param vecStr : vector of string |
||
58 |
* @param str : string to be searched |
||
59 |
* @return true if the string has been found, false otherwise |
||
60 |
*/ |
||
61 |
9 |
bool findInVectorString(const std::vector<std::string> & vecStr, const std::string & str){ |
|
62 |
✓✓✓✓ ✓✓ |
9 |
if(vecStr.size() == 0lu || str == ""){return false;} |
63 |
7 |
bool isSearch(true); |
|
64 |
7 |
std::vector<std::string>::const_iterator it(vecStr.begin()); |
|
65 |
✓✓✓✓ ✓✓ |
21 |
while(it != vecStr.end() && isSearch){ |
66 |
14 |
isSearch = *it != str; |
|
67 |
14 |
++it; |
|
68 |
} |
||
69 |
7 |
return !isSearch; |
|
70 |
} |
||
71 |
|||
72 |
///Erase first char in a string |
||
73 |
/** @param str : string to be modifed |
||
74 |
* @param chars : chars to be searched and removed |
||
75 |
@return modifed string |
||
76 |
*/ |
||
77 |
9 |
std::string eraseFirstCharsInStr(const std::string& str, const std::string & chars){ |
|
78 |
✓ | 9 |
std::string buffer(str); |
79 |
9 |
bool continuer = true; |
|
80 |
9 |
std::string::iterator it = buffer.begin(); |
|
81 |
//Let's remove the first chars |
||
82 |
✓✗✓✓ ✓✓ |
30 |
while(it != buffer.end() && continuer){ |
83 |
✓✓✓✓ |
21 |
if(findInString(chars, *it)){it = buffer.erase(it);} |
84 |
else{ |
||
85 |
9 |
continuer = false; |
|
86 |
9 |
it++; |
|
87 |
} |
||
88 |
} |
||
89 |
18 |
return buffer; |
|
90 |
} |
||
91 |
|||
92 |
///Erase first and last char in a string |
||
93 |
/** @param str : string to be modifed |
||
94 |
* @param chars : chars to be searched and removed |
||
95 |
@return modifed string |
||
96 |
*/ |
||
97 |
10 |
std::string eraseLastCharsInStr(const std::string& str, const std::string & chars){ |
|
98 |
✓✓ | 10 |
if(str.size() > 0lu){ |
99 |
9 |
size_t nbCharToRemove(0lu); |
|
100 |
9 |
std::string::const_reverse_iterator it(str.rbegin()); |
|
101 |
✓✓✓ | 21 |
while(findInString(chars, *it)){ |
102 |
12 |
++it; |
|
103 |
12 |
++nbCharToRemove; |
|
104 |
} |
||
105 |
|||
106 |
✓✓ | 9 |
if(nbCharToRemove == 0lu){ |
107 |
✓ | 4 |
return str; |
108 |
}else{ |
||
109 |
✓ | 10 |
std::string buffer(str.substr(0, str.size() - nbCharToRemove)); |
110 |
5 |
return buffer; |
|
111 |
} |
||
112 |
}else{ |
||
113 |
1 |
return str; |
|
114 |
} |
||
115 |
} |
||
116 |
|||
117 |
///Erase first and last char in a string |
||
118 |
/** @param str : string to be modifed |
||
119 |
* @param chars : chars to be searched and removed |
||
120 |
@return modifed string |
||
121 |
*/ |
||
122 |
5 |
std::string eraseFirstLastChars(const std::string& str, const std::string & chars){ |
|
123 |
✓ | 10 |
std::string buffer(eraseFirstCharsInStr(str, chars)); |
124 |
✓ | 10 |
return eraseLastCharsInStr(buffer, chars); |
125 |
} |
||
126 |
|||
127 |
///Erase first and last char in a vector of strings |
||
128 |
/** @param vecStr : vector of string to be modifed |
||
129 |
* @param chars : chars to be searched and removed |
||
130 |
@return modifed vector of strings |
||
131 |
*/ |
||
132 |
1 |
std::vector<std::string> eraseFirstLastChars(const std::vector<std::string> & vecStr, const std::string & chars){ |
|
133 |
1 |
std::vector<std::string> vecOut; |
|
134 |
✓✓ | 2 |
for(std::vector<std::string>::const_iterator it(vecStr.begin()); it != vecStr.end(); ++it){ |
135 |
✓✓ | 1 |
vecOut.push_back(eraseFirstLastChars(*it, chars)); |
136 |
} |
||
137 |
1 |
return vecOut; |
|
138 |
} |
||
139 |
|||
140 |
///Count number of chararacters ch in string |
||
141 |
/** @param str : string to be used |
||
142 |
* @param ch : character to be serached |
||
143 |
* @return number of character ch in string |
||
144 |
*/ |
||
145 |
20 |
size_t countNbChar(const std::string & str, char ch){ |
|
146 |
20 |
size_t nbChar(0lu); |
|
147 |
20 |
std::string::const_iterator it(str.begin()); |
|
148 |
✓✓ | 350 |
while(it != str.end()){ |
149 |
✓✓ | 330 |
if(*it == ch) nbChar++; |
150 |
330 |
it++; |
|
151 |
} |
||
152 |
20 |
return nbChar; |
|
153 |
} |
||
154 |
|||
155 |
///copie la string str en effaçant le caractère ch |
||
156 |
/** @param str : chaîne à copier |
||
157 |
@param ch : caractère à effacer |
||
158 |
@return string sans le caractère ch |
||
159 |
*/ |
||
160 |
10 |
std::string eraseCharInStr(const std::string& str, char ch){ |
|
161 |
✓ | 10 |
std::string buffer = ""; |
162 |
✓✓ | 274 |
for(std::string::const_iterator it = str.begin(); it != str.end(); it++){ |
163 |
✓✓✓ | 264 |
if(*it != ch) buffer += *it; |
164 |
} |
||
165 |
10 |
return buffer; |
|
166 |
} |
||
167 |
|||
168 |
///copie la string str en effaçant les caractères rmchs |
||
169 |
/** @param str : chaîne à copier |
||
170 |
@param rmchs : caractères à effacer |
||
171 |
@return string sans les caractères rmchs |
||
172 |
*/ |
||
173 |
4 |
std::string eraseCharsInStr(const std::string& str, const std::string & rmchs){ |
|
174 |
4 |
std::string buffer = str; |
|
175 |
✓✓ | 12 |
for(std::string::const_iterator it = rmchs.begin(); it != rmchs.end(); it++){ |
176 |
✓ | 8 |
buffer = eraseCharInStr(buffer, *it); |
177 |
} |
||
178 |
4 |
return buffer; |
|
179 |
} |
||
180 |
|||
181 |
///fonction qui remplace un caractère par un autre dans une string |
||
182 |
/** @param str : string à modifier |
||
183 |
* @param find : caractère à trouver dans la string |
||
184 |
* @param replace : caractère à remplacer dans la string |
||
185 |
* @return string modifiée |
||
186 |
*/ |
||
187 |
2 |
std::string replaceCharInStr(const std::string& str, char find, char replace){ |
|
188 |
✓ | 2 |
std::string buffer = ""; |
189 |
✓✓ | 46 |
for(std::string::const_iterator it = str.begin(); it != str.end(); it++){ |
190 |
✓✓ | 44 |
if(*it == find){ |
191 |
✓ | 4 |
buffer += replace; |
192 |
}else{ |
||
193 |
✓ | 40 |
buffer += *it; |
194 |
} |
||
195 |
} |
||
196 |
2 |
return buffer; |
|
197 |
} |
||
198 |
|||
199 |
///Replace all char in the strFind by char replace |
||
200 |
/** @param str : string to be modified |
||
201 |
* @param strFind : string of the characters to be found |
||
202 |
* @param replace : character to be found |
||
203 |
* @return modified string |
||
204 |
*/ |
||
205 |
4 |
std::string replaceCharsInStr(const std::string & str, const std::string & strFind, char replace){ |
|
206 |
✓✓✓✓ ✓✓✓ |
4 |
if(str == "" || strFind == "") return str; |
207 |
✓ | 2 |
std::string out(str); |
208 |
✓✓ | 3 |
for(long unsigned int i(0lu); i < strFind.size(); ++i){ |
209 |
✓ | 2 |
out = replaceCharInStr(out, strFind[i], replace); |
210 |
} |
||
211 |
1 |
return out; |
|
212 |
} |
||
213 |
|||
214 |
///fonction qui remplace un caractère par un autre dans une string |
||
215 |
/** @param str : string à modifier |
||
216 |
* @param find : caractère à trouver dans la string |
||
217 |
* @param replace : chaîne à remplacer dans la string |
||
218 |
* @return string modifiée |
||
219 |
*/ |
||
220 |
1 |
std::string replaceCharInStr(const std::string& str, char find, const std::string& replace){ |
|
221 |
✓ | 1 |
std::string buffer = ""; |
222 |
✓✓ | 23 |
for(std::string::const_iterator it = str.begin(); it != str.end(); it++){ |
223 |
✓✓ | 22 |
if(*it == find){ |
224 |
✓ | 2 |
buffer += replace; |
225 |
}else{ |
||
226 |
✓ | 20 |
buffer += *it; |
227 |
} |
||
228 |
} |
||
229 |
1 |
return buffer; |
|
230 |
} |
||
231 |
|||
232 |
///Count the number of patern in string |
||
233 |
/** @param src : string to be analysed |
||
234 |
* @param patern : patern to be serached |
||
235 |
* @return number of occurence of patern in src |
||
236 |
*/ |
||
237 |
5 |
size_t countStrInStr(const std::string & src, const std::string & patern){ |
|
238 |
5 |
long unsigned int sizePatern(patern.size()); |
|
239 |
✓✓✓✓ ✓✓ |
5 |
if(sizePatern == 0lu || src == ""){return 0lu;} |
240 |
2 |
size_t nbPaternFound(0lu); |
|
241 |
|||
242 |
2 |
long unsigned int sizeSrc(src.size()); |
|
243 |
2 |
long unsigned int beginTest(0lu), nbMatch(0lu); |
|
244 |
✓✓ | 45 |
for(long unsigned int i(0lu); i < sizeSrc; ++i){ |
245 |
✓✓ | 43 |
if(src[i] == patern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch |
246 |
✓✓ | 12 |
if(nbMatch == 0lu){ //c'est le premier qu'on teste |
247 |
3 |
beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste |
|
248 |
} |
||
249 |
12 |
++nbMatch; //la prochaîne fois on testera le caractère suivant |
|
250 |
✓✓ | 12 |
if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde |
251 |
3 |
++nbPaternFound; |
|
252 |
3 |
beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais) |
|
253 |
3 |
nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif |
|
254 |
} |
||
255 |
}else{ //si le caractère i n'est pas le même caractère que nbMatch |
||
256 |
✗✓ | 31 |
if(nbMatch != 0lu){ //si on avais déjà tester des caractères avant |
257 |
i = beginTest; |
||
258 |
} |
||
259 |
31 |
beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais) |
|
260 |
31 |
nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif |
|
261 |
} |
||
262 |
} |
||
263 |
2 |
return nbPaternFound; |
|
264 |
} |
||
265 |
|||
266 |
///Replace a patern by an other in the input string |
||
267 |
/** @param[out] out : output string |
||
268 |
* @param src : input string |
||
269 |
* @param patern : patern to be searched |
||
270 |
* @param replace : string which replace patern |
||
271 |
*/ |
||
272 |
58 |
void replaceStrInStr(std::string & out, const std::string & src, const std::string & patern, const std::string & replace){ |
|
273 |
58 |
long unsigned int sizePatern(patern.size()); |
|
274 |
✓✓✓✓ ✓✓ |
58 |
if(sizePatern == 0lu || src == "") return; |
275 |
55 |
out = ""; //on évite les petits désagréments |
|
276 |
55 |
long unsigned int sizeSrc(src.size()); |
|
277 |
55 |
long unsigned int beginTest(0lu), nbMatch(0lu); |
|
278 |
✓✓ | 2206 |
for(long unsigned int i(0lu); i < sizeSrc; ++i){ |
279 |
✓✓ | 2151 |
if(src[i] == patern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch |
280 |
✓✓ | 1108 |
if(nbMatch == 0lu){ //c'est le premier qu'on teste |
281 |
98 |
beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste |
|
282 |
} |
||
283 |
1108 |
++nbMatch; //la prochaîne fois on testera le caractère suivant |
|
284 |
✓✓ | 1108 |
if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde |
285 |
55 |
out += replace; //on a trouver le motif patern, donc on le remplace par le motif replace |
|
286 |
55 |
beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais) |
|
287 |
55 |
nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif |
|
288 |
} |
||
289 |
}else{ //si le caractère i n'est pas le même caractère que nbMatch |
||
290 |
✓✓ | 1043 |
if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant |
291 |
1000 |
out += src[i]; //on ne change rien à ce caractère |
|
292 |
}else{ //si on avais déjà tester des caractères avant |
||
293 |
43 |
out += src[beginTest]; |
|
294 |
43 |
i = beginTest; |
|
295 |
} |
||
296 |
1043 |
beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais) |
|
297 |
1043 |
nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif |
|
298 |
} |
||
299 |
} |
||
300 |
//We are potentially at the end of the source, so no more test |
||
301 |
} |
||
302 |
|||
303 |
///Replace a patern by an other in the input string |
||
304 |
/** @param src : input string |
||
305 |
* @param patern : patern to be searched |
||
306 |
* @param replace : string which replace patern |
||
307 |
* @return output string |
||
308 |
*/ |
||
309 |
56 |
std::string replaceStrInStr(const std::string & src, const std::string & patern, const std::string & replace){ |
|
310 |
✓ | 56 |
std::string result(""); |
311 |
✓ | 56 |
replaceStrInStr(result, src, patern, replace); |
312 |
56 |
return result; |
|
313 |
} |
||
314 |
|||
315 |
///Replace a patern by an other in the input string in a vector of string |
||
316 |
/** @param vecSrc : vector of input strings |
||
317 |
* @param patern : patern to be searched |
||
318 |
* @param replace : string which replace patern |
||
319 |
* @return output string |
||
320 |
*/ |
||
321 |
1 |
std::vector<std::string> replaceStrInStr(const std::vector<std::string> & vecSrc, const std::string & patern, const std::string & replace){ |
|
322 |
1 |
std::vector<std::string> vecOut; |
|
323 |
✓✓ | 2 |
for(std::vector<std::string>::const_iterator it(vecSrc.begin()); it != vecSrc.end(); ++it){ |
324 |
✓✓ | 1 |
vecOut.push_back(replaceStrInStr(*it, patern, replace)); |
325 |
} |
||
326 |
1 |
return vecOut; |
|
327 |
} |
||
328 |
|||
329 |
///Replace all the vector patern in the string srcDest by the replace string |
||
330 |
/** @param[out] srcDest : source and modified string |
||
331 |
* @param vecPatern : vector of the paterns we want to search |
||
332 |
* @param replace : string we want to replace |
||
333 |
*/ |
||
334 |
5 |
void replaceVectorStrInStr(std::string & srcDest, const std::vector<std::string> & vecPatern, const std::string & replace){ |
|
335 |
✓✓✓✓ ✓✓ |
5 |
if(srcDest == "" || vecPatern.size() == 0lu) return; |
336 |
✓✓ | 5 |
for(std::vector<std::string>::const_iterator it(vecPatern.begin()); it != vecPatern.end(); ++it){ |
337 |
✓ | 3 |
srcDest = replaceStrInStr(srcDest, *it, replace); |
338 |
} |
||
339 |
} |
||
340 |
|||
341 |
///Replace all the list patern in the string srcDest by the replace string |
||
342 |
/** @param[out] srcDest : source and modified string |
||
343 |
* @param listPatern : vector of the paterns we want to search |
||
344 |
* @param replace : string we want to replace |
||
345 |
*/ |
||
346 |
5 |
void replaceListStrInStr(std::string & srcDest, const std::list<std::string> & listPatern, const std::string & replace){ |
|
347 |
✓✓✓✓ ✓✓ |
5 |
if(srcDest == "" || listPatern.size() == 0lu) return; |
348 |
✓✓ | 5 |
for(std::list<std::string>::const_iterator it(listPatern.begin()); it != listPatern.end(); ++it){ |
349 |
✓ | 3 |
srcDest = replaceStrInStr(srcDest, *it, replace); |
350 |
} |
||
351 |
} |
||
352 |
|||
353 |
///Replace a map of string in a string |
||
354 |
/** @param[out] out : updated string |
||
355 |
* @param src : source string |
||
356 |
* @param mapReplace : map of patterns (keys) and value to replace (values) |
||
357 |
*/ |
||
358 |
2 |
void replaceStrInStr(std::string & out, const std::string & src, const std::map<std::string, std::string> & mapReplace){ |
|
359 |
✓✓ | 2 |
if(mapReplace.size() == 0lu){ |
360 |
✓ | 1 |
out = src; |
361 |
1 |
return; |
|
362 |
} |
||
363 |
✓ | 2 |
std::string tmpStr(src); |
364 |
✓✓ | 3 |
for(std::map<std::string, std::string>::const_iterator it(mapReplace.begin()); it != mapReplace.end(); ++it){ |
365 |
✓ | 2 |
replaceStrInStr(out, tmpStr, it->first, it->second); |
366 |
✓ | 2 |
tmpStr = out; |
367 |
} |
||
368 |
} |
||
369 |
|||
370 |
///Replace a map of string in a string |
||
371 |
/** @param src : source string |
||
372 |
* @param mapReplace : map of patterns (keys) and value to replace (values) |
||
373 |
* @return updated string |
||
374 |
*/ |
||
375 |
2 |
std::string replaceStrInStr(const std::string & src, const std::map<std::string, std::string> & mapReplace){ |
|
376 |
✓ | 2 |
std::string out(""); |
377 |
✓ | 2 |
replaceStrInStr(out, src, mapReplace); |
378 |
2 |
return out; |
|
379 |
} |
||
380 |
|||
381 |
///Replace all the vector patern in the string srcDest by the replace string |
||
382 |
/** @param src : source string |
||
383 |
* @param vecPatern : vector of the paterns we want to search |
||
384 |
* @param replace : string we want to replace |
||
385 |
* @return modified string |
||
386 |
*/ |
||
387 |
5 |
std::string replaceVectorStrInStr(const std::string & src, const std::vector<std::string> & vecPatern, const std::string & replace){ |
|
388 |
5 |
std::string result(src); |
|
389 |
✓ | 5 |
replaceVectorStrInStr(result, vecPatern, replace); |
390 |
5 |
return result; |
|
391 |
} |
||
392 |
|||
393 |
///Replace all the list patern in the string srcDest by the replace string |
||
394 |
/** @param src : source string |
||
395 |
* @param vecPatern : vector of the paterns we want to search |
||
396 |
* @param replace : string we want to replace |
||
397 |
* @return modified string |
||
398 |
*/ |
||
399 |
5 |
std::string replaceListStrInStr(const std::string & src, const std::list<std::string> & vecPatern, const std::string & replace){ |
|
400 |
5 |
std::string result(src); |
|
401 |
✓ | 5 |
replaceListStrInStr(result, vecPatern, replace); |
402 |
5 |
return result; |
|
403 |
} |
||
404 |
|||
405 |
///Escape given string with passed characters |
||
406 |
/** @param src : string to be excaped |
||
407 |
* @param strCharToEscape : list of the characters to be escaped |
||
408 |
* @param escapeStr : escape sequence (could be one char) |
||
409 |
* @return escaped string |
||
410 |
*/ |
||
411 |
8 |
std::string phoenix_escapeStr(const std::string & src, const std::string & strCharToEscape, const std::string & escapeStr){ |
|
412 |
✓ | 8 |
std::string out(""); |
413 |
✓✓ | 448 |
for(size_t i(0lu); i < src.size(); ++i){ |
414 |
440 |
char ch = src[i]; |
|
415 |
✓✓✓ | 440 |
if(findInString(strCharToEscape, ch)){ |
416 |
✓ | 7 |
out += escapeStr; |
417 |
} |
||
418 |
✓ | 440 |
out += ch; |
419 |
} |
||
420 |
8 |
return out; |
|
421 |
} |
||
422 |
|||
423 |
///Cut a string the the given separator char |
||
424 |
/** @param str : string to be cut |
||
425 |
@param separator : separtor char |
||
426 |
@return list of string |
||
427 |
*/ |
||
428 |
52 |
std::list<std::string> cutStringList(const std::string & str, char separator){ |
|
429 |
52 |
std::list<std::string> liste; |
|
430 |
✓ | 104 |
std::string buffer = ""; |
431 |
✓✓ | 2738 |
for(std::string::const_iterator it = str.begin(); it != str.end(); ++it){ |
432 |
✓✓ | 2686 |
if(*it != separator){ |
433 |
✓ | 2522 |
buffer += *it; |
434 |
}else{ |
||
435 |
✓ | 164 |
liste.push_back(buffer); |
436 |
✓ | 164 |
buffer = ""; |
437 |
} |
||
438 |
} |
||
439 |
✓✓✓ | 52 |
if(buffer != ""){liste.push_back(buffer);} |
440 |
104 |
return liste; |
|
441 |
} |
||
442 |
|||
443 |
///Cut a string the the given separator char |
||
444 |
/** @param str : string to be cut |
||
445 |
@param separator : separtor char |
||
446 |
@return vector of string |
||
447 |
*/ |
||
448 |
2 |
std::vector<std::string> cutStringVector(const std::string & str, char separator){ |
|
449 |
2 |
std::vector<std::string> vec; |
|
450 |
✓ | 4 |
std::string buffer = ""; |
451 |
✓✓ | 59 |
for(std::string::const_iterator it = str.begin(); it != str.end(); ++it){ |
452 |
✓✓ | 57 |
if(*it != separator){ |
453 |
✓ | 53 |
buffer += *it; |
454 |
}else{ |
||
455 |
✓ | 4 |
vec.push_back(buffer); |
456 |
✓ | 4 |
buffer = ""; |
457 |
} |
||
458 |
} |
||
459 |
✓✓✓ | 2 |
if(buffer != ""){vec.push_back(buffer);} |
460 |
4 |
return vec; |
|
461 |
} |
||
462 |
|||
463 |
///Cut a string on white characters ('\t' ou ' ') |
||
464 |
/** @param str : string to be cut |
||
465 |
@return list of string |
||
466 |
*/ |
||
467 |
1 |
std::list<std::string> cutStringOnSpacesList(const std::string& str){ |
|
468 |
1 |
std::list<std::string> liste; |
|
469 |
✓✗ | 1 |
if(str.size() != 0lu){ |
470 |
✓ | 2 |
std::string buffer(""); |
471 |
✓✓ | 14 |
for(std::string::const_iterator it(str.begin()); it != str.end(); ++it){ |
472 |
✓✗✓✓ ✓✗✓✓ |
13 |
if(*it != '\t' && *it != ' ' && *it !='\n'){ |
473 |
✓ | 11 |
buffer += *it; |
474 |
}else{ |
||
475 |
✓✗ | 2 |
if(buffer != ""){ |
476 |
✓ | 2 |
liste.push_back(buffer); |
477 |
✓ | 2 |
buffer = ""; |
478 |
} |
||
479 |
} |
||
480 |
} |
||
481 |
✓✗✓ | 1 |
if(buffer != "") liste.push_back(buffer); |
482 |
} |
||
483 |
1 |
return liste; |
|
484 |
} |
||
485 |
|||
486 |
///Cut a string on white characters ('\t' ou ' ') |
||
487 |
/** @param str : string to be cut |
||
488 |
@return vector of string |
||
489 |
*/ |
||
490 |
1 |
std::vector<std::string> cutStringOnSpacesVector(const std::string& str){ |
|
491 |
1 |
std::vector<std::string> vec; |
|
492 |
✓✗ | 1 |
if(str.size() != 0lu){ |
493 |
✓ | 2 |
std::string buffer(""); |
494 |
✓✓ | 14 |
for(std::string::const_iterator it(str.begin()); it != str.end(); ++it){ |
495 |
✓✗✓✓ ✓✗✓✓ |
13 |
if(*it != '\t' && *it != ' ' && *it !='\n'){ |
496 |
✓ | 11 |
buffer += *it; |
497 |
}else{ |
||
498 |
✓✗ | 2 |
if(buffer != ""){ |
499 |
✓ | 2 |
vec.push_back(buffer); |
500 |
✓ | 2 |
buffer = ""; |
501 |
} |
||
502 |
} |
||
503 |
} |
||
504 |
✓✗✓ | 1 |
if(buffer != "") vec.push_back(buffer); |
505 |
} |
||
506 |
1 |
return vec; |
|
507 |
} |
||
508 |
|||
509 |
///Copy a string of nbCh starting from begin char |
||
510 |
/** @param str : string to be copied |
||
511 |
@param begin : first character index |
||
512 |
@param nbCh : number of characters to be copied |
||
513 |
@return sub string of input string |
||
514 |
*/ |
||
515 |
3 |
std::string copyStr(const std::string& str, long unsigned int begin, long unsigned int nbCh){ |
|
516 |
✗✓✗✗ |
3 |
if(str.size() < begin) return ""; |
517 |
✗✓ | 3 |
if(str.size() < begin + nbCh) nbCh = str.size() - begin; |
518 |
✓ | 6 |
std::string str2(""); |
519 |
✓✓ | 18 |
for(long unsigned int i(begin); i < begin + nbCh; ++i){ |
520 |
✓ | 15 |
str2 += str[i]; |
521 |
} |
||
522 |
3 |
return str2; |
|
523 |
} |
||
524 |
|||
525 |
|||
526 |
///Check if two string start the same way |
||
527 |
/** @param str : string to be tested |
||
528 |
@param beginig : begining to be checked |
||
529 |
@return true if str starts as beginig |
||
530 |
*/ |
||
531 |
524 |
bool isSameBegining(const std::string & str, const std::string & beginig){ |
|
532 |
✓✓ | 524 |
if(str.size() < beginig.size()) return false; |
533 |
233 |
std::string::const_iterator it = str.begin(); |
|
534 |
233 |
std::string::const_iterator it2 = beginig.begin(); |
|
535 |
✓✓✓✓ ✓✓ |
1923 |
while(it != str.end() && it2 != beginig.end()){ |
536 |
✓✓ | 1820 |
if(*it != *it2){ return false;} |
537 |
1690 |
it++; |
|
538 |
1690 |
it2++; |
|
539 |
} |
||
540 |
103 |
return true; |
|
541 |
} |
||
542 |
|||
543 |
///Convert a char pointer into a string (event if the char pointer is NULL) |
||
544 |
/** @param ch : char pointer to be converted into a string |
||
545 |
* @return corresponding string, or empty string if the input char pointer is NULL |
||
546 |
*/ |
||
547 |
2 |
std::string phoenix_charToString(const char * ch){ |
|
548 |
✓✓ | 2 |
if(ch != NULL){ |
549 |
✓ | 2 |
std::string str(ch); |
550 |
1 |
return str; |
|
551 |
}else{ |
||
552 |
✓ | 1 |
return ""; |
553 |
} |
||
554 |
} |
||
555 |
|||
556 |
///Get the common begining between str1 and str2 |
||
557 |
/** @param str1 : string |
||
558 |
* @param str2 : string |
||
559 |
* @return common begining between str1 and str2 |
||
560 |
*/ |
||
561 |
5 |
std::string phoenix_getCommonBegining(const std::string & str1, const std::string & str2){ |
|
562 |
✓ | 5 |
std::string out(""); |
563 |
5 |
std::string::const_iterator it = str1.begin(); |
|
564 |
5 |
std::string::const_iterator it2 = str2.begin(); |
|
565 |
✓✓✓✓ ✓✓ |
9 |
while(it != str1.end() && it2 != str2.end()){ |
566 |
✓✓ | 6 |
if(*it == *it2){ |
567 |
✓ | 4 |
out += *it; |
568 |
}else{ |
||
569 |
2 |
break; |
|
570 |
} |
||
571 |
4 |
it++; |
|
572 |
4 |
it2++; |
|
573 |
} |
||
574 |
10 |
return out; |
|
575 |
} |
||
576 |
Generated by: GCOVR (Version 4.2) |