PhoenixClockMock  2.0.0
Tool to manipulate mock of clock (split, merge and get info)
PString Class Reference

Extends the std::string. More...

#include <PString.h>

+ Inheritance diagram for PString:
+ Collaboration diagram for PString:

Public Member Functions

PStringadd (char ch)
 Add a char to an other. More...
 
PStringadd (const char *str)
 Add a char pointer to an other. More...
 
PStringadd (const PString &other)
 Add a PString to an other. More...
 
PStringadd (const std::string &other)
 Add a std::string to an other. More...
 
size_t count (char ch) const
 Count the number of char ch in the current PString. More...
 
size_t count (const PString &patern) const
 Count the number of patern in string. More...
 
PString eraseChar (char ch) const
 Erase char ch of current string. More...
 
PString eraseChar (const PString &vecChar) const
 Erase char ch of current string. More...
 
PString eraseFirstChar (const PString &vecChar) const
 Erase first char in a string. More...
 
PString eraseFirstLastChar (const PString &vecChar) const
 Erase first and last char in a string. More...
 
PString eraseLastChar (const PString &vecChar) const
 Erase first and last char in a string. More...
 
PString escapeStr (const PString &strCharToEscape, const PString &escapeSeq) const
 Escape given string with passed characters. More...
 
bool find (char ch) const
 Find a char in a string. More...
 
bool find (const PString &listChar) const
 Find multiple chars in a string. More...
 
size_t findPatternIndex (const PString &pattern, size_t offset=0lu) const
 Get the index of the first character of the given pattern. More...
 
PString firstToLower () const
 Convert first letter of the PString in lower case. More...
 
PString firstToUpper () const
 Convert first letter of the PString in upper case. More...
 
PString format (const PString &arg) const
 Replace first {} with arg. More...
 
template<typename T >
PStringfromValue (const T &other)
 Convert a value to a PString. More...
 
PString getBetweenDelimiter (const PString &beginPattern, const PString &endPattern) const
 Get the PString between delimiter. More...
 
PString getCommonBegining (const PString &other) const
 Get the common begining between the current PString and other. More...
 
bool isLowerCase () const
 Say if the given PString is in lowercase. More...
 
bool isNumber () const
 Say if the given PString is composed of numbers. More...
 
bool isSameBegining (const PString &beginStr) const
 Say if the current PString has the same begining of beginStr. More...
 
bool isUpperCase () const
 Say if the given PString is in uppercase. More...
 
PString keepChar (const PString &listChar) const
 Keep only the characters in the given listChar. More...
 
PStringmerge (const std::vector< PString > &vecStr, const PString &separator="")
 Merge a set of PString. More...
 
PStringoperator+= (char ch)
 Add a char to an other. More...
 
PStringoperator+= (const PString &other)
 Add a PString to an other. More...
 
PStringoperator+= (const std::string &other)
 Add a std::string to an other. More...
 
template<typename T >
PStringoperator+= (const T &other)
 Append type in PString. More...
 
template<typename T >
PStringoperator<< (const T &other)
 Append type in PString. More...
 
PStringoperator= (const PString &other)
 Definition of equal operator of PString. More...
 
PStringoperator= (const std::string &other)
 Definition of equal operator of PString and std::string. More...
 
template<typename T >
PStringoperator= (const T &other)
 Set type in PString. More...
 
 PString ()
 Default constructor of PString. More...
 
 PString (const char *str)
 Default constructor of PString. More...
 
 PString (const PString &other)
 Copy constructor of PString. More...
 
 PString (const std::string &str)
 Default constructor of PString. More...
 
PString replace (const PString &pattern, const PString &replaceStr) const
 Replace a PString into an other PString. More...
 
PString replace (const PString &pattern, const PString &replaceStr, size_t maxNbReplace) const
 Replace a PString into an other PString. More...
 
PString replaceChar (const PString &vecChar, const PString &replaceStr) const
 Replace characters in vecChar by replaceStr. More...
 
std::vector< PStringsplit (char separator) const
 Cut a PString on the given separator char. More...
 
std::vector< PStringsplit (const PString &vecSeparator) const
 Split the PString on any given characters of vecSeparator. More...
 
PString toLower () const
 Convert PString in lower case. More...
 
PString toLowerUnderscore () const
 Convert std::string in lower case and space in '_'. More...
 
PString toUpper () const
 Convert std::string in upper case. More...
 
template<typename T >
toValue () const
 Convert the current string into a value. More...
 
virtual ~PString ()
 Destructeur of PString. More...
 

Static Public Member Functions

template<typename T >
static PString toString (const T &value)
 Convert a value to a PString. More...
 
template<typename T >
static T toValue (const PString &other)
 Convert the given string into a value. More...
 

