PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
string_function.cpp File Reference
#include "string_function.h"
+ Include dependency graph for string_function.cpp:

Go to the source code of this file.

Functions

std::string copyStr (const std::string &str, long unsigned int begin, long unsigned int nbCh)
 Copy a string of nbCh starting from begin char. More...
 
size_t countNbChar (const std::string &str, char ch)
 Count number of chararacters ch in string. More...
 
size_t countStrInStr (const std::string &src, const std::string &patern)
 Count the number of patern in string. More...
 
std::list< std::string > cutStringList (const std::string &str, char separator)
 Cut a string the the given separator char. More...
 
std::list< std::string > cutStringOnSpacesList (const std::string &str)
 Cut a string on white characters ('&#92;t' ou ' ') More...
 
std::vector< std::string > cutStringOnSpacesVector (const std::string &str)
 Cut a string on white characters ('&#92;t' ou ' ') More...
 
std::vector< std::string > cutStringVector (const std::string &str, char separator)
 Cut a string the the given separator char. More...
 
std::string eraseCharInStr (const std::string &str, char ch)
 copie la string str en effaçant le caractère ch More...
 
std::string eraseCharsInStr (const std::string &str, const std::string &rmchs)
 copie la string str en effaçant les caractères rmchs More...
 
std::string eraseFirstCharsInStr (const std::string &str, const std::string &chars)
 Erase first char in a string. More...
 
std::string eraseFirstLastChars (const std::string &str, const std::string &chars)
 Erase first and last char in a string. More...
 
std::vector< std::string > eraseFirstLastChars (const std::vector< std::string > &vecStr, const std::string &chars)
 Erase first and last char in a vector of strings. More...
 
std::string eraseLastCharsInStr (const std::string &str, const std::string &chars)
 Erase first and last char in a string. More...
 
bool findCharsInString (const std::string &str, const std::string &chars)
 Find multiple chars in a string. More...
 
bool findInListString (const std::list< std::string > &listStr, const std::string &str)
 Find a string in a list of string. More...
 
bool findInString (const std::string &str, char ch)
 Find a char in a string. More...
 
bool findInVectorString (const std::vector< std::string > &vecStr, const std::string &str)
 Find a string in a vector of string. More...
 
bool isSameBegining (const std::string &str, const std::string &beginig)
 Check if two string start the same way. More...
 
std::string phoenix_charToString (const char *ch)
 Convert a char pointer into a string (event if the char pointer is NULL) More...
 
std::string phoenix_escapeStr (const std::string &src, const std::string &strCharToEscape, const std::string &escapeStr)
 Escape given string with passed characters. More...
 
std::string phoenix_getCommonBegining (const std::string &str1, const std::string &str2)
 Get the common begining between str1 and str2. More...
 
std::string replaceCharInStr (const std::string &str, char find, char replace)
 fonction qui remplace un caractère par un autre dans une string More...
 
std::string replaceCharInStr (const std::string &str, char find, const std::string &replace)
 fonction qui remplace un caractère par un autre dans une string More...
 
std::string replaceCharsInStr (const std::string &str, const std::string &strFind, char replace)
 Replace all char in the strFind by char replace. More...
 
std::string replaceListStrInStr (const std::string &src, const std::list< std::string > &vecPatern, const std::string &replace)
 Replace all the list patern in the string srcDest by the replace string. More...
 
void replaceListStrInStr (std::string &srcDest, const std::list< std::string > &listPatern, const std::string &replace)
 Replace all the list patern in the string srcDest by the replace string. More...
 
std::string replaceStrInStr (const std::string &src, const std::map< std::string, std::string > &mapReplace)
 Replace a map of string in a string. More...
 
std::string replaceStrInStr (const std::string &src, const std::string &patern, const std::string &replace)
 Replace a patern by an other in the input string. More...
 
std::vector< std::string > replaceStrInStr (const std::vector< std::string > &vecSrc, const std::string &patern, const std::string &replace)
 Replace a patern by an other in the input string in a vector of string. More...
 
