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 |
31905 |
bool findInString(const std::string& str, char ch){ |
|
16 |
31905 |
std::string::const_iterator it = str.begin(); |
|
17 |
✓✓ | 348984 |
while(it != str.end()){ |
18 |
✓✓ | 327829 |
if(*it == ch) return true; |
19 |
317079 |
++it; |
|
20 |
} |
||
21 |
21155 |
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 |
512 |
std::string eraseFirstCharsInStr(const std::string& str, const std::string & chars){ |
|
78 |
✓ | 512 |
std::string buffer(str); |
79 |
512 |
bool continuer = true; |
|
80 |
512 |
std::string::iterator it = buffer.begin(); |
|
81 |
//Let's remove the first chars |
||
82 |
✓✓✓✓ ✓✓ |
2269 |
while(it != buffer.end() && continuer){ |
83 |
✓✓✓✓ |
1757 |
if(findInString(chars, *it)){it = buffer.erase(it);} |
84 |
else{ |
||
85 |
356 |
continuer = false; |
|
86 |
356 |
it++; |
|
87 |
} |
||
88 |
} |
||
89 |
1024 |
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 |
493 |
std::string eraseLastCharsInStr(const std::string& str, const std::string & chars){ |
|
98 |
✓✓ | 493 |
if(str.size() > 0lu){ |
99 |
336 |
size_t nbCharToRemove(0lu); |
|
100 |
336 |
std::string::const_reverse_iterator it(str.rbegin()); |
|
101 |
✓✓✓ | 836 |
while(findInString(chars, *it)){ |
102 |
500 |
++it; |
|
103 |
500 |
++nbCharToRemove; |
|
104 |
} |
||
105 |
|||
106 |
✓✓ | 336 |
if(nbCharToRemove == 0lu){ |
107 |
✓ | 46 |
return str; |
108 |
}else{ |
||
109 |
✓ | 580 |
std::string buffer(str.substr(0, str.size() - nbCharToRemove)); |
110 |
290 |
return buffer; |
|
111 |
} |
||
112 |
}else{ |
||
113 |
157 |
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 |
488 |
std::string eraseFirstLastChars(const std::string& str, const std::string & chars){ |
|
123 |
✓ | 976 |
std::string buffer(eraseFirstCharsInStr(str, chars)); |
124 |
✓ | 976 |
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 |
47 |
size_t countNbChar(const std::string & str, char ch){ |
|
133 |
47 |
size_t nbChar(0lu); |
|
134 |
47 |
std::string::const_iterator it(str.begin()); |
|
135 |
✓✓ | 1048 |
while(it != str.end()){ |
136 |
✓✓ | 1001 |
if(*it == ch) nbChar++; |
137 |
1001 |
it++; |
|
138 |
} |
||
139 |
47 |
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 |
154315 |
std::string eraseCharInStr(const std::string& str, char ch){ |
|
148 |
✓ | 154315 |
std::string buffer = ""; |
149 |
✓✓ | 216473 |
for(std::string::const_iterator it = str.begin(); it != str.end(); it++){ |
150 |
✓✓✓ | 62158 |
if(*it != ch) buffer += *it; |
151 |
} |
||
152 |
154315 |
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 |
2545 |
std::string eraseCharsInStr(const std::string& str, const std::string & rmchs){ |
|
161 |
2545 |
std::string buffer = str; |
|
162 |
✓✓ | 156858 |
for(std::string::const_iterator it = rmchs.begin(); it != rmchs.end(); it++){ |
163 |
✓ | 154313 |
buffer = eraseCharInStr(buffer, *it); |
164 |
} |
||
165 |
2545 |
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 |
1 |
std::string replaceCharInStr(const std::string& str, char find, const std::string& replace){ |
|
208 |
✓ | 1 |
std::string buffer = ""; |
209 |
✓✓ | 23 |
for(std::string::const_iterator it = str.begin(); it != str.end(); it++){ |
210 |
✓✓ | 22 |
if(*it == find){ |
211 |
✓ | 2 |
buffer += replace; |
212 |
}else{ |
||
213 |
✓ | 20 |
buffer += *it; |
214 |
} |
||
215 |
} |
||
216 |
1 |
return buffer; |
|
217 |
} |
||
218 |
|||
219 |
///fonction qui remplace un modif de caractères par un autre dans une chaîne de caractere |
||
220 |
/** @param out : chaîne de caractères après traitement |
||
221 |
* @param src : chaîne de caractères source, à modifier |
||
222 |
* @param patern : motif à chercher dans la chaîne de caractères source |
||
223 |
* @param replace : motif se substituant à patern |
||
224 |
*/ |
||
225 |
66 |
void replaceStrInStr(std::string & out, const std::string & src, const std::string & patern, const std::string & replace){ |
|
226 |
66 |
long unsigned int sizePatern(patern.size()); |
|
227 |
✓✓✓✓ ✓✓ |
66 |
if(sizePatern == 0lu || src == "") return; |
228 |
63 |
out = ""; //on évite les petits désagréments |
|
229 |
63 |
long unsigned int sizeSrc(src.size()); |
|
230 |
63 |
long unsigned int beginTest(0lu), nbMatch(0lu); |
|
231 |
✓✓ | 3503 |
for(long unsigned int i(0lu); i < sizeSrc; ++i){ |
232 |
✓✓ | 3440 |
if(src[i] == patern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch |
233 |
✓✓ | 1638 |
if(nbMatch == 0lu){ //c'est le premier qu'on teste |
234 |
109 |
beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste |
|
235 |
} |
||
236 |
1638 |
++nbMatch; //la prochaîne fois on testera le caractère suivant |
|
237 |
✓✓ | 1638 |
if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde |
238 |
63 |
out += replace; //on a trouver le motif patern, donc on le remplace par le motif replace |
|
239 |
63 |
beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais) |
|
240 |
63 |
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 |
✓✓ | 1802 |
if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant |
244 |
1756 |
out += src[i]; //on ne change rien à ce caractère |
|
245 |
}else{ //si on avais déjà tester des caractères avant |
||
246 |
// for(long unsigned int k(beginTest); k <= i; ++k){ //on rajoute tout les caractères qu'il ne faut pas modifier |
||
247 |
// out += src[k]; |
||
248 |
// } |
||
249 |
46 |
out += src[beginTest]; |
|
250 |
46 |
i = beginTest; |
|
251 |
} |
||
252 |
1802 |
beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais) |
|
253 |
1802 |
nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif |
|
254 |
} |
||
255 |
} |
||
256 |
//We are potentially at the end of the source, so no more test |
||
257 |
} |
||
258 |
|||
259 |
///fonction qui remplace un modif de caractères par un autre dans une chaîne de caractere |
||
260 |
/** @param src : chaîne de caractères source, à modifier |
||
261 |
* @param patern : motif à chercher dans la chaîne de caractères source |
||
262 |
* @param replace : motif se substituant à patern |
||
263 |
* @return chaîne de caractères après traitement |
||
264 |
*/ |
||
265 |
66 |
std::string replaceStrInStr(const std::string & src, const std::string & patern, const std::string & replace){ |
|
266 |
✓ | 66 |
std::string result(""); |
267 |
✓ | 66 |
replaceStrInStr(result, src, patern, replace); |
268 |
66 |
return result; |
|
269 |
} |
||
270 |
|||
271 |
///Replace all the vector patern in the string srcDest by the replace string |
||
272 |
/** @param[out] srcDest : source and modified string |
||
273 |
* @param vecPatern : vector of the paterns we want to search |
||
274 |
* @param replace : string we want to replace |
||
275 |
*/ |
||
276 |
5 |
void replaceVectorStrInStr(std::string & srcDest, const std::vector<std::string> & vecPatern, const std::string & replace){ |
|
277 |
✓✓✓✓ ✓✓ |
5 |
if(srcDest == "" || vecPatern.size() == 0lu) return; |
278 |
✓✓ | 5 |
for(std::vector<std::string>::const_iterator it(vecPatern.begin()); it != vecPatern.end(); ++it){ |
279 |
✓ | 3 |
srcDest = replaceStrInStr(srcDest, *it, replace); |
280 |
} |
||
281 |
} |
||
282 |
|||
283 |
///Replace all the list patern in the string srcDest by the replace string |
||
284 |
/** @param[out] srcDest : source and modified string |
||
285 |
* @param listPatern : vector of the paterns we want to search |
||
286 |
* @param replace : string we want to replace |
||
287 |
*/ |
||
288 |
5 |
void replaceListStrInStr(std::string & srcDest, const std::list<std::string> & listPatern, const std::string & replace){ |
|
289 |
✓✓✓✓ ✓✓ |
5 |
if(srcDest == "" || listPatern.size() == 0lu) return; |
290 |
✓✓ | 5 |
for(std::list<std::string>::const_iterator it(listPatern.begin()); it != listPatern.end(); ++it){ |
291 |
✓ | 3 |
srcDest = replaceStrInStr(srcDest, *it, replace); |
292 |
} |
||
293 |
} |
||
294 |
|||
295 |
///Replace all the vector patern in the string srcDest by the replace string |
||
296 |
/** @param src : source string |
||
297 |
* @param vecPatern : vector of the paterns we want to search |
||
298 |
* @param replace : string we want to replace |
||
299 |
* @return modified string |
||
300 |
*/ |
||
301 |
5 |
std::string replaceVectorStrInStr(const std::string & src, const std::vector<std::string> & vecPatern, const std::string & replace){ |
|
302 |
5 |
std::string result(src); |
|
303 |
✓ | 5 |
replaceVectorStrInStr(result, vecPatern, replace); |
304 |
5 |
return result; |
|
305 |
} |
||
306 |
|||
307 |
///Replace all the list patern in the string srcDest by the replace string |
||
308 |
/** @param src : source string |
||
309 |
* @param vecPatern : vector of the paterns we want to search |
||
310 |
* @param replace : string we want to replace |
||
311 |
* @return modified string |
||
312 |
*/ |
||
313 |
5 |
std::string replaceListStrInStr(const std::string & src, const std::list<std::string> & vecPatern, const std::string & replace){ |
|
314 |
5 |
std::string result(src); |
|
315 |
✓ | 5 |
replaceListStrInStr(result, vecPatern, replace); |
316 |
5 |
return result; |
|
317 |
} |
||
318 |
|||
319 |
///Escape given string with passed characters |
||
320 |
/** @param src : string to be excaped |
||
321 |
* @param strCharToEscape : list of the characters to be escaped |
||
322 |
* @param escapeStr : escape sequence (could be one char) |
||
323 |
* @return escaped string |
||
324 |
*/ |
||
325 |
8 |
std::string phoenix_escapeStr(const std::string & src, const std::string & strCharToEscape, const std::string & escapeStr){ |
|
326 |
✓ | 8 |
std::string out(""); |
327 |
✓✓ | 454 |
for(size_t i(0lu); i < src.size(); ++i){ |
328 |
446 |
char ch = src[i]; |
|
329 |
✓✓✓ | 446 |
if(findInString(strCharToEscape, ch)){ |
330 |
✓ | 7 |
out += escapeStr; |
331 |
} |
||
332 |
✓ | 446 |
out += ch; |
333 |
} |
||
334 |
8 |
return out; |
|
335 |
} |
||
336 |
|||
337 |
///Cut a string the the given separator char |
||
338 |
/** @param str : string to be cut |
||
339 |
@param separator : separtor char |
||
340 |
@return list of string |
||
341 |
*/ |
||
342 |
63 |
std::list<std::string> cutStringList(const std::string & str, char separator){ |
|
343 |
63 |
std::list<std::string> liste; |
|
344 |
✓ | 126 |
std::string buffer = ""; |
345 |
✓✓ | 3372 |
for(std::string::const_iterator it = str.begin(); it != str.end(); ++it){ |
346 |
✓✓ | 3309 |
if(*it != separator){ |
347 |
✓ | 3089 |
buffer += *it; |
348 |
}else{ |
||
349 |
✓ | 220 |
liste.push_back(buffer); |
350 |
✓ | 220 |
buffer = ""; |
351 |
} |
||
352 |
} |
||
353 |
✓✓✓ | 63 |
if(buffer != ""){liste.push_back(buffer);} |
354 |
126 |
return liste; |
|
355 |
} |
||
356 |
|||
357 |
///Cut a string the the given separator char |
||
358 |
/** @param str : string to be cut |
||
359 |
@param separator : separtor char |
||
360 |
@return vector of string |
||
361 |
*/ |
||
362 |
53 |
std::vector<std::string> cutStringVector(const std::string & str, char separator){ |
|
363 |
53 |
std::vector<std::string> vec; |
|
364 |
✓ | 106 |
std::string buffer = ""; |
365 |
✓✓ | 482 |
for(std::string::const_iterator it = str.begin(); it != str.end(); ++it){ |
366 |
✓✓ | 429 |
if(*it != separator){ |
367 |
✓ | 426 |
buffer += *it; |
368 |
}else{ |
||
369 |
✓ | 3 |
vec.push_back(buffer); |
370 |
✓ | 3 |
buffer = ""; |
371 |
} |
||
372 |
} |
||
373 |
✓✗✓ | 53 |
if(buffer != ""){vec.push_back(buffer);} |
374 |
106 |
return vec; |
|
375 |
} |
||
376 |
|||
377 |
///Cut a string on white characters ('\t' ou ' ') |
||
378 |
/** @param str : string to be cut |
||
379 |
@return list of string |
||
380 |
*/ |
||
381 |
1 |
std::list<std::string> cutStringOnSpacesList(const std::string& str){ |
|
382 |
1 |
std::list<std::string> liste; |
|
383 |
✓✗ | 1 |
if(str.size() != 0lu){ |
384 |
✓ | 2 |
std::string buffer(""); |
385 |
✓✓ | 14 |
for(std::string::const_iterator it(str.begin()); it != str.end(); ++it){ |
386 |
✓✗✓✓ ✓✗✓✓ |
13 |
if(*it != '\t' && *it != ' ' && *it !='\n'){ |
387 |
✓ | 11 |
buffer += *it; |
388 |
}else{ |
||
389 |
✓✗ | 2 |
if(buffer != ""){ |
390 |
✓ | 2 |
liste.push_back(buffer); |
391 |
✓ | 2 |
buffer = ""; |
392 |
} |
||
393 |
} |
||
394 |
} |
||
395 |
✓✗✓ | 1 |
if(buffer != "") liste.push_back(buffer); |
396 |
} |
||
397 |
1 |
return liste; |
|
398 |
} |
||
399 |
|||
400 |
///Cut a string on white characters ('\t' ou ' ') |
||
401 |
/** @param str : string to be cut |
||
402 |
@return vector of string |
||
403 |
*/ |
||
404 |
1 |
std::vector<std::string> cutStringOnSpacesVector(const std::string& str){ |
|
405 |
1 |
std::vector<std::string> vec; |
|
406 |
✓✗ | 1 |
if(str.size() != 0lu){ |
407 |
✓ | 2 |
std::string buffer(""); |
408 |
✓✓ | 14 |
for(std::string::const_iterator it(str.begin()); it != str.end(); ++it){ |
409 |
✓✗✓✓ ✓✗✓✓ |
13 |
if(*it != '\t' && *it != ' ' && *it !='\n'){ |
410 |
✓ | 11 |
buffer += *it; |
411 |
}else{ |
||
412 |
✓✗ | 2 |
if(buffer != ""){ |
413 |
✓ | 2 |
vec.push_back(buffer); |
414 |
✓ | 2 |
buffer = ""; |
415 |
} |
||
416 |
} |
||
417 |
} |
||
418 |
✓✗✓ | 1 |
if(buffer != "") vec.push_back(buffer); |
419 |
} |
||
420 |
1 |
return vec; |
|
421 |
} |
||
422 |
|||
423 |
///Copy a string of nbCh starting from begin char |
||
424 |
/** @param str : string to be copied |
||
425 |
@param begin : first character index |
||
426 |
@param nbCh : number of characters to be copied |
||
427 |
@return sub string of input string |
||
428 |
*/ |
||
429 |
1 |
std::string copyStr(const std::string& str, long unsigned int begin, long unsigned int nbCh){ |
|
430 |
✗✓✗✗ |
1 |
if(str.size() < begin) return ""; |
431 |
✗✓ | 1 |
if(str.size() < begin + nbCh) nbCh = str.size() - begin; |
432 |
✓ | 2 |
std::string str2(""); |
433 |
✓✓ | 5 |
for(long unsigned int i(begin); i < begin + nbCh; ++i){ |
434 |
✓ | 4 |
str2 += str[i]; |
435 |
} |
||
436 |
1 |
return str2; |
|
437 |
} |
||
438 |
|||
439 |
|||
440 |
///Check if two string start the same way |
||
441 |
/** @param str : string to be tested |
||
442 |
@param beginig : begining to be checked |
||
443 |
@return true if str starts as beginig |
||
444 |
*/ |
||
445 |
528 |
bool isSameBegining(const std::string & str, const std::string & beginig){ |
|
446 |
✓✓ | 528 |
if(str.size() < beginig.size()) return false; |
447 |
239 |
std::string::const_iterator it = str.begin(); |
|
448 |
239 |
std::string::const_iterator it2 = beginig.begin(); |
|
449 |
✓✓✓✓ ✓✓ |
1969 |
while(it != str.end() && it2 != beginig.end()){ |
450 |
✓✓ | 1866 |
if(*it != *it2){ return false;} |
451 |
1730 |
it++; |
|
452 |
1730 |
it2++; |
|
453 |
} |
||
454 |
103 |
return true; |
|
455 |
} |
||
456 |
|||
457 |
///Convert a char pointer into a string (event if the char pointer is NULL) |
||
458 |
/** @param ch : char pointer to be converted into a string |
||
459 |
* @return corresponding string, or empty string if the input char pointer is NULL |
||
460 |
*/ |
||
461 |
2 |
std::string phoenix_charToString(const char * ch){ |
|
462 |
✓✓ | 2 |
if(ch != NULL){ |
463 |
✓ | 2 |
std::string str(ch); |
464 |
1 |
return str; |
|
465 |
}else{ |
||
466 |
✓ | 1 |
return ""; |
467 |
} |
||
468 |
} |
||
469 |
|||
470 |
///Get the common begining between str1 and str2 |
||
471 |
/** @param str1 : string |
||
472 |
* @param str2 : string |
||
473 |
* @return common begining between str1 and str2 |
||
474 |
*/ |
||
475 |
5 |
std::string phoenix_getCommonBegining(const std::string & str1, const std::string & str2){ |
|
476 |
✓ | 5 |
std::string out(""); |
477 |
5 |
std::string::const_iterator it = str1.begin(); |
|
478 |
5 |
std::string::const_iterator it2 = str2.begin(); |
|
479 |
✓✓✓✓ ✓✓ |
9 |
while(it != str1.end() && it2 != str2.end()){ |
480 |
✓✓ | 6 |
if(*it == *it2){ |
481 |
✓ | 4 |
out += *it; |
482 |
}else{ |
||
483 |
2 |
break; |
|
484 |
} |
||
485 |
4 |
it++; |
|
486 |
4 |
it2++; |
|
487 |
} |
||
488 |
10 |
return out; |
|
489 |
} |
||
490 |
Generated by: GCOVR (Version 4.2) |