Protected Member Functions

void concatenatePString (const PString &other)
 Concatenate a PString into the current PString. More...
 
void concatenatePString (const std::string &other)
 Concatenate a std::string into the current PString. More...
 
void copyPString (const PString &other)
 Copy function of PString. More...
 
void copyPString (const std::string &other)
 Copy function of PString. More...
 

Private Member Functions

void initialisationPString ()
 Initialisation function of the class PString. More...
 

Detailed Description

Extends the std::string.

Definition at line 16 of file PString.h.

Constructor & Destructor Documentation

◆ PString() [1/4]

PString::PString ( )

Default constructor of PString.

Definition at line 86 of file PString.cpp.

87  :std::string("")
88 {
90 }
void initialisationPString()
Initialisation function of the class PString.
Definition: PString.cpp:818

References initialisationPString().

Referenced by PPath::getExtension(), PPath::getParentDirectory(), PPath::getProgramDirectory(), PPath::getProgramLocation(), and PPath::simplify().

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

◆ PString() [2/4]

PString::PString ( const char *  str)

Default constructor of PString.

Parameters
str: pointer to initialise the PString

Definition at line 95 of file PString.cpp.

96  :std::string(str)
97 {
99 }

References initialisationPString().

+ Here is the call graph for this function:

◆ PString() [3/4]

PString::PString ( const std::string &  str)

Default constructor of PString.

Parameters
str: string to initialise the PString

Definition at line 104 of file PString.cpp.

105  :std::string(str)
106 {
108 }

References initialisationPString().

+ Here is the call graph for this function:

◆ PString() [4/4]

PString::PString ( const PString other)

Copy constructor of PString.

Parameters
other: class to copy

Definition at line 113 of file PString.cpp.

114  :std::string()
115 {
116  copyPString(other);
117 }
void copyPString(const PString &other)
Copy function of PString.
Definition: PString.cpp:784

References copyPString().

+ Here is the call graph for this function:

◆ ~PString()

PString::~PString ( )
virtual

Destructeur of PString.

Definition at line 120 of file PString.cpp.

120  {
121 
122 }

Member Function Documentation

◆ add() [1/4]

PString & PString::add ( char  ch)

Add a char to an other.

Parameters
ch: char to be added to the current one
Returns
PString

Definition at line 188 of file PString.cpp.

188  {
189  std::string str;
190  str+= ch;
191  concatenatePString(str);
192  return *this;
193 }
void concatenatePString(const PString &other)
Concatenate a PString into the current PString.
Definition: PString.cpp:800

References concatenatePString().

+ Here is the call graph for this function:

◆ add() [2/4]

PString & PString::add ( const char *  str)

Add a char pointer to an other.

Parameters
str: char pointer to be added to the current one
Returns
PString

Definition at line 199 of file PString.cpp.

199  {
201  return *this;
202 }
PString phoenix_charToString(const char *ch)
Convert a char pointer into a string (event if the char pointer is NULL)
Definition: PString.cpp:14

References concatenatePString(), and phoenix_charToString().

+ Here is the call graph for this function:

◆ add() [3/4]

PString & PString::add ( const PString other)

Add a PString to an other.

Parameters
other: PString to be added to the current one
Returns
PString

Definition at line 170 of file PString.cpp.

170  {
171  concatenatePString(other);
172  return *this;
173 }

References concatenatePString().

Referenced by PPath::makeAbsolute(), and operator+=().

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

◆ add() [4/4]

PString & PString::add ( const std::string &  other)

Add a std::string to an other.

Parameters
other: std::string to be added to the current one
Returns
PString

Definition at line 179 of file PString.cpp.

179  {
180  concatenatePString(other);
181  return *this;
182 }

References concatenatePString().

+ Here is the call graph for this function:

◆ concatenatePString() [1/2]

void PString::concatenatePString ( const PString other)
protected

Concatenate a PString into the current PString.

Parameters
other: PString to be added

Definition at line 800 of file PString.cpp.

800  {
801  std::string tmp(*this);
802  resize(tmp.size() + other.size());
803  memcpy((char*)data(), tmp.data(), tmp.size());
804  memcpy((char*)data() + tmp.size(), other.data(), other.size());
805 }

Referenced by add(), operator+=(), and operator<<().

+ Here is the caller graph for this function:

◆ concatenatePString() [2/2]

void PString::concatenatePString ( const std::string &  other)
protected

Concatenate a std::string into the current PString.

Parameters
other: std::string to be added

Definition at line 810 of file PString.cpp.

810  {
811  std::string tmp(*this);
812  resize(tmp.size() + other.size());
813  memcpy((char*)data(), tmp.data(), tmp.size());
814  memcpy((char*)data() + tmp.size(), other.data(), other.size());
815 }