void replaceStrInStr (std::string &out, const std::string &src, const std::map< std::string, std::string > &mapReplace)
 Replace a map of string in a string. More...
 
void replaceStrInStr (std::string &out, const std::string &src, const std::string &patern, const std::string &replace)
 Replace a patern by an other in the input string. More...
 
std::string replaceVectorStrInStr (const std::string &src, const std::vector< std::string > &vecPatern, const std::string &replace)
 Replace all the vector patern in the string srcDest by the replace string. More...
 
void replaceVectorStrInStr (std::string &srcDest, const std::vector< std::string > &vecPatern, const std::string &replace)
 Replace all the vector patern in the string srcDest by the replace string. More...
 

Function Documentation

◆ copyStr()

std::string copyStr ( const std::string &  str,
long unsigned int  begin,
long unsigned int  nbCh 
)

Copy a string of nbCh starting from begin char.

Parameters
str: string to be copied
begin: first character index
nbCh: number of characters to be copied
Returns
sub string of input string

Definition at line 515 of file string_function.cpp.

515  {
516  if(str.size() < begin) return "";
517  if(str.size() < begin + nbCh) nbCh = str.size() - begin;
518  std::string str2("");
519  for(long unsigned int i(begin); i < begin + nbCh; ++i){
520  str2 += str[i];
521  }
522  return str2;
523 }

References createReleaseCurl::str.

Referenced by eraseLongestExtension(), and testStringFunction().

+ Here is the caller graph for this function:

◆ countNbChar()

size_t countNbChar ( const std::string &  str,
char  ch 
)

Count number of chararacters ch in string.

Parameters
str: string to be used
ch: character to be serached
Returns
number of character ch in string

Definition at line 145 of file string_function.cpp.

145  {
146  size_t nbChar(0lu);
147  std::string::const_iterator it(str.begin());
148  while(it != str.end()){
149  if(*it == ch) nbChar++;
150  it++;
151  }
152  return nbChar;
153 }

References createReleaseCurl::str.

Referenced by eraseExtension(), getLongestExtention(), printAllCol(), printAllColCerr(), and testStringFunction().

+ Here is the caller graph for this function:

◆ countStrInStr()

size_t countStrInStr ( const std::string &  src,
const std::string &  patern 
)

Count the number of patern in string.

Parameters
src: string to be analysed
patern: patern to be serached
Returns
number of occurence of patern in src

Definition at line 237 of file string_function.cpp.

237  {
238  long unsigned int sizePatern(patern.size());
239  if(sizePatern == 0lu || src == ""){return 0lu;}
240  size_t nbPaternFound(0lu);
241 
242  long unsigned int sizeSrc(src.size());
243  long unsigned int beginTest(0lu), nbMatch(0lu);
244  for(long unsigned int i(0lu); i < sizeSrc; ++i){
245  if(src[i] == patern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch
246  if(nbMatch == 0lu){ //c'est le premier qu'on teste
247  beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
248  }
249  ++nbMatch; //la prochaîne fois on testera le caractère suivant
250  if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
251  ++nbPaternFound;
252  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
253  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  if(nbMatch != 0lu){ //si on avais déjà tester des caractères avant
257  i = beginTest;
258  }
259  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
260  nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
261  }
262  }
263  return nbPaternFound;
264 }

Referenced by testStringFunction().

+ Here is the caller graph for this function:

◆ cutStringList()

std::list<std::string> cutStringList ( const std::string &  str,
char  separator 
)

Cut a string the the given separator char.

Parameters
str: string to be cut
separator: separtor char
Returns
list of string

Definition at line 428 of file string_function.cpp.

428  {
429  std::list<std::string> liste;
430  std::string buffer = "";
431  for(std::string::const_iterator it = str.begin(); it != str.end(); ++it){
432  if(*it != separator){
433  buffer += *it;
434  }else{
435  liste.push_back(buffer);
436  buffer = "";
437  }
438  }
439  if(buffer != ""){liste.push_back(buffer);}
440  return liste;
441 }

