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