◆ copyPString() [1/2]

void PString::copyPString ( const PString other)
protected

Copy function of PString.

Parameters
other: class to copy

Definition at line 784 of file PString.cpp.

784  {
785  resize(other.size());
786  memcpy((char*)data(), other.data(), other.size());
787 }

Referenced by fromValue(), PPath::operator=(), operator=(), and PString().

+ Here is the caller graph for this function:

◆ copyPString() [2/2]

void PString::copyPString ( const std::string &  other)
protected

Copy function of PString.

Parameters
other: class to copy

Definition at line 792 of file PString.cpp.

792  {
793  resize(other.size());
794  memcpy((char*)data(), other.data(), other.size());
795 }

◆ count() [1/2]

size_t PString::count ( char  ch) const

Count the number of char ch in the current PString.

Parameters
ch: char to be counted
Returns
number of char ch in the current PString

Definition at line 386 of file PString.cpp.

386  {
387  const PString & str(*this);
388  size_t nbChar(0lu);
389  std::string::const_iterator it(str.begin());
390  while(it != str.end()){
391  if(*it == ch) nbChar++;
392  it++;
393  }
394  return nbChar;
395 }
Extends the std::string.
Definition: PString.h:16

Referenced by PPath::getLongestExtension().

+ Here is the caller graph for this function:

◆ count() [2/2]

size_t PString::count ( const PString patern) const

Count the number of patern in string.

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

Definition at line 401 of file PString.cpp.

401  {
402  const PString & src = *this;
403  long unsigned int sizePatern(patern.size()), sizeSrc(src.size());
404  if(sizePatern == 0lu || sizeSrc == 0lu){return 0lu;}
405  size_t nbPaternFound(0lu);
406 
407  long unsigned int beginTest(0lu), nbMatch(0lu);
408  for(long unsigned int i(0lu); i < sizeSrc; ++i){
409  if(src[i] == patern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch
410  if(nbMatch == 0lu){ //c'est le premier qu'on teste
411  beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
412  }
413  ++nbMatch; //la prochaîne fois on testera le caractère suivant
414  if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
415  ++nbPaternFound;
416  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
417  nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
418  }
419  }else{ //si le caractère i n'est pas le même caractère que nbMatch
420  if(nbMatch != 0lu){ //si on avais déjà tester des caractères avant
421  i = beginTest;
422  }
423  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
424  nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
425  }
426  }
427  return nbPaternFound;
428 }

◆ eraseChar() [1/2]

PString PString::eraseChar ( char  ch) const

Erase char ch of current string.

Parameters
ch: char to be removed
Returns
modified PString

Definition at line 556 of file PString.cpp.

556  {
557  PString buffer = "";
558  for(PString::const_iterator it = begin(); it != end(); it++){
559  if(*it != ch) buffer += *it;
560  }
561  return buffer;
562 }

Referenced by eraseChar(), and PPath::getCurrentNodeName().

+ Here is the caller graph for this function:

◆ eraseChar() [2/2]

PString PString::eraseChar ( const PString vecChar) const

Erase char ch of current string.

Parameters
vecChar: chars to be removed
Returns
modified PString

Definition at line 568 of file PString.cpp.

568  {
569  PString buffer(*this);
570  for(PString::const_iterator it = vecChar.begin(); it != vecChar.end(); it++){
571  buffer = buffer.eraseChar(*it);
572  }
573  return buffer;
574 }

References eraseChar().

+ Here is the call graph for this function:

◆ eraseFirstChar()

PString PString::eraseFirstChar ( const PString vecChar) const

Erase first char in a string.

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

Definition at line 580 of file PString.cpp.

580  {
581  PString buffer(*this);
582  bool continuer = true;
583  PString::iterator it = buffer.begin();
584  //Let's remove the first chars
585  while(it != buffer.end() && continuer){
586  if(vecChar.find(*it)){it = buffer.erase(it);}
587  else{
588  continuer = false;
589  it++;
590  }
591  }
592  return buffer;
593 }
bool find(char ch) const
Find a char in a string.
Definition: PString.cpp:434

References find().

Referenced by checkEraseFirstChars(), and eraseFirstLastChar().

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

◆ eraseFirstLastChar()

PString PString::eraseFirstLastChar ( const PString vecChar) const

Erase first and last char in a string.

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

Definition at line 623 of file PString.cpp.

623  {
624  PString buffer(eraseFirstChar(vecChar));
625  return buffer.eraseLastChar(vecChar);
626 }
PString eraseFirstChar(const PString &vecChar) const
Erase first char in a string.
Definition: PString.cpp:580