References createReleaseCurl::str.

Referenced by checkResultSeparator(), createDirectoriesIfNotExist(), getUnderPath(), removePathDots(), and testStringFunction().

+ Here is the caller graph for this function:

◆ cutStringOnSpacesList()

std::list<std::string> cutStringOnSpacesList ( const std::string &  str)

Cut a string on white characters ('&#92;t' ou ' ')

Parameters
str: string to be cut
Returns
list of string

Definition at line 467 of file string_function.cpp.

467  {
468  std::list<std::string> liste;
469  if(str.size() != 0lu){
470  std::string buffer("");
471  for(std::string::const_iterator it(str.begin()); it != str.end(); ++it){
472  if(*it != '\t' && *it != ' ' && *it !='\n'){
473  buffer += *it;
474  }else{
475  if(buffer != ""){
476  liste.push_back(buffer);
477  buffer = "";
478  }
479  }
480  }
481  if(buffer != "") liste.push_back(buffer);
482  }
483  return liste;
484 }

References createReleaseCurl::str.

Referenced by testStringFunction().

+ Here is the caller graph for this function:

◆ cutStringOnSpacesVector()

std::vector<std::string> cutStringOnSpacesVector ( const std::string &  str)

Cut a string on white characters ('&#92;t' ou ' ')

Parameters
str: string to be cut
Returns
vector of string

Definition at line 490 of file string_function.cpp.

490  {
491  std::vector<std::string> vec;
492  if(str.size() != 0lu){
493  std::string buffer("");
494  for(std::string::const_iterator it(str.begin()); it != str.end(); ++it){
495  if(*it != '\t' && *it != ' ' && *it !='\n'){
496  buffer += *it;
497  }else{
498  if(buffer != ""){
499  vec.push_back(buffer);
500  buffer = "";
501  }
502  }
503  }
504  if(buffer != "") vec.push_back(buffer);
505  }
506  return vec;
507 }

References createReleaseCurl::str.

Referenced by testStringFunction().

+ Here is the caller graph for this function:

◆ cutStringVector()

std::vector<std::string> cutStringVector ( const std::string &  str,
char  separator 
)

Cut a string the the given separator char.

Parameters
str: string to be cut
separator: separtor char
Returns
vector of string

Definition at line 448 of file string_function.cpp.

448  {
449  std::vector<std::string> vec;
450  std::string buffer = "";
451  for(std::string::const_iterator it = str.begin(); it != str.end(); ++it){
452  if(*it != separator){
453  buffer += *it;
454  }else{
455  vec.push_back(buffer);
456  buffer = "";
457  }
458  }
459  if(buffer != ""){vec.push_back(buffer);}
460  return vec;
461 }

References createReleaseCurl::str.

Referenced by phoenix_find(), and testStringFunction().

+ Here is the caller graph for this function:

◆ eraseCharInStr()

std::string eraseCharInStr ( const std::string &  str,
char  ch 
)

copie la string str en effaçant le caractère ch

Parameters
str: chaîne à copier
ch: caractère à effacer
Returns
string sans le caractère ch

Definition at line 160 of file string_function.cpp.

160  {
161  std::string buffer = "";
162  for(std::string::const_iterator it = str.begin(); it != str.end(); it++){
163  if(*it != ch) buffer += *it;
164  }
165  return buffer;
166 }

References createReleaseCurl::str.

Referenced by eraseCharsInStr(), and testStringFunction().

+ Here is the caller graph for this function:

◆ eraseCharsInStr()

std::string eraseCharsInStr ( const std::string &  str,
const std::string &  rmchs 
)

copie la string str en effaçant les caractères rmchs

Parameters
str: chaîne à copier
rmchs: caractères à effacer
Returns
string sans les caractères rmchs

Definition at line 173 of file string_function.cpp.

173  {
174  std::string buffer = str;
175  for(std::string::const_iterator it = rmchs.begin(); it != rmchs.end(); it++){
176  buffer = eraseCharInStr(buffer, *it);
177  }
178  return buffer;
179 }

References eraseCharInStr(), and createReleaseCurl::str.

Referenced by getCurrentNodeName(), and testStringFunction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eraseFirstCharsInStr()

std::string eraseFirstCharsInStr ( const std::string &  str,
const std::string &  chars 
)

Erase first char in a string.

Parameters
str: string to be modifed
chars: chars to be searched and removed
Returns
modifed string

Definition at line 77 of file string_function.cpp.

77  {
78  std::string buffer(str);
79  bool continuer = true;
80  std::string::iterator it = buffer.begin();
81  //Let's remove the first chars
82  while(it != buffer.end() && continuer){
83  if(findInString(chars, *it)){it = buffer.erase(it);}
84  else{
85  continuer = false;
86  it++;
87  }
88  }
89  return buffer;
90 }

References findInString(), and createReleaseCurl::str.

Referenced by checkEraseFirstChars(), and eraseFirstLastChars().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eraseFirstLastChars() [1/2]

std::string eraseFirstLastChars ( const std::string &  str,
const std::string &  chars 
)

Erase first and last char in a string.

Parameters
str: string to be modifed
chars: chars to be searched and removed
Returns
modifed string

Definition at line 122 of file string_function.cpp.

122  {
123  std::string buffer(eraseFirstCharsInStr(str, chars));
124  return eraseLastCharsInStr(buffer, chars);
125 }

References eraseFirstCharsInStr(), eraseLastCharsInStr(), and createReleaseCurl::str.

Referenced by checkEraseFirstLastChars(), checkEraseFirstLastCharsVector(), and eraseFirstLastChars().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eraseFirstLastChars() [2/2]

std::vector<std::string> eraseFirstLastChars ( const std::vector< std::string > &  vecStr,
const std::string &  chars 
)

Erase first and last char in a vector of strings.

Parameters
vecStr: vector of string to be modifed
chars: chars to be searched and removed
Returns
modifed vector of strings

Definition at line 132 of file string_function.cpp.

132  {
133  std::vector<std::string> vecOut;
134  for(std::vector<std::string>::const_iterator it(vecStr.begin()); it != vecStr.end(); ++it){
135  vecOut.push_back(eraseFirstLastChars(*it, chars));
136  }
137  return vecOut;
138 }

References eraseFirstLastChars().

+ Here is the call graph for this function:

◆ eraseLastCharsInStr()

std::string eraseLastCharsInStr ( const std::string &  str,
const std::string &  chars 
)

Erase first and last char in a string.

Parameters
str: string to be modifed
chars: chars to be searched and removed
Returns
modifed string

Definition at line 97 of file string_function.cpp.

97  {
98  if(str.size() > 0lu){
99  size_t nbCharToRemove(0lu);
100  std::string::const_reverse_iterator it(str.rbegin());
101  while(findInString(chars, *it)){
102  ++it;
103  ++nbCharToRemove;
104  }
105 
106  if(nbCharToRemove == 0lu){
107  return str;
108  }else{
109  std::string buffer(str.substr(0, str.size() - nbCharToRemove));
110  return buffer;
111  }
112  }else{
113  return str;
114  }
115 }

References findInString(), and createReleaseCurl::str.

Referenced by checkEraseLastChars(), eraseFirstLastChars(), and testFindInListString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findCharsInString()

bool findCharsInString ( const std::string &  str,
const std::string &  chars 
)

Find multiple chars in a string.

Parameters
str: string to be used
chars: chars to be searched
Returns
true if one of the chars has been found, false otherwise

Definition at line 29 of file string_function.cpp.

29  {
30  if(str.size() == 0lu || chars.size() == 0lu){return false;}
31  bool foundChar = false;
32  long unsigned int i(0lu), size(chars.size());
33  while(!foundChar && i < size){
34  foundChar = findInString(str, chars[i]);
35  ++i;
36  }
37  return foundChar;
38 }

References findInString(), and createReleaseCurl::str.