References eraseFirstChar(), and eraseLastChar().

Referenced by checkEraseFirstLastChars().

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

◆ eraseLastChar()

PString PString::eraseLastChar ( const PString vecChar) const

Erase first and last char in a string.

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

Definition at line 599 of file PString.cpp.

599  {
600  if(size() > 0lu){
601  size_t nbCharToRemove(0lu);
602  PString::const_reverse_iterator it(rbegin());
603  while(vecChar.find(*it)){
604  ++it;
605  ++nbCharToRemove;
606  }
607 
608  if(nbCharToRemove == 0lu){
609  return *this;
610  }else{
611  PString buffer(substr(0, size() - nbCharToRemove));
612  return buffer;
613  }
614  }else{
615  return *this;
616  }
617 }

References find().

Referenced by checkEraseLastChars(), and eraseFirstLastChar().

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

◆ escapeStr()

PString PString::escapeStr ( const PString strCharToEscape,
const PString escapeSeq 
) const

Escape given string with passed characters.

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

Definition at line 767 of file PString.cpp.

767  {
768  if(size() == 0lu || strCharToEscape.size() == 0lu || escapeSeq.size() == 0lu){return *this;}
769  const PString & src = *this;
770  std::string out("");
771  for(size_t i(0lu); i < src.size(); ++i){
772  char ch = src[i];
773  if(strCharToEscape.find(ch)){
774  out += escapeSeq;
775  }
776  out += ch;
777  }
778  return out;
779 }

References find().

Referenced by phoenix_listArgToString().

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

◆ find() [1/2]

bool PString::find ( char  ch) const

Find a char in a string.

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

Definition at line 434 of file PString.cpp.

434  {
435  PString::const_iterator it = begin();
436  while(it != end()){
437  if(*it == ch) return true;
438  ++it;
439  }
440  return false;
441 }

Referenced by eraseFirstChar(), eraseLastChar(), escapeStr(), find(), PPath::getExtension(), PPath::getParentDirectory(), keepChar(), replaceChar(), and split().

+ Here is the caller graph for this function:

◆ find() [2/2]

bool PString::find ( const PString listChar) const

Find multiple chars in a string.

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

Definition at line 447 of file PString.cpp.

447  {
448  if(size() == 0lu || listChar.size() == 0lu){return false;}
449  bool foundChar = false;
450  long unsigned int i(0lu), size(listChar.size());
451  while(!foundChar && i < size){
452  foundChar = find(listChar[i]);
453  ++i;
454  }
455  return foundChar;
456 }

References find().

+ Here is the call graph for this function:

◆ findPatternIndex()

size_t PString::findPatternIndex ( const PString pattern,
size_t  offset = 0lu 
) const

Get the index of the first character of the given pattern.

Parameters
pattern: pattern to be searched
offset: offset where to start searching the pattern (0 by default)
Returns
index of the first character of the pattern, or size of the PString if the pattern wasn't found

Definition at line 220 of file PString.cpp.

220  {
221  size_t sizePatern(pattern.size());
222  const PString & src = *this;
223  if(sizePatern == 0lu || src.size() < offset + sizePatern){return size();}
224 
225  size_t sizeSrc(src.size());
226  size_t beginTest(0lu), nbMatch(0lu);
227  for(size_t i(offset); i < sizeSrc; ++i){
228  if(src[i] == pattern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch
229  if(nbMatch == 0lu){ //c'est le premier qu'on teste
230  beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
231  }
232  ++nbMatch; //la prochaîne fois on testera le caractère suivant
233  if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
234  return beginTest; //on a trouver le motif pattern, donc on le remplace par le motif replaceStr
235  }
236  }else{ //si le caractère i n'est pas le même caractère que nbMatch
237  if(nbMatch != 0lu){ //si on avais déjà tester des caractères avant
238  i = beginTest; //On revient là où l'on avait fait le premier test
239  }
240  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
241  nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
242  }
243  }
244  return sizeSrc;
245 }

Referenced by getBetweenDelimiter().

+ Here is the caller graph for this function:

◆ firstToLower()

PString PString::firstToLower ( ) const

Convert first letter of the PString in lower case.

Returns
PString with first letter of the PString in lower case

Definition at line 737 of file PString.cpp.

737  {
738  if(size() == 0lu){return *this;}
739  const PString & str = *this;
740  std::string strOut(str);
741  char currentChar = strOut[0lu];
742  if(phoenix_isCharUpperCase(currentChar)){
743  strOut[0lu] = currentChar + (char)32;
744  }
745  return strOut;
746 }
bool phoenix_isCharUpperCase(char ch)
Tels if the character is upper case letter.
Definition: PString.cpp:27