Referenced by testStringFunction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findInListString()

bool findInListString ( const std::list< std::string > &  listStr,
const std::string &  str 
)

Find a string in a list of string.

Parameters
listStr: list of string
str: string to be searched
Returns
true if the string has been found, false otherwise

Definition at line 45 of file string_function.cpp.

45  {
46  if(listStr.size() == 0lu || str == ""){return false;}
47  bool isSearch(true);
48  std::list<std::string>::const_iterator it(listStr.begin());
49  while(it != listStr.end() && isSearch){
50  isSearch = *it != str;
51  ++it;
52  }
53  return !isSearch;
54 }

References createReleaseCurl::str.

Referenced by testFindInListString().

+ Here is the caller graph for this function:

◆ findInString()

bool findInString ( const std::string &  str,
char  ch 
)

Find a char in a string.

Parameters
str: string to be used
ch: char to be searched
Returns
true if the char has been found, false otherwise

Definition at line 15 of file string_function.cpp.

15  {
16  std::string::const_iterator it = str.begin();
17  while(it != str.end()){
18  if(*it == ch) return true;
19  ++it;
20  }
21  return false;
22 }

References createReleaseCurl::str.

Referenced by eraseFirstCharsInStr(), eraseLastCharsInStr(), findCharsInString(), getExtention(), phoenix_escapeStr(), and testStringFunction().

+ Here is the caller graph for this function:

◆ findInVectorString()

bool findInVectorString ( const std::vector< std::string > &  vecStr,
const std::string &  str 
)

Find a string in a vector of string.

Parameters
vecStr: vector of string
str: string to be searched
Returns
true if the string has been found, false otherwise

Definition at line 61 of file string_function.cpp.

61  {
62  if(vecStr.size() == 0lu || str == ""){return false;}
63  bool isSearch(true);
64  std::vector<std::string>::const_iterator it(vecStr.begin());
65  while(it != vecStr.end() && isSearch){
66  isSearch = *it != str;
67  ++it;
68  }
69  return !isSearch;
70 }

References createReleaseCurl::str.

Referenced by testFindInListString().

+ Here is the caller graph for this function:

◆ isSameBegining()

bool isSameBegining ( const std::string &  str,
const std::string &  beginig 
)

Check if two string start the same way.

Parameters
str: string to be tested
beginig: begining to be checked
Returns
true if str starts as beginig

Definition at line 531 of file string_function.cpp.

531  {
532  if(str.size() < beginig.size()) return false;
533  std::string::const_iterator it = str.begin();
534  std::string::const_iterator it2 = beginig.begin();
535  while(it != str.end() && it2 != beginig.end()){
536  if(*it != *it2){ return false;}
537  it++;
538  it2++;
539  }
540  return true;
541 }

References createReleaseCurl::str.

Referenced by ArgParser::ArgParser(), completePathDir(), OptionParser::getLongOptionValue(), OptionMode::getPossibleMode(), OptionMode::getPossibleOption(), Option::getPossibleOption(), OptionParser::getPossibleOtherOption(), Option::parsePartOption(), path_completion_all(), path_completion_dirOnly(), and testStringFunction().

+ Here is the caller graph for this function:

◆ phoenix_charToString()

std::string phoenix_charToString ( const char *  ch)

Convert a char pointer into a string (event if the char pointer is NULL)

Parameters
ch: char pointer to be converted into a string
Returns
corresponding string, or empty string if the input char pointer is NULL

Definition at line 547 of file string_function.cpp.

547  {
548  if(ch != NULL){
549  std::string str(ch);
550  return str;
551  }else{
552  return "";
553  }
554 }

References createReleaseCurl::str.

Referenced by testCharToString().

+ Here is the caller graph for this function:

◆ phoenix_escapeStr()

std::string phoenix_escapeStr ( const std::string &  src,
const std::string &  strCharToEscape,
const std::string &  escapeStr 
)

Escape given string with passed characters.

Parameters
src: string to be excaped
strCharToEscape: list of the characters to be escaped
escapeStr: escape sequence (could be one char)
Returns
escaped string

Definition at line 411 of file string_function.cpp.

411  {
412  std::string out("");
413  for(size_t i(0lu); i < src.size(); ++i){
414  char ch = src[i];
415  if(findInString(strCharToEscape, ch)){
416  out += escapeStr;
417  }
418  out += ch;
419  }
420  return out;
421 }

References findInString().

Referenced by phoenix_listArgToString(), and testEscapeString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ phoenix_getCommonBegining()

std::string phoenix_getCommonBegining ( const std::string &  str1,
const std::string &  str2 
)

Get the common begining between str1 and str2.

Parameters
str1: string
str2: string
Returns
common begining between str1 and str2

Definition at line 561 of file string_function.cpp.

561  {
562  std::string out("");
563  std::string::const_iterator it = str1.begin();
564  std::string::const_iterator it2 = str2.begin();
565  while(it != str1.end() && it2 != str2.end()){
566  if(*it == *it2){
567  out += *it;
568  }else{
569  break;
570  }
571  it++;
572  it2++;
573  }
574  return out;
575 }

Referenced by testGetCommonBegning().

+ Here is the caller graph for this function:

◆ replaceCharInStr() [1/2]

std::string replaceCharInStr ( const std::string &  str,
char  find,
char  replace 
)

fonction qui remplace un caractère par un autre dans une string

Parameters
str: string à modifier
find: caractère à trouver dans la string
replace: caractère à remplacer dans la string
Returns
string modifiée

Definition at line 187 of file string_function.cpp.

187  {
188  std::string buffer = "";
189  for(std::string::const_iterator it = str.begin(); it != str.end(); it++){
190  if(*it == find){
191  buffer += replace;
192  }else{
193  buffer += *it;
194  }
195  }
196  return buffer;
197 }

References createReleaseCurl::str.

Referenced by replaceCharsInStr(), and testStringFunction().

+ Here is the caller graph for this function:

◆ replaceCharInStr() [2/2]

std::string replaceCharInStr ( const std::string &  str,
char  find,
const std::string &  replace 
)

fonction qui remplace un caractère par un autre dans une string

Parameters
str: string à modifier
find: caractère à trouver dans la string
replace: chaîne à remplacer dans la string
Returns
string modifiée

Definition at line 220 of file string_function.cpp.

220  {
221  std::string buffer = "";
222  for(std::string::const_iterator it = str.begin(); it != str.end(); it++){
223  if(*it == find){
224  buffer += replace;
225  }else{
226  buffer += *it;
227  }
228  }
229  return buffer;
230 }

References createReleaseCurl::str.

◆ replaceCharsInStr()

std::string replaceCharsInStr ( const std::string &  str,
const std::string &  strFind,
char  replace 
)

Replace all char in the strFind by char replace.

Parameters
str: string to be modified
strFind: string of the characters to be found
replace: character to be found
Returns
modified string

Definition at line 205 of file string_function.cpp.

205  {
206  if(str == "" || strFind == "") return str;
207  std::string out(str);
208  for(long unsigned int i(0lu); i < strFind.size(); ++i){
209  out = replaceCharInStr(out, strFind[i], replace);
210  }
211  return out;
212 }

References replaceCharInStr(), and createReleaseCurl::str.

Referenced by testStringFunction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replaceListStrInStr() [1/2]

std::string replaceListStrInStr ( const std::string &  src,
const std::list< std::string > &  vecPatern,
const std::string &  replace 
)

Replace all the list patern in the string srcDest by the replace string.

Parameters
src: source string
vecPatern: vector of the paterns we want to search
replace: string we want to replace
Returns
modified string

Definition at line 399 of file string_function.cpp.

399  {
400  std::string result(src);
401  replaceListStrInStr(result, vecPatern, replace);
402  return result;
403 }

References replaceListStrInStr().

+ Here is the call graph for this function:

◆ replaceListStrInStr() [2/2]