References phoenix_isCharUpperCase().

+ Here is the call graph for this function:

◆ firstToUpper()

PString PString::firstToUpper ( ) const

Convert first letter of the PString in upper case.

Returns
PString with first letter of the PString in upper case

Definition at line 751 of file PString.cpp.

751  {
752  if(size() == 0lu){return *this;}
753  const PString & str = *this;
754  std::string strOut(str);
755  char currentChar = strOut[0lu];
756  if(phoenix_isCharLowerCase(currentChar)){
757  strOut[0lu] = currentChar - (char)32;
758  }
759  return strOut;
760 }
bool phoenix_isCharLowerCase(char ch)
Tels if the character is lower case letter.
Definition: PString.cpp:35

References phoenix_isCharLowerCase().

+ Here is the call graph for this function:

◆ format()

PString PString::format ( const PString arg) const

Replace first {} with arg.

Parameters
arg: PString to be replaced
Returns
modified PString

Definition at line 361 of file PString.cpp.

361  {
362  return replace("{}", arg, 1lu);
363 }
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.
Definition: PString.cpp:267

References replace().

Referenced by checkFormat().

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

◆ fromValue()

template<typename T >
PString & PString::fromValue ( const T &  other)

Convert a value to a PString.

Parameters
other: value to be converted
Returns
corresponding PString

Definition at line 36 of file PString_impl.h.

36  {
37  std::string tmpValue(valueToString(other));
38  copyPString(tmpValue);
39  return *this;
40 }
std::string valueToString(const T &val)
Convert a type into a string.

References copyPString(), and valueToString().

Referenced by checkValueToStringConvertion(), and OptionValue::setDefaultValue().

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

◆ getBetweenDelimiter()

PString PString::getBetweenDelimiter ( const PString beginPattern,
const PString endPattern 
) const

Get the PString between delimiter.

Parameters
beginPattern: pattern before the PString we want to get
endPattern: pattern after the PString we want to get
Returns
PString between beginPattern and endPattern or empty string if one of them is not found

Definition at line 252 of file PString.cpp.

252  {
253  size_t indexBeginPattern(findPatternIndex(beginPattern) + beginPattern.size());
254  size_t indexEndPattern(findPatternIndex(endPattern, indexBeginPattern));
255  if(indexBeginPattern != size() && indexEndPattern != size()){
256  return substr(indexBeginPattern, indexEndPattern - indexBeginPattern);
257  }else{
258  return "";
259  }
260 }
size_t findPatternIndex(const PString &pattern, size_t offset=0lu) const
Get the index of the first character of the given pattern.
Definition: PString.cpp:220

References findPatternIndex().

+ Here is the call graph for this function:

◆ getCommonBegining()

PString PString::getCommonBegining ( const PString other) const

Get the common begining between the current PString and other.

Parameters
other: string
Returns
common begining between the current PString and other

Definition at line 477 of file PString.cpp.

477  {
478  PString out("");
479  const PString & str1(*this);
480  PString::const_iterator it = str1.begin();
481  PString::const_iterator it2 = other.begin();
482  while(it != str1.end() && it2 != other.end()){
483  if(*it == *it2){
484  out += *it;
485  }else{
486  break;
487  }
488  it++;
489  it2++;
490  }
491  return out;
492 }

◆ initialisationPString()

void PString::initialisationPString ( )
private

Initialisation function of the class PString.

Definition at line 818 of file PString.cpp.

818  {
819 
820 }

Referenced by PString().

+ Here is the caller graph for this function:

◆ isLowerCase()

bool PString::isLowerCase ( ) const

Say if the given PString is in lowercase.

Returns
true if the PString is in lowercase, false if not

Definition at line 646 of file PString.cpp.

646  {
647  if(size() == 0lu){return false;}
648  const PString & str = *this;
649  bool isLower(true);
650  size_t i(0lu);
651  while(i < str.size() && isLower){
652  isLower = phoenix_isCharLowerCase(str[i]);
653  ++i;
654  }
655  return isLower;
656 }

References phoenix_isCharLowerCase().

+ Here is the call graph for this function:

◆ isNumber()

bool PString::isNumber ( ) const

Say if the given PString is composed of numbers.

Returns
true if the PString is composed of numbers, false if not

Definition at line 661 of file PString.cpp.

661  {
662  if(size() == 0lu){return false;}
663  const PString & str = *this;
664  bool isNumber(true);
665  size_t i(0lu);
666  while(i < str.size() && isNumber){
667  isNumber = phoenix_isCharNumber(str[i]);
668  ++i;
669  }
670  return isNumber;
671 }
bool phoenix_isCharNumber(char ch)
Tels if the character is a number or not.
Definition: PString.cpp:43
bool isNumber() const
Say if the given PString is composed of numbers.
Definition: PString.cpp:661