void replaceListStrInStr ( std::string &  srcDest,
const std::list< std::string > &  listPatern,
const std::string &  replace 
)

Replace all the list patern in the string srcDest by the replace string.

Parameters
[out]srcDest: source and modified string
listPatern: vector of the paterns we want to search
replace: string we want to replace

Definition at line 346 of file string_function.cpp.

346  {
347  if(srcDest == "" || listPatern.size() == 0lu) return;
348  for(std::list<std::string>::const_iterator it(listPatern.begin()); it != listPatern.end(); ++it){
349  srcDest = replaceStrInStr(srcDest, *it, replace);
350  }
351 }

References replaceStrInStr().

Referenced by checkReplaceListStrInStr(), and replaceListStrInStr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replaceStrInStr() [1/5]

std::string replaceStrInStr ( const std::string &  src,
const std::map< std::string, std::string > &  mapReplace 
)

Replace a map of string in a string.

Parameters
src: source string
mapReplace: map of patterns (keys) and value to replace (values)
Returns
updated string

Definition at line 375 of file string_function.cpp.

375  {
376  std::string out("");
377  replaceStrInStr(out, src, mapReplace);
378  return out;
379 }

References replaceStrInStr().

+ Here is the call graph for this function:

◆ replaceStrInStr() [2/5]

std::string replaceStrInStr ( const std::string &  src,
const std::string &  patern,
const std::string &  replace 
)

Replace a patern by an other in the input string.

Parameters
src: input string
patern: patern to be searched
replace: string which replace patern
Returns
output string

Definition at line 309 of file string_function.cpp.

309  {
310  std::string result("");
311  replaceStrInStr(result, src, patern, replace);
312  return result;
313 }

References replaceStrInStr().

+ Here is the call graph for this function:

◆ replaceStrInStr() [3/5]

std::vector<std::string> replaceStrInStr ( const std::vector< std::string > &  vecSrc,
const std::string &  patern,
const std::string &  replace 
)

Replace a patern by an other in the input string in a vector of string.

Parameters
vecSrc: vector of input strings
patern: patern to be searched
replace: string which replace patern
Returns
output string

Definition at line 321 of file string_function.cpp.

321  {
322  std::vector<std::string> vecOut;
323  for(std::vector<std::string>::const_iterator it(vecSrc.begin()); it != vecSrc.end(); ++it){
324  vecOut.push_back(replaceStrInStr(*it, patern, replace));
325  }
326  return vecOut;
327 }

References replaceStrInStr().

+ Here is the call graph for this function:

◆ replaceStrInStr() [4/5]

void replaceStrInStr ( std::string &  out,
const std::string &  src,
const std::map< std::string, std::string > &  mapReplace 
)

Replace a map of string in a string.

Parameters
[out]out: updated string
src: source string
mapReplace: map of patterns (keys) and value to replace (values)

Definition at line 358 of file string_function.cpp.

358  {
359  if(mapReplace.size() == 0lu){
360  out = src;
361  return;
362  }
363  std::string tmpStr(src);
364  for(std::map<std::string, std::string>::const_iterator it(mapReplace.begin()); it != mapReplace.end(); ++it){
365  replaceStrInStr(out, tmpStr, it->first, it->second);
366  tmpStr = out;
367  }
368 }

References replaceStrInStr().

+ Here is the call graph for this function:

◆ replaceStrInStr() [5/5]

void replaceStrInStr ( std::string &  out,
const std::string &  src,
const std::string &  patern,
const std::string &  replace 
)

Replace a patern by an other in the input string.

Parameters
[out]out: output string
src: input string
patern: patern to be searched
replace: string which replace patern

Definition at line 272 of file string_function.cpp.