References phoenix_isCharNumber().

+ Here is the call graph for this function:

◆ isSameBegining()

bool PString::isSameBegining ( const PString beginStr) const

Say if the current PString has the same begining of beginStr.

Parameters
beginStr: begining string to check
Returns
true if the current PString has the same begining of beginStr, false otherhwise

Definition at line 369 of file PString.cpp.

369  {
370  const PString & src = *this;
371  if(src.size() < beginStr.size()) return false;
372  std::string::const_iterator it = src.begin();
373  std::string::const_iterator it2 = beginStr.begin();
374  while(it != src.end() && it2 != beginStr.end()){
375  if(*it != *it2){ return false;}
376  it++;
377  it2++;
378  }
379  return true;
380 }

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

+ Here is the caller graph for this function:

◆ isUpperCase()

bool PString::isUpperCase ( ) const

Say if the given PString is in uppercase.

Returns
true if the PString is in uppercase, false if not

Definition at line 631 of file PString.cpp.

631  {
632  if(size() == 0lu){return false;}
633  const PString & str = *this;
634  bool isUpper(true);
635  size_t i(0lu);
636  while(i < str.size() && isUpper){
637  isUpper = phoenix_isCharUpperCase(str[i]);
638  ++i;
639  }
640  return isUpper;
641 }

References phoenix_isCharUpperCase().

+ Here is the call graph for this function:

◆ keepChar()

PString PString::keepChar ( const PString listChar) const

Keep only the characters in the given listChar.

Parameters
listChar: list of characters to be kept
Returns
PString which contains only characters in listChar

Definition at line 462 of file PString.cpp.

462  {
463  if(listChar.size() == 0lu){return "";}
464  PString out;
465  for(PString::const_iterator it = begin(); it != end(); ++it){
466  if(listChar.find(*it)){
467  out += *it;
468  }
469  }
470  return out;
471 }

References find().

+ Here is the call graph for this function:

◆ merge()

PString & PString::merge ( const std::vector< PString > &  vecStr,
const PString separator = "" 
)

Merge a set of PString.

Parameters
vecStr: vector of PString ot be merged
separator: separator between PString
Returns
corresponding PString

Definition at line 542 of file PString.cpp.

542  {
543  PString out(""), comma("");;
544  for(std::vector<PString>::const_iterator it(vecStr.begin()); it != vecStr.end(); ++it){
545  out += comma + (*it);
546  comma = separator;
547  }
548  *this = out;
549  return *this;
550 }

◆ operator+=() [1/4]

PString & PString::operator+= ( char  ch)

Add a char to an other.

Parameters
ch: char to be added to the current one
Returns
PString

Definition at line 162 of file PString.cpp.

162  {
163  return add(ch);
164 }
PString & add(const PString &other)
Add a PString to an other.
Definition: PString.cpp:170

References add().

+ Here is the call graph for this function:

◆ operator+=() [2/4]

PString & PString::operator+= ( const PString other)

Add a PString to an other.

Parameters
other: PString to be added to the current one
Returns
PString

Definition at line 146 of file PString.cpp.

146  {
147  return add(other);
148 }

References add().

+ Here is the call graph for this function:

◆ operator+=() [3/4]

PString & PString::operator+= ( const std::string &  other)

Add a std::string to an other.

Parameters
other: std::string to be added to the current one
Returns
PString

Definition at line 154 of file PString.cpp.

154  {
155  return add(other);
156 }

References add().

+ Here is the call graph for this function:

◆ operator+=() [4/4]

template<typename T >
PString & PString::operator+= ( const T &  other)

Append type in PString.

Parameters
other: type to be appended
Returns
PString

Definition at line 67 of file PString_impl.h.

67  {
68  std::string tmp(valueToString(other));
69  concatenatePString(tmp);
70  return *this;
71 }

References concatenatePString(), and valueToString().

+ Here is the call graph for this function:

◆ operator<<()

template<typename T >
PString & PString::operator<< ( const T &  other)

Append type in PString.

Parameters
other: type to be appended
Returns
PString

Definition at line 78 of file PString_impl.h.

78  {
79  std::string tmp(valueToString(other));
80  concatenatePString(tmp);
81  return *this;
82 }

References concatenatePString(), and valueToString().

+ Here is the call graph for this function:

◆ operator=() [1/3]

PString & PString::operator= ( const PString other)

Definition of equal operator of PString.

Parameters
other: class to copy
Returns
copied class

Definition at line 128 of file PString.cpp.

128  {
129  copyPString(other);
130  return *this;
131 }

References copyPString().

+ Here is the call graph for this function:

◆ operator=() [2/3]

PString & PString::operator= ( const std::string &  other)

Definition of equal operator of PString and std::string.

Parameters
other: class to copy
Returns
copied class

Definition at line 137 of file PString.cpp.

137  {
138  copyPString(other);
139  return *this;
140 }

References copyPString().

+ Here is the call graph for this function:

◆ operator=() [3/3]

template<typename T >
PString & PString::operator= ( const T &  other)

Set type in PString.

Parameters
other: type to be set in the PString
Returns
PString

Definition at line 56 of file PString_impl.h.

56  {
57  std::string tmp(valueToString(other));
58  copyPString(tmp);
59  return *this;
60 }

References copyPString(), and valueToString().

+ Here is the call graph for this function:

◆ replace() [1/2]

PString PString::replace ( const PString pattern,
const PString replaceStr 
) const

Replace a PString into an other PString.

Parameters
pattern: pattern to be replaced
replaceStr: string to replace
Returns
modified PString

Definition at line 267 of file PString.cpp.

267  {
268  size_t sizePatern(pattern.size());
269  const PString & src = *this;
270  if(sizePatern == 0lu || src.size() == 0lu) return *this;
271  PString out(""); //on évite les petits désagréments
272  size_t sizeSrc(src.size());
273  size_t beginTest(0lu), nbMatch(0lu);
274  for(size_t i(0lu); i < sizeSrc; ++i){
275  if(src[i] == pattern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch
276  if(nbMatch == 0lu){ //c'est le premier qu'on teste
277  beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
278  }
279  ++nbMatch; //la prochaîne fois on testera le caractère suivant
280  if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
281  out += replaceStr; //on a trouver le motif pattern, donc on le remplace par le motif replaceStr
282  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
283  nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
284  }
285  }else{ //si le caractère i n'est pas le même caractère que nbMatch
286  if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant
287  out += src[i]; //on ne change rien à ce caractère
288  }else{ //si on avais déjà tester des caractères avant
289  out += src[beginTest];
290  i = beginTest;
291  }
292  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
293  nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
294  }
295  }
296  //We are potentially at the end of the source, so no more test
297  return out;
298 }

Referenced by ArgParser::ArgParser(), checkPStringReplace(), and format().

+ Here is the caller graph for this function:

◆ replace() [2/2]

PString PString::replace ( const PString pattern,
const PString replaceStr,
size_t  maxNbReplace 
) const

Replace a PString into an other PString.

Parameters
pattern: pattern to be replaced
replaceStr: string to replace
maxNbReplace: maximum number of replace to perform in the string
Returns
modified PString

Definition at line 306 of file PString.cpp.

306  {
307  size_t sizePatern(pattern.size());
308  const PString & src = *this;
309  if(sizePatern == 0lu || src.size() == 0lu || maxNbReplace == 0lu) return *this;
310  PString out(""); //on évite les petits désagréments
311  size_t sizeSrc(src.size());
312  size_t beginTest(0lu), nbMatch(0lu), nbReplace(0lu);
313  for(size_t i(0lu); i < sizeSrc; ++i){
314  if(src[i] == pattern[nbMatch] && nbReplace < maxNbReplace){ //si le caractère i est le même que le caractère nbMatch
315  if(nbMatch == 0lu){ //c'est le premier qu'on teste
316  beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
317  }
318  ++nbMatch; //la prochaîne fois on testera le caractère suivant
319  if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
320  out += replaceStr; //on a trouver le motif pattern, donc on le remplace par le motif replaceStr
321  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
322  nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
323  ++nbReplace;
324  }
325  }else{ //si le caractère i n'est pas le même caractère que nbMatch
326  if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant
327  out += src[i]; //on ne change rien à ce caractère
328  }else{ //si on avais déjà tester des caractères avant
329  out += src[beginTest];
330  i = beginTest;
331  }
332  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
333  nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
334  }
335  }
336  //We are potentially at the end of the source, so no more test
337  return out;
338 }

◆ replaceChar()

PString PString::replaceChar ( const PString vecChar,
const PString replaceStr 
) const

Replace characters in vecChar by replaceStr.

Parameters
vecChar: set of characters to be replaced
replaceStr: replacement string
Returns
modified PString

Definition at line 345 of file PString.cpp.

345  {
346  PString out;
347  for(PString::const_iterator it(begin()); it != end(); ++it){
348  if(vecChar.find(*it)){
349  out += replaceStr;
350  }else{
351  out += *it;
352  }
353  }
354  return out;
355 }

References find().

+ Here is the call graph for this function:

◆ split() [1/2]

std::vector< PString > PString::split ( char  separator) const