272  {
273  long unsigned int sizePatern(patern.size());
274  if(sizePatern == 0lu || src == "") return;
275  out = ""; //on évite les petits désagréments
276  long unsigned int sizeSrc(src.size());
277  long unsigned int beginTest(0lu), nbMatch(0lu);
278  for(long unsigned int i(0lu); i < sizeSrc; ++i){
279  if(src[i] == patern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch
280  if(nbMatch == 0lu){ //c'est le premier qu'on teste
281  beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
282  }
283  ++nbMatch; //la prochaîne fois on testera le caractère suivant
284  if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
285  out += replace; //on a trouver le motif patern, donc on le remplace par le motif replace
286  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
287  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  if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant
291  out += src[i]; //on ne change rien à ce caractère
292  }else{ //si on avais déjà tester des caractères avant
293  out += src[beginTest];
294  i = beginTest;
295  }
296  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
297  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 }

Referenced by ArgParser::ArgParser(), replaceListStrInStr(), replaceStrInStr(), replaceVectorStrInStr(), testFindInListString(), testReplaceStrInStrMap(), and testStringFunction().

+ Here is the caller graph for this function:

◆ replaceVectorStrInStr() [1/2]

std::string replaceVectorStrInStr ( const std::string &  src,
const std::vector< std::string > &  vecPatern,
const std::string &  replace 
)

Replace all the vector patern in the string srcDest by the replace string.

Parameters
src: source string
vecPatern: vector of the paterns we want to search
replace: string we want to replace
Returns
modified string

Definition at line 387 of file string_function.cpp.

387  {
388  std::string result(src);
389  replaceVectorStrInStr(result, vecPatern, replace);
390  return result;
391 }

References replaceVectorStrInStr().

+ Here is the call graph for this function:

◆ replaceVectorStrInStr() [2/2]

void replaceVectorStrInStr ( std::string &  srcDest,
const std::vector< std::string > &  vecPatern,
const std::string &  replace 
)

Replace all the vector patern in the string srcDest by the replace string.

Parameters
[out]srcDest: source and modified string
vecPatern: vector of the paterns we want to search
replace: string we want to replace

Definition at line 334 of file string_function.cpp.

334  {
335  if(srcDest == "" || vecPatern.size() == 0lu) return;
336  for(std::vector<std::string>::const_iterator it(vecPatern.begin()); it != vecPatern.end(); ++it){
337  srcDest = replaceStrInStr(srcDest, *it, replace);
338  }
339 }

References replaceStrInStr().

Referenced by checkReplaceVectorStrInStr(), and replaceVectorStrInStr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:
eraseCharInStr
std::string eraseCharInStr(const std::string &str, char ch)
copie la string str en effaçant le caractère ch
Definition: string_function.cpp:160
eraseFirstCharsInStr
std::string eraseFirstCharsInStr(const std::string &str, const std::string &chars)
Erase first char in a string.
Definition: string_function.cpp:77
replaceListStrInStr
void replaceListStrInStr(std::string &srcDest, const std::list< std::string > &listPatern, const std::string &replace)
Replace all the list patern in the string srcDest by the replace string.
Definition: string_function.cpp:346
findInString
bool findInString(const std::string &str, char ch)
Find a char in a string.
Definition: string_function.cpp:15
replaceCharInStr
std::string replaceCharInStr(const std::string &str, char find, char replace)
fonction qui remplace un caractère par un autre dans une string
Definition: string_function.cpp:187
replaceVectorStrInStr
void replaceVectorStrInStr(std::string &srcDest, const std::vector< std::string > &vecPatern, const std::string &replace)
Replace all the vector patern in the string srcDest by the replace string.
Definition: string_function.cpp:334
createReleaseCurl.str
str
Definition: createReleaseCurl.py:128
eraseLastCharsInStr
std::string eraseLastCharsInStr(const std::string &str, const std::string &chars)
Erase first and last char in a string.
Definition: string_function.cpp:97
eraseFirstLastChars
std::string eraseFirstLastChars(const std::string &str, const std::string &chars)
Erase first and last char in a string.
Definition: string_function.cpp:122
replaceStrInStr
void replaceStrInStr(std::string &out, const std::string &src, const std::string &patern, const std::string &replace)
Replace a patern by an other in the input string.
Definition: string_function.cpp:272