Cut a PString on the given separator char.

Parameters
separator: separtor char
Returns
vector of PString

Definition at line 498 of file PString.cpp.

498  {
499  std::vector<PString> vec;
500  PString buffer = "";
501  for(PString::const_iterator it = begin(); it != end(); ++it){
502  if(*it != separator){
503  buffer += *it;
504  }else{
505  vec.push_back(buffer);
506  buffer = "";
507  }
508  }
509  if(buffer != ""){vec.push_back(buffer);}
510  return vec;
511 }

Referenced by checkResultSeparator(), PPath::createDirectory(), PPath::getUnderPath(), and PPath::simplify().

+ Here is the caller graph for this function:

◆ split() [2/2]

std::vector< PString > PString::split ( const PString vecSeparator) const

Split the PString on any given characters of vecSeparator.

Parameters
vecSeparator: PString of separator characters
Returns
split PString

Definition at line 517 of file PString.cpp.

517  {
518  std::vector<PString> vec;
519  if(size() != 0lu && vecSeparator.size() != 0lu){
520  PString buffer("");
521  for(PString::const_iterator it(begin()); it != end(); ++it){
522  if(!vecSeparator.find(*it)){
523  buffer += *it;
524  }else{
525  if(buffer != ""){
526  vec.push_back(buffer);
527  buffer = "";
528  }
529  }
530  }
531  if(buffer != "") vec.push_back(buffer);
532  }
533  return vec;
534 }

References find().

+ Here is the call graph for this function:

◆ toLower()

PString PString::toLower ( ) const

Convert PString in lower case.

Returns
lower case PString

Definition at line 676 of file PString.cpp.

676  {
677  if(size() == 0lu){return *this;}
678  const PString & str = *this;
679  std::string strOut("");
680  char currentChar;
681  long unsigned int size(str.size());
682  for(long unsigned int i(0lu); i < size; ++i){
683  currentChar = str[i];
684  if(phoenix_isCharUpperCase(currentChar)){
685  strOut += currentChar + (char)32;
686  }else{
687  strOut += currentChar;
688  }
689  }
690  return strOut;
691 }

References phoenix_isCharUpperCase().

+ Here is the call graph for this function:

◆ toLowerUnderscore()

PString PString::toLowerUnderscore ( ) const

Convert std::string in lower case and space in '_'.

Returns
std::string in lower case and space in '_'

Definition at line 696 of file PString.cpp.

696  {
697  if(size() == 0lu){return *this;}
698  const PString & str = *this;
699  std::string strOut("");
700  char currentChar;
701  long unsigned int size(str.size());
702  for(long unsigned int i(0lu); i < size; ++i){
703  currentChar = str[i];
704  if(phoenix_isCharUpperCase(currentChar)){
705  strOut += currentChar + (char)32;
706  }else{
707  if(currentChar == ' '){strOut += '_';}
708  else{strOut += currentChar;}
709  }
710  }
711  return strOut;
712 }

References phoenix_isCharUpperCase().

+ Here is the call graph for this function:

◆ toString()

template<typename T >
PString PString::toString ( const T &  value)
static

Convert a value to a PString.

Parameters
value: value to be converted
Returns
corresponding PString

Definition at line 18 of file PString_impl.h.

18  {
19  return valueToString(value);
20 }

References valueToString().

Referenced by phoenix_mockMakeOutputFile(), testPString(), and testPStringConversion().

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

◆ toUpper()

PString PString::toUpper ( ) const

Convert std::string in upper case.

Returns
lower case std::string

Definition at line 717 of file PString.cpp.

717  {
718  if(size() == 0lu){return *this;}
719  const PString & str = *this;
720  std::string strOut("");
721  char currentChar;
722  long unsigned int size(str.size());
723  for(long unsigned int i(0); i < size; ++i){
724  currentChar = str[i];
725  if(phoenix_isCharLowerCase(currentChar)){
726  strOut += currentChar - (char)32;
727  }else{
728  strOut += currentChar;
729  }
730  }
731  return strOut;
732 }

References phoenix_isCharLowerCase().

+ Here is the call graph for this function:

◆ toValue() [1/2]

template<typename T >
T PString::toValue

Convert the current string into a value.

Returns
corresponding value

Definition at line 46 of file PString_impl.h.

46  {
47  T value(stringToValue<T>(*this));
48  return value;
49 }

◆ toValue() [2/2]

template<typename T >
T PString::toValue ( const PString other)
static

Convert the given string into a value.

Parameters
other: PString to be converted
Returns
corresponding value

Definition at line 27 of file PString_impl.h.

27  {
28  return stringToValue<T>(other);
29 }

Referenced by checkValueToStringConvertion().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: