PhoenixSlider  2.0.0
Tool to create HTML presentation automatically
PPath Class Reference

Path of a directory or a file. More...

#include <PPath.h>

+ Inheritance diagram for PPath:
+ Collaboration diagram for PPath:

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...
 
bool changeMode (mode_t __mode=S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) const
 Change the mode of a file or directory. More...
 
bool checkFileBegning (const PString &expectedBegining) const
 Check if the given file starts with the given begning. 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...
 
bool createDirectory (mode_t mode=0755) const
 Create the current directory. 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...
 
PPatheraseExtension ()
 Erase the extension of the PPath. More...
 
PPath eraseExtension () const
 Erase the extension of the PPath. 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...
 
PPatheraseLongestExtension ()
 Erase the longest extension of the PPath. More...
 
PPath eraseLongestExtension () const
 Erase the longest extension of the PPath. 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...
 
std::vector< PPathgetAllDirectoryInDir () const
 Get the list of files in a directory. More...
 
std::vector< PPathgetAllElementInDir () const
 Get the list of all elements in a directory. More...
 
std::vector< PPathgetAllFileInDir () const
 Get the list of files in a directory. 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...
 
PPath getDirectoryName () const
 Get the name of the directory, from last char to / (if the last char is not a /, otherwise it takes the chars before last /) More...
 
PString getExtension () const
 Get file extension. More...
 
time_t getFileModificationTime () const
 Get the last modification time of the given file. More...
 
PPath getFileName () const
 Get the name of the file, from last char to /. More...
 
size_t getFileSize () const
 Get the size of the current file. More...
 
PString getLongestExtension () const
 Get the longest file extension. More...
 
PPath getParentDirectory () const
 Get path of parent directory of current path. More...
 
PPath getParentDirectory (const PPath &subDirName) const
 Get the parent directory which contains subDirName. More...
 
PPath getUnderPath (const PString &pathPart) const
 Get path which is under the given pathPart ('some/dir/path' with 'dir' will return 'path') More...
 
bool isAbsolutePath () const
 Tel if a path is absolute or not. More...
 
bool isDirectoryExist () const
 Say if the current directory path does exist. More...
 
bool isExist () const
 Say if the current path does exist. More...
 
bool isFileExist () const
 Say if the current file path does exist. 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...
 
PString loadFileContent () const
 Get the file content in a PString. More...
 
PPath makeAbsolute () const
 Make an absolute path of the given path. 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...
 
PPathoperator= (const PPath &other)
 Definition of equal operator of PPath. More...
 
 PPath ()
 Default constructor of PPath. More...
 
 PPath (const PPath &other)
 Copy constructor of PPath. More...
 
 PPath (const PString &other)
 Constructor of PPath. 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...
 
bool saveFileContent (const PString &content) const
 Save a PString in a file. More...
 
PPath simplify () const
 Remove extra dots from the path. 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 ~PPath ()
 Destructor of PPath. More...
 

Static Public Member Functions

static PPath getCurrentDirectory ()
 Returns the current directory. More...
 
static PString getCurrentNodeName ()
 Get the name of the current node on which the program is running. More...
 
static PPath getHomeDir ()
 Gets the $HOME directory. More...
 
static PPath getProgramDirectory ()
 Get the program directory. More...
 
static PPath getProgramLocation ()
 Get the program location. More...
 
static PPath getProgramPrefix ()
 Get the program prefix (installation directory without /bin) More...
 
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 copyPPath (const PPath &other)
 Copy function of PPath. 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 initialisationPPath ()
 Initialisation function of the class PPath. More...
 
void initialisationPString ()
 Initialisation function of the class PString. More...
 

Friends

PPath operator/ (const PPath &other1, const PPath &other2)
 Operator / for PPath to concatenate PPath. More...
 

Detailed Description

Path of a directory or a file.

Definition at line 17 of file PPath.h.

Constructor & Destructor Documentation

◆ PPath() [1/3]

PPath::PPath ( )

Default constructor of PPath.

Definition at line 64 of file PPath.cpp.

65  :PString()
66 {
68 }
void initialisationPPath()
Initialisation function of the class PPath.
Definition: PPath.cpp:662
PString()
Default constructor of PString.
Definition: PString.cpp:70

References initialisationPPath().

Referenced by getDirectoryName(), getFileName(), and getParentDirectory().

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

◆ PPath() [2/3]

PPath::PPath ( const PString other)

Constructor of PPath.

Parameters
other: PString

Definition at line 73 of file PPath.cpp.

74  :PString(other)
75 {
77 }

References initialisationPPath().

+ Here is the call graph for this function:

◆ PPath() [3/3]

PPath::PPath ( const PPath other)

Copy constructor of PPath.

Parameters
other: class to copy

Definition at line 82 of file PPath.cpp.

83  :PString(other)
84 {
85  copyPPath(other);
86 }
void copyPPath(const PPath &other)
Copy function of PPath.
Definition: PPath.cpp:657

References copyPPath().

+ Here is the call graph for this function:

◆ ~PPath()

PPath::~PPath ( )
virtual

Destructor of PPath.

Definition at line 89 of file PPath.cpp.

89  {
90 
91 }

Member Function Documentation

◆ add() [1/4]

PString & PString::add ( char  ch)
inherited

Add a char to an other.

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

Definition at line 172 of file PString.cpp.

172  {
173  std::string str;
174  str+= ch;
175  concatenatePString(str);
176  return *this;
177 }
void concatenatePString(const PString &other)
Concatenate a PString into the current PString.
Definition: PString.cpp:784

References PString::concatenatePString().

+ Here is the call graph for this function:

◆ add() [2/4]

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

Add a char pointer to an other.

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

Definition at line 183 of file PString.cpp.

183  {
185  return *this;
186 }
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 PString::concatenatePString(), and phoenix_charToString().

+ Here is the call graph for this function:

◆ add() [3/4]

PString & PString::add ( const PString other)
inherited

Add a PString to an other.

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

Definition at line 154 of file PString.cpp.

154  {
155  concatenatePString(other);
156  return *this;
157 }

References PString::concatenatePString().

Referenced by makeAbsolute(), and PString::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)
inherited

Add a std::string to an other.

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

Definition at line 163 of file PString.cpp.

163  {
164  concatenatePString(other);
165  return *this;
166 }

References PString::concatenatePString().

+ Here is the call graph for this function:

◆ changeMode()

bool PPath::changeMode ( mode_t  __mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) const

Change the mode of a file or directory.

Parameters
__mode: mode to be applied to the given file (Default value makes files executable S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
Returns
true on success, false otherwise

Definition at line 526 of file PPath.cpp.

526  {
527  return chmod(c_str(), __mode) >= 0;
528 }

◆ checkFileBegning()

bool PPath::checkFileBegning ( const PString expectedBegining) const

Check if the given file starts with the given begning.

Parameters
expectedBegining: expected begening of the file
Returns
true if the file starts with the expected begning, false otherwise

Definition at line 421 of file PPath.cpp.

421  {
422  if(size() == 0lu){return false;}
423  FILE* fp = fopen(c_str(), "r");
424  if(fp == NULL || expectedBegining.size() == 0lu){return false;}
425  int val(0);
426  size_t i(0lu);
427  bool isMatch(true);
428  while(isMatch && !feof(fp) && i < expectedBegining.size()){
429  val = fgetc(fp);
430  isMatch = (char)val == expectedBegining[i];
431  ++i;
432  }
433  fclose(fp);
434  return isMatch;
435 }

◆ concatenatePString() [1/2]

void PString::concatenatePString ( const PString other)
protectedinherited

Concatenate a PString into the current PString.

Parameters
other: PString to be added

Definition at line 784 of file PString.cpp.

784  {
785  std::string tmp(*this);
786  resize(tmp.size() + other.size());
787  memcpy((char*)data(), tmp.data(), tmp.size());
788  memcpy((char*)data() + tmp.size(), other.data(), other.size());
789 }

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

+ Here is the caller graph for this function:

◆ concatenatePString() [2/2]

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

Concatenate a std::string into the current PString.

Parameters
other: std::string to be added

Definition at line 794 of file PString.cpp.

794  {
795  std::string tmp(*this);
796  resize(tmp.size() + other.size());
797  memcpy((char*)data(), tmp.data(), tmp.size());
798  memcpy((char*)data() + tmp.size(), other.data(), other.size());
799 }

◆ copyPPath()

void PPath::copyPPath ( const PPath other)
protected

Copy function of PPath.

Parameters
other: class to copy

Definition at line 657 of file PPath.cpp.

657  {
658 
659 }

Referenced by operator=(), and PPath().

+ Here is the caller graph for this function:

◆ copyPString() [1/2]

void PString::copyPString ( const PString other)
protectedinherited

Copy function of PString.

Parameters
other: class to copy

Definition at line 768 of file PString.cpp.

768  {
769  resize(other.size());
770  memcpy((char*)data(), other.data(), other.size());
771 }

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

+ Here is the caller graph for this function:

◆ copyPString() [2/2]

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

Copy function of PString.

Parameters
other: class to copy

Definition at line 776 of file PString.cpp.

776  {
777  resize(other.size());
778  memcpy((char*)data(), other.data(), other.size());
779 }

◆ count() [1/2]

size_t PString::count ( char  ch) const
inherited

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 370 of file PString.cpp.

370  {
371  const PString & str(*this);
372  size_t nbChar(0lu);
373  std::string::const_iterator it(str.begin());
374  while(it != str.end()){
375  if(*it == ch) nbChar++;
376  it++;
377  }
378  return nbChar;
379 }
Extends the std::string.
Definition: PString.h:16

Referenced by getLongestExtension().

+ Here is the caller graph for this function:

◆ count() [2/2]

size_t PString::count ( const PString patern) const
inherited

Count the number of patern in string.

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

Definition at line 385 of file PString.cpp.

385  {
386  const PString & src = *this;
387  long unsigned int sizePatern(patern.size()), sizeSrc(src.size());
388  if(sizePatern == 0lu || sizeSrc == 0lu){return 0lu;}
389  size_t nbPaternFound(0lu);
390 
391  long unsigned int beginTest(0lu), nbMatch(0lu);
392  for(long unsigned int i(0lu); i < sizeSrc; ++i){
393  if(src[i] == patern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch
394  if(nbMatch == 0lu){ //c'est le premier qu'on teste
395  beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
396  }
397  ++nbMatch; //la prochaîne fois on testera le caractère suivant
398  if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
399  ++nbPaternFound;
400  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
401  nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
402  }
403  }else{ //si le caractère i n'est pas le même caractère que nbMatch
404  if(nbMatch != 0lu){ //si on avais déjà tester des caractères avant
405  i = beginTest;
406  }
407  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
408  nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
409  }
410  }
411  return nbPaternFound;
412 }

◆ createDirectory()

bool PPath::createDirectory ( mode_t  mode = 0755) const

Create the current directory.

Parameters
mode: access mode of the created directory
Returns
true on success, false otherwise

Definition at line 331 of file PPath.cpp.

331  {
332  if(size() == 0lu){return false;}
333  else if(isDirectoryExist()){return true;}
334 
335  std::vector<PString> listDir(split('/'));
336  PPath tmpDirName;
337  bool isNotFirst(false);
338  for(std::vector<PString>::iterator it(listDir.begin()); it != listDir.end(); ++it){
339  if(isNotFirst){
340  tmpDirName += "/";
341  }
342  tmpDirName += *it;
343  if(tmpDirName != ""){
344  if(!tmpDirName.isDirectoryExist()){
345  if(mkdir(tmpDirName.c_str(), mode) != 0){
346  return false;
347  }
348  }
349  }
350  isNotFirst = true;
351  }
352  return true;
353 // return mkdir(c_str(), 0755) == 0;
354 }
Path of a directory or a file.
Definition: PPath.h:17
bool isDirectoryExist() const
Say if the current directory path does exist.
Definition: PPath.cpp:151
std::vector< PString > split(char separator) const
Cut a PString on the given separator char.
Definition: PString.cpp:482

References isDirectoryExist(), and PString::split().

+ Here is the call graph for this function:

◆ eraseChar() [1/2]

PString PString::eraseChar ( char  ch) const
inherited

Erase char ch of current string.

Parameters
ch: char to be removed
Returns
modified PString

Definition at line 540 of file PString.cpp.

540  {
541  PString buffer = "";
542  for(PString::const_iterator it = begin(); it != end(); it++){
543  if(*it != ch) buffer += *it;
544  }
545  return buffer;
546 }

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

+ Here is the caller graph for this function:

◆ eraseChar() [2/2]

PString PString::eraseChar ( const PString vecChar) const
inherited

Erase char ch of current string.

Parameters
vecChar: chars to be removed
Returns
modified PString

Definition at line 552 of file PString.cpp.

552  {
553  PString buffer(*this);
554  for(PString::const_iterator it = vecChar.begin(); it != vecChar.end(); it++){
555  buffer = buffer.eraseChar(*it);
556  }
557  return buffer;
558 }

References PString::eraseChar().

+ Here is the call graph for this function:

◆ eraseExtension() [1/2]

PPath & PPath::eraseExtension ( )

Erase the extension of the PPath.

Returns
PPath without extension

Definition at line 292 of file PPath.cpp.

292  {
293  if(size() <= 1lu){return *this;}
294  PString extension(getExtension());
295  if(extension.size() == 0lu){return *this;}
296  resize(size() - extension.size() - 1lu);
297  return *this;
298 }
PString getExtension() const
Get file extension.
Definition: PPath.cpp:252

References getExtension().

Referenced by eraseExtension(), PLog::resize(), and slider_saveHtmlSlideMp4().

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

◆ eraseExtension() [2/2]

PPath PPath::eraseExtension ( ) const

Erase the extension of the PPath.

Returns
PPath without extension

Definition at line 314 of file PPath.cpp.

314  {
315  PPath out(*this);
316  return out.eraseExtension();
317 }

References eraseExtension().

+ Here is the call graph for this function:

◆ eraseFirstChar()

PString PString::eraseFirstChar ( const PString vecChar) const
inherited

Erase first char in a string.

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

Definition at line 564 of file PString.cpp.

564  {
565  PString buffer(*this);
566  bool continuer = true;
567  PString::iterator it = buffer.begin();
568  //Let's remove the first chars
569  while(it != buffer.end() && continuer){
570  if(vecChar.find(*it)){it = buffer.erase(it);}
571  else{
572  continuer = false;
573  it++;
574  }
575  }
576  return buffer;
577 }
bool find(char ch) const
Find a char in a string.
Definition: PString.cpp:418

References PString::find().

Referenced by checkEraseFirstChars(), and PString::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
inherited

Erase first and last char in a string.

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

Definition at line 607 of file PString.cpp.

607  {
608  PString buffer(eraseFirstChar(vecChar));
609  return buffer.eraseLastChar(vecChar);
610 }
PString eraseFirstChar(const PString &vecChar) const
Erase first char in a string.
Definition: PString.cpp:564

References PString::eraseFirstChar(), and PString::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
inherited

Erase first and last char in a string.

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

Definition at line 583 of file PString.cpp.

583  {
584  if(size() > 0lu){
585  size_t nbCharToRemove(0lu);
586  PString::const_reverse_iterator it(rbegin());
587  while(vecChar.find(*it)){
588  ++it;
589  ++nbCharToRemove;
590  }
591 
592  if(nbCharToRemove == 0lu){
593  return *this;
594  }else{
595  PString buffer(substr(0, size() - nbCharToRemove));
596  return buffer;
597  }
598  }else{
599  return *this;
600  }
601 }

References PString::find().

Referenced by checkEraseLastChars(), and PString::eraseFirstLastChar().

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

◆ eraseLongestExtension() [1/2]

PPath & PPath::eraseLongestExtension ( )

Erase the longest extension of the PPath.

Returns
PPath without longest extension

Definition at line 303 of file PPath.cpp.

303  {
304  if(size() <= 1lu){return *this;}
305  PString extension(getLongestExtension());
306  if(extension.size() == 0lu){return *this;}
307  resize(size() - extension.size() - 1lu);
308  return *this;
309 }
PString getLongestExtension() const
Get the longest file extension.
Definition: PPath.cpp:268

References getLongestExtension().

Referenced by eraseLongestExtension().

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

◆ eraseLongestExtension() [2/2]

PPath PPath::eraseLongestExtension ( ) const

Erase the longest extension of the PPath.

Returns
PPath without longest extension

Definition at line 322 of file PPath.cpp.

322  {
323  PPath out(*this);
324  return out.eraseLongestExtension();
325 }

References eraseLongestExtension().

+ Here is the call graph for this function:

◆ escapeStr()

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

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 751 of file PString.cpp.

751  {
752  if(size() == 0lu || strCharToEscape.size() == 0lu || escapeSeq.size() == 0lu){return *this;}
753  const PString & src = *this;
754  std::string out("");
755  for(size_t i(0lu); i < src.size(); ++i){
756  char ch = src[i];
757  if(strCharToEscape.find(ch)){
758  out += escapeSeq;
759  }
760  out += ch;
761  }
762  return out;
763 }

References PString::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
inherited

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 418 of file PString.cpp.

418  {
419  PString::const_iterator it = begin();
420  while(it != end()){
421  if(*it == ch) return true;
422  ++it;
423  }
424  return false;
425 }

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

+ Here is the caller graph for this function:

◆ find() [2/2]

bool PString::find ( const PString listChar) const
inherited

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 431 of file PString.cpp.

431  {
432  if(size() == 0lu || listChar.size() == 0lu){return false;}
433  bool foundChar = false;
434  long unsigned int i(0lu), size(listChar.size());
435  while(!foundChar && i < size){
436  foundChar = find(listChar[i]);
437  ++i;
438  }
439  return foundChar;
440 }

References PString::find().

+ Here is the call graph for this function:

◆ findPatternIndex()

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

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 204 of file PString.cpp.

204  {
205  size_t sizePatern(pattern.size());
206  const PString & src = *this;
207  if(sizePatern == 0lu || src.size() < offset + sizePatern){return size();}
208 
209  size_t sizeSrc(src.size());
210  size_t beginTest(0lu), nbMatch(0lu);
211  for(size_t i(offset); i < sizeSrc; ++i){
212  if(src[i] == pattern[nbMatch]){ //si le caractère i est le même que le caractère nbMatch
213  if(nbMatch == 0lu){ //c'est le premier qu'on teste
214  beginTest = i; //il faut donc se rappeler où on a commencer à faire le teste
215  }
216  ++nbMatch; //la prochaîne fois on testera le caractère suivant
217  if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
218  return beginTest; //on a trouver le motif pattern, donc on le remplace par le motif replaceStr
219  }
220  }else{ //si le caractère i n'est pas le même caractère que nbMatch
221  if(nbMatch != 0lu){ //si on avais déjà tester des caractères avant
222  i = beginTest; //On revient là où l'on avait fait le premier test
223  }
224  beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
225  nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
226  }
227  }
228  return sizeSrc;
229 }

Referenced by PString::getBetweenDelimiter().

+ Here is the caller graph for this function:

◆ firstToLower()

PString PString::firstToLower ( ) const
inherited

Convert first letter of the PString in lower case.

Returns
PString with first letter of the PString in lower case

Definition at line 721 of file PString.cpp.

721  {
722  if(size() == 0lu){return *this;}
723  const PString & str = *this;
724  std::string strOut(str);
725  char currentChar = strOut[0lu];
726  if(phoenix_isCharUpperCase(currentChar)){
727  strOut[0lu] = currentChar + (char)32;
728  }
729  return strOut;
730 }
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
inherited

Convert first letter of the PString in upper case.

Returns
PString with first letter of the PString in upper case

Definition at line 735 of file PString.cpp.

735  {
736  if(size() == 0lu){return *this;}
737  const PString & str = *this;
738  std::string strOut(str);
739  char currentChar = strOut[0lu];
740  if(phoenix_isCharLowerCase(currentChar)){
741  strOut[0lu] = currentChar - (char)32;
742  }
743  return strOut;
744 }
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
inherited

Replace first {} with arg.

Parameters
arg: PString to be replaced
Returns
modified PString

Definition at line 345 of file PString.cpp.

345  {
346  return replace("{}", arg, 1lu);
347 }
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.
Definition: PString.cpp:251

References PString::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)
inherited

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 }
void copyPString(const PString &other)
Copy function of PString.
Definition: PString.cpp:768
std::string valueToString(const T &val)
Convert a type into a string.

References PString::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:

◆ getAllDirectoryInDir()

std::vector< PPath > PPath::getAllDirectoryInDir ( ) const

Get the list of files in a directory.

Returns
list of files in the current directory

Definition at line 479 of file PPath.cpp.

479  {
480  std::vector<PPath> listFile;
481  // Open the current directory
482  DIR * dp = opendir(c_str());
483  if(NULL == dp){
484  return listFile;
485  }
486  dirent * dptr = readdir(dp);
487  while(NULL != dptr){
488  if(dptr->d_type == DT_DIR){
489  PPath dirName(dptr->d_name);
490  if(dirName != ".." && dirName != "."){
491  listFile.push_back(dirName);
492  }
493  }
494  dptr = readdir(dp);
495  }
496  closedir(dp);
497  return listFile;
498 }

Referenced by testPPathListAllFileInDir().

+ Here is the caller graph for this function:

◆ getAllElementInDir()

std::vector< PPath > PPath::getAllElementInDir ( ) const

Get the list of all elements in a directory.

Returns
list of files in the current directory

Definition at line 503 of file PPath.cpp.

503  {
504  std::vector<PPath> listFile;
505  // Open the current directory
506  DIR * dp = opendir(c_str());
507  if(NULL == dp){
508  return listFile;
509  }
510  dirent * dptr = readdir(dp);
511  while(NULL != dptr){
512  PPath fileName(dptr->d_name);
513  if(fileName != ".." && fileName != "."){
514  listFile.push_back(fileName);
515  }
516  dptr = readdir(dp);
517  }
518  closedir(dp);
519  return listFile;
520 }

Referenced by testPPathListAllFileInDir().

+ Here is the caller graph for this function:

◆ getAllFileInDir()

std::vector< PPath > PPath::getAllFileInDir ( ) const

Get the list of files in a directory.

Returns
list of files in the current directory

Definition at line 457 of file PPath.cpp.

457  {
458  std::vector<PPath> listFile;
459  // Open the current directory
460  DIR * dp = opendir(c_str());
461  if(NULL == dp){
462  return listFile;
463  }
464  dirent * dptr = readdir(dp);
465  while(NULL != dptr){
466  if(dptr->d_type == DT_REG){
467  PPath fileName(dptr->d_name);
468  listFile.push_back(fileName);
469  }
470  dptr = readdir(dp);
471  }
472  closedir(dp);
473  return listFile;
474 }

Referenced by testPPathListAllFileInDir().

+ Here is the caller graph for this function:

◆ getBetweenDelimiter()

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

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 236 of file PString.cpp.

236  {
237  size_t indexBeginPattern(findPatternIndex(beginPattern) + beginPattern.size());
238  size_t indexEndPattern(findPatternIndex(endPattern, indexBeginPattern));
239  if(indexBeginPattern != size() && indexEndPattern != size()){
240  return substr(indexBeginPattern, indexEndPattern - indexBeginPattern);
241  }else{
242  return "";
243  }
244 }
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:204

References PString::findPatternIndex().

+ Here is the call graph for this function:

◆ getCommonBegining()

PString PString::getCommonBegining ( const PString other) const
inherited

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 461 of file PString.cpp.

461  {
462  PString out("");
463  const PString & str1(*this);
464  PString::const_iterator it = str1.begin();
465  PString::const_iterator it2 = other.begin();
466  while(it != str1.end() && it2 != other.end()){
467  if(*it == *it2){
468  out += *it;
469  }else{
470  break;
471  }
472  it++;
473  it2++;
474  }
475  return out;
476 }

◆ getCurrentDirectory()

PPath PPath::getCurrentDirectory ( )
static

Returns the current directory.

Returns
current directory

Definition at line 636 of file PPath.cpp.

636  {
637 #ifndef __APPLE__
638  char* ptr = get_current_dir_name();
639  PString str(phoenix_charToString(ptr));
640  free(ptr);
641  return str;
642 #else
643  return phoenix_getenv("PWD");
644 #endif
645 }
PString phoenix_getenv(const PString &varName)
Get the value of the given environment variable.
Definition: phoenix_env.cpp:15

References phoenix_charToString(), and phoenix_getenv().

Referenced by makeAbsolute(), and testPPathGetProgram().

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

◆ getCurrentNodeName()

PString PPath::getCurrentNodeName ( )
static

Get the name of the current node on which the program is running.

Returns
name of the current node on which the program is running

Definition at line 650 of file PPath.cpp.

650  {
651  return phoenix_popen("uname -n").eraseChar(" \n\t");
652 }
PString eraseChar(char ch) const
Erase char ch of current string.
Definition: PString.cpp:540
PString phoenix_popen(const PString &command)
Execute the given command and returns the output of this command.

References PString::eraseChar(), and phoenix_popen().

Referenced by testPPathGetProgram().

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

◆ getDirectoryName()

PPath PPath::getDirectoryName ( ) const

Get the name of the directory, from last char to / (if the last char is not a /, otherwise it takes the chars before last /)

Returns
name of the corresponding directory

Definition at line 186 of file PPath.cpp.

186  {
187  std::string buffer("");
188  std::string::const_reverse_iterator rit = rbegin();
189  while(rit != rend()){
190  if(*rit == '/'){
191  if(buffer != ""){
192  break;
193  }else{
194  rit++;
195  continue;
196  }
197  }
198  buffer = *rit + buffer;
199  rit++;
200  }
201  return PPath(buffer);
202 }
PPath()
Default constructor of PPath.
Definition: PPath.cpp:64

References PPath().

+ Here is the call graph for this function:

◆ getExtension()

PString PPath::getExtension ( ) const

Get file extension.

Returns
file extension

Definition at line 252 of file PPath.cpp.

252  {
253  if(!find('.')) return "";
254  std::string extension("");
255  bool run(true);
256  std::string::const_reverse_iterator rit(rbegin());
257  while(run && rit != rend()){
258  if(*rit == '.' || *rit == '/') run = false;
259  else extension = *rit + extension;
260  rit++;
261  }
262  return PString(extension);
263 }

References PString::find(), and PString::PString().

Referenced by eraseExtension(), PLog::resize(), and slider_saveHtmlSlide().

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

◆ getFileModificationTime()

time_t PPath::getFileModificationTime ( ) const

Get the last modification time of the given file.

Parameters
fileName: name of the file we want the last modification time
Returns
last modification time of the given file

Definition at line 441 of file PPath.cpp.

441  {
442  struct stat attr;
443  if(stat(c_str(), &attr) == 0){
444 #ifdef __APPLE__
445  return attr.st_mtimespec.tv_sec;
446 #else
447  return attr.st_mtim.tv_sec;
448 #endif
449  }else{
450  return -1l;
451  }
452 }

◆ getFileName()

PPath PPath::getFileName ( ) const

Get the name of the file, from last char to /.

Returns
name of the corresponding file

Definition at line 172 of file PPath.cpp.

172  {
173  std::string buffer("");
174  std::string::const_reverse_iterator rit = rbegin();
175  while(rit != rend()){
176  if(*rit == '/') break;
177  buffer = *rit + buffer;
178  rit++;
179  }
180  return PPath(buffer);
181 }

References PPath().

Referenced by path_completion_all(), and path_completion_dirOnly().

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

◆ getFileSize()

size_t PPath::getFileSize ( ) const

Get the size of the current file.

Returns
size of the current file in bytes

Definition at line 407 of file PPath.cpp.

407  {
408  FILE* fs = fopen(c_str(), "r");
409  if(fs == NULL){return 0lu;}
410  fseek(fs, 0, SEEK_END);
411  size_t fileSize(ftell(fs));
412  fseek(fs, 0, SEEK_SET);
413  fclose(fs);
414  return fileSize;
415 }

◆ getHomeDir()

PPath PPath::getHomeDir ( )
static

Gets the $HOME directory.

Returns
$HOME directory

Definition at line 629 of file PPath.cpp.

629  {
630  return phoenix_getenv("HOME");
631 }

References phoenix_getenv().

Referenced by testPPathGetProgram().

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

◆ getLongestExtension()

PString PPath::getLongestExtension ( ) const

Get the longest file extension.

Returns
longest file extension

Definition at line 268 of file PPath.cpp.

268  {
269  size_t nbPoint(count('.'));
270  if(nbPoint == 0lu) return "";
271  PString extension(""), tmpExtension(""), middleDot("");
272  bool run(true);
273  PString::const_reverse_iterator rit(rbegin());
274  while(run && rit != rend()){
275  if(*rit == '/'){run = false;}
276  else if(*rit == '.'){
277  extension = tmpExtension + middleDot + extension;
278  tmpExtension = "";
279  middleDot = ".";
280  }else{
281  tmpExtension = *rit + tmpExtension;
282  }
283 
284  rit++;
285  }
286  return extension;
287 }
size_t count(char ch) const
Count the number of char ch in the current PString.
Definition: PString.cpp:370

References PString::count().

Referenced by eraseLongestExtension().

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

◆ getParentDirectory() [1/2]

PPath PPath::getParentDirectory ( ) const

Get path of parent directory of current path.

Returns
parent directory of current path

Definition at line 207 of file PPath.cpp.

207  {
208  if(size() == 0lu){return PString("");}
209  std::string buffer("");
210  bool find(false), isLastSlash(back() == '/');
211  std::string::const_reverse_iterator rit = rbegin();
212  while(rit != rend()){
213  if(find){
214  buffer = *rit + buffer;
215  }else{
216  find = (*rit == '/' && !isLastSlash);
217  isLastSlash = *rit == '/';
218  }
219  rit++;
220  }
221  return PPath(buffer);
222 }

References PString::find(), PPath(), and PString::PString().

Referenced by getParentDirectory(), getProgramDirectory(), getProgramPrefix(), path_completion_all(), and path_completion_dirOnly().

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

◆ getParentDirectory() [2/2]

PPath PPath::getParentDirectory ( const PPath subDirName) const

Get the parent directory which contains subDirName.

Parameters
subDirName: name of the searched sub-directory
Returns
corresponding PPath (or empty if subDirName was not found)

Definition at line 228 of file PPath.cpp.

228  {
229  if(size() == 0lu || !isDirectoryExist()){return *this;}
230  PPath curDir(*this);
231  std::string tmp(curDir / subDirName);
232  DIR * dp = opendir(tmp.c_str());
233  while(NULL == dp && curDir.size() > 1lu){
234  curDir = curDir.getParentDirectory();
235  tmp = curDir / subDirName;
236  dp = opendir(tmp.c_str());
237  }
238  return curDir;
239 
240 
241 // PPath curDir(*this);
242 // PPath tmpDir(curDir / subDirName);
243 // while(!curDir.isDirectoryExist() && curDir.size() > subDirName.size()){
244 // curDir = curDir.getParentDirectory() / subDirName;
245 // }
246 // return curDir;
247 }

References getParentDirectory(), and isDirectoryExist().

+ Here is the call graph for this function:

◆ getProgramDirectory()

PPath PPath::getProgramDirectory ( )
static

Get the program directory.

Returns
directory of the program

Definition at line 606 of file PPath.cpp.

606  {
607  PPath progLoc(getProgramLocation());
608  if(progLoc != ""){
609  return progLoc.getParentDirectory();
610  }else{
611 #ifdef CMAKE_INSTALL_PREFIX
612  return PString(CMAKE_INSTALL_PREFIX "/bin/");
613 #else
614  return PString("/usr/bin/");
615 #endif
616  }
617 }
static PPath getProgramLocation()
Get the program location.
Definition: PPath.cpp:585

References getParentDirectory(), getProgramLocation(), and PString::PString().

Referenced by getProgramPrefix(), and testPPathGetProgram().

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

◆ getProgramLocation()

PPath PPath::getProgramLocation ( )
static

Get the program location.

Returns
location of the current program

Definition at line 585 of file PPath.cpp.

585  {
586  char buffer[4096];
587  ssize_t nbChar = readlink("/proc/self/exe", buffer, 2048);
588 // readlink("/proc/self/exe", buf, bufsize) (Linux)
589 // readlink("/proc/curproc/file", buf, bufsize) (FreeBSD)
590 // readlink("/proc/self/path/a.out", buf, bufsize) (Solaris)
591 
592  if(nbChar > 0l){
593  PString outputBuf("");
594  for(ssize_t i(0l); i < nbChar; ++i){
595  outputBuf += buffer[i];
596  }
597  return outputBuf;
598  }else{
599  return PString("");
600  }
601 }

References PString::PString().

Referenced by getProgramDirectory(), and testPPathGetProgram().

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

◆ getProgramPrefix()

PPath PPath::getProgramPrefix ( )
static

Get the program prefix (installation directory without /bin)

Returns
prefix of the program (installation directory without /bin)

Definition at line 622 of file PPath.cpp.

622  {
624 }
PPath getParentDirectory() const
Get path of parent directory of current path.
Definition: PPath.cpp:207
static PPath getProgramDirectory()
Get the program directory.
Definition: PPath.cpp:606

References getParentDirectory(), and getProgramDirectory().

Referenced by testPPathGetProgram().

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

◆ getUnderPath()

PPath PPath::getUnderPath ( const PString pathPart) const

Get path which is under the given pathPart ('some/dir/path' with 'dir' will return 'path')

Parameters
pathPart: directory in the fileName we are looking for
Returns
rest of the path under the pathPart

Definition at line 360 of file PPath.cpp.

360  {
361  if(pathPart.size() == 0lu){return *this;}
362  std::vector<PString> listDir(split('/'));
363  std::vector<PString>::iterator it(listDir.begin());
364  bool isSearch(true);
365  while(isSearch && it != listDir.end()){
366  isSearch = *it != pathPart;
367  ++it;
368  }
369  PPath out;
370  PString separator("");
371  while(it != listDir.end()){
372  out += separator + (*it);
373  separator = "/";
374  ++it;
375  }
376  return out;
377 }

References PString::split().

+ Here is the call graph for this function:

◆ initialisationPPath()

void PPath::initialisationPPath ( )
private

Initialisation function of the class PPath.

Definition at line 662 of file PPath.cpp.

662  {
663 
664 }

Referenced by PPath().

+ Here is the caller graph for this function:

◆ initialisationPString()

void PString::initialisationPString ( )
privateinherited

Initialisation function of the class PString.

Definition at line 802 of file PString.cpp.

802  {
803 
804 }

Referenced by PString::PString().

+ Here is the caller graph for this function:

◆ isAbsolutePath()

bool PPath::isAbsolutePath ( ) const

Tel if a path is absolute or not.

Parameters
path: path to be checked
Returns
true if the path is absolute, false otherwise

Definition at line 164 of file PPath.cpp.

164  {
165  if(size() == 0lu) return false;
166  return front() == '/';
167 }

Referenced by makeAbsolute().

+ Here is the caller graph for this function:

◆ isDirectoryExist()

bool PPath::isDirectoryExist ( ) const

Say if the current directory path does exist.

Returns
if the current directory path does exist

Definition at line 151 of file PPath.cpp.

151  {
152  if(size() == 0lu) return false;
153  struct stat path_stat;
154  if(stat(c_str(), &path_stat) != 0){
155  return false;
156  }
157  return S_ISDIR(path_stat.st_mode) != 0;
158 }

Referenced by createDirectory(), getParentDirectory(), path_completion_all(), and path_completion_dirOnly().

+ Here is the caller graph for this function:

◆ isExist()

bool PPath::isExist ( ) const

Say if the current path does exist.

Returns
if the current path does exist

Definition at line 131 of file PPath.cpp.

131  {
132  if(size() == 0lu) return false;
133  return access(c_str(), F_OK) != -1;
134 }

◆ isFileExist()

bool PPath::isFileExist ( ) const

Say if the current file path does exist.

Returns
if the current file path does exist

Definition at line 139 of file PPath.cpp.

139  {
140  if(size() == 0lu) return false;
141  struct stat path_stat;
142  if(stat(c_str(), &path_stat) != 0){
143  return false;
144  }
145  return S_ISREG(path_stat.st_mode) != 0;
146 }

Referenced by loadFileContent(), and path_completion_all().

+ Here is the caller graph for this function:

◆ isLowerCase()

bool PString::isLowerCase ( ) const
inherited

Say if the given PString is in lowercase.

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

Definition at line 630 of file PString.cpp.

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

References phoenix_isCharLowerCase().

+ Here is the call graph for this function:

◆ isNumber()

bool PString::isNumber ( ) const
inherited

Say if the given PString is composed of numbers.

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

Definition at line 645 of file PString.cpp.

645  {
646  if(size() == 0lu){return false;}
647  const PString & str = *this;
648  bool isNumber(true);
649  size_t i(0lu);
650  while(i < str.size() && isNumber){
651  isNumber = phoenix_isCharNumber(str[i]);
652  ++i;
653  }
654  return isNumber;
655 }
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:645

References phoenix_isCharNumber().

+ Here is the call graph for this function:

◆ isSameBegining()

bool PString::isSameBegining ( const PString beginStr) const
inherited

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 353 of file PString.cpp.

353  {
354  const PString & src = *this;
355  if(src.size() < beginStr.size()) return false;
356  std::string::const_iterator it = src.begin();
357  std::string::const_iterator it2 = beginStr.begin();
358  while(it != src.end() && it2 != beginStr.end()){
359  if(*it != *it2){ return false;}
360  it++;
361  it2++;
362  }
363  return true;
364 }

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
inherited

Say if the given PString is in uppercase.

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

Definition at line 615 of file PString.cpp.

615  {
616  if(size() == 0lu){return false;}
617  const PString & str = *this;
618  bool isUpper(true);
619  size_t i(0lu);
620  while(i < str.size() && isUpper){
621  isUpper = phoenix_isCharUpperCase(str[i]);
622  ++i;
623  }
624  return isUpper;
625 }

References phoenix_isCharUpperCase().

+ Here is the call graph for this function:

◆ keepChar()

PString PString::keepChar ( const PString listChar) const
inherited

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 446 of file PString.cpp.

446  {
447  if(listChar.size() == 0lu){return "";}
448  PString out;
449  for(PString::const_iterator it = begin(); it != end(); ++it){
450  if(listChar.find(*it)){
451  out += *it;
452  }
453  }
454  return out;
455 }

References PString::find().

+ Here is the call graph for this function:

◆ loadFileContent()

PString PPath::loadFileContent ( ) const

Get the file content in a PString.

Returns
PString content of the file

Definition at line 382 of file PPath.cpp.

382  {
383  if(!isFileExist()){return "";}
384  FILE * fp = fopen(c_str(), "r");
385  if(fp == NULL){return "";}
386  PString bufferAllFile(phoenix_getFileContent(fp));
387  fclose(fp);
388  return bufferAllFile;
389 }
PString phoenix_getFileContent(FILE *fp)
Get the content of a file.
Definition: PPath.cpp:28
bool isFileExist() const
Say if the current file path does exist.
Definition: PPath.cpp:139

References isFileExist(), and phoenix_getFileContent().

Referenced by slider_saveHtmlSlideHtml().

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

◆ makeAbsolute()

PPath PPath::makeAbsolute ( ) const

Make an absolute path of the given path.

Returns
corresponding absolute path

Definition at line 572 of file PPath.cpp.

572  {
573  if(size() == 0lu){
574  return PPath::getCurrentDirectory().add("/");
575  }else if(isAbsolutePath()){
576  return *this;
577  }else{
578  return PPath::getCurrentDirectory().add("/").add(*this);
579  }
580 }
static PPath getCurrentDirectory()
Returns the current directory.
Definition: PPath.cpp:636
bool isAbsolutePath() const
Tel if a path is absolute or not.
Definition: PPath.cpp:164
PString & add(const PString &other)
Add a PString to an other.
Definition: PString.cpp:154

References PString::add(), getCurrentDirectory(), and isAbsolutePath().

+ Here is the call graph for this function:

◆ merge()

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

Merge a set of PString.

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

Definition at line 526 of file PString.cpp.

526  {
527  PString out(""), comma("");;
528  for(std::vector<PString>::const_iterator it(vecStr.begin()); it != vecStr.end(); ++it){
529  out += comma + (*it);
530  comma = separator;
531  }
532  *this = out;
533  return *this;
534 }

◆ operator+=() [1/4]

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

Add a char to an other.

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

Definition at line 146 of file PString.cpp.

146  {
147  return add(ch);
148 }

References PString::add().

+ Here is the call graph for this function:

◆ operator+=() [2/4]

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

Add a PString to an other.

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

Definition at line 130 of file PString.cpp.

130  {
131  return add(other);
132 }

References PString::add().

+ Here is the call graph for this function:

◆ operator+=() [3/4]

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

Add a std::string to an other.

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

Definition at line 138 of file PString.cpp.

138  {
139  return add(other);
140 }

References PString::add().

+ Here is the call graph for this function:

◆ operator+=() [4/4]

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

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 PString::concatenatePString(), and valueToString().

+ Here is the call graph for this function:

◆ operator<<()

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

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 PString::concatenatePString(), and valueToString().

+ Here is the call graph for this function:

◆ operator=()

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

Definition of equal operator of PPath.

Parameters
other: class to copy
Returns
copied class

Definition at line 97 of file PPath.cpp.

97  {
98  copyPString(other);
99  copyPPath(other);
100  return *this;
101 }

References copyPPath(), and PString::copyPString().

+ Here is the call graph for this function:

◆ replace() [1/2]

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

Replace a PString into an other PString.

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

Definition at line 251 of file PString.cpp.

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

Referenced by ArgParser::ArgParser(), checkPStringReplace(), and PString::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
inherited

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 290 of file PString.cpp.

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

◆ replaceChar()

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

Replace characters in vecChar by replaceStr.

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

Definition at line 329 of file PString.cpp.

329  {
330  PString out;
331  for(PString::const_iterator it(begin()); it != end(); ++it){
332  if(vecChar.find(*it)){
333  out += replaceStr;
334  }else{
335  out += *it;
336  }
337  }
338  return out;
339 }

References PString::find().

+ Here is the call graph for this function:

◆ saveFileContent()

bool PPath::saveFileContent ( const PString content) const

Save a PString in a file.

Parameters
content: file content
Returns
true on success, false otherwise

Definition at line 395 of file PPath.cpp.

395  {
396  FILE * fp = fopen(c_str(), "w");
397  if(fp == NULL){return false;}
398  bool result(true);
399  fprintf(fp, "%s", content.c_str());
400  fclose(fp);
401  return result;
402 }

Referenced by phoenix_popen().

+ Here is the caller graph for this function:

◆ simplify()

PPath PPath::simplify ( ) const

Remove extra dots from the path.

Returns
path wthout dots

Definition at line 533 of file PPath.cpp.

533  {
534  if(size() == 0lu){return *this;}
535  if(front() == '.'){return *this;}
536  std::vector<PString> listDir(split('/'));
537  std::vector<PString>::reverse_iterator rit = listDir.rbegin();
538  while(rit != listDir.rend()){
539  if(*rit == "." || *rit == ""){
540 // rit = listDir.erase(rit); //No erase in reverse_iterator, so anoying
541  *rit = "";
542  }else if(*rit == ".."){
543 // rit = listDir.erase(rit); //No erase in reverse_iterator, so anoying
544  *rit = "";
545  ++rit;
546  if(rit != listDir.rend()){
547 // rit = listDir.erase(rit); //No erase in reverse_iterator, so anoying
548  *rit = "";
549  }
550  }
551 // else{
552 // ++rit; //No erase in reverse_iterator, so anoying
553 // }
554  ++rit;
555  }
556  PPath out;
557  PString separator("");
558  if(front() == '/'){
559  out = PString("/");
560  }
561  for(std::vector<PString>::iterator it(listDir.begin()); it != listDir.end(); ++it){
562  if(*it == ""){continue;}
563  out += separator + (*it);
564  separator = "/";
565  }
566  return out;
567 }

References PString::PString(), and PString::split().

+ Here is the call graph for this function:

◆ split() [1/2]

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

Cut a PString on the given separator char.

Parameters
separator: separtor char
Returns
vector of PString

Definition at line 482 of file PString.cpp.

482  {
483  std::vector<PString> vec;
484  PString buffer = "";
485  for(PString::const_iterator it = begin(); it != end(); ++it){
486  if(*it != separator){
487  buffer += *it;
488  }else{
489  vec.push_back(buffer);
490  buffer = "";
491  }
492  }
493  if(buffer != ""){vec.push_back(buffer);}
494  return vec;
495 }

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

+ Here is the caller graph for this function:

◆ split() [2/2]

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

Split the PString on any given characters of vecSeparator.

Parameters
vecSeparator: PString of separator characters
Returns
split PString

Definition at line 501 of file PString.cpp.

501  {
502  std::vector<PString> vec;
503  if(size() != 0lu && vecSeparator.size() != 0lu){
504  PString buffer("");
505  for(PString::const_iterator it(begin()); it != end(); ++it){
506  if(!vecSeparator.find(*it)){
507  buffer += *it;
508  }else{
509  if(buffer != ""){
510  vec.push_back(buffer);
511  buffer = "";
512  }
513  }
514  }
515  if(buffer != "") vec.push_back(buffer);
516  }
517  return vec;
518 }

References PString::find().

+ Here is the call graph for this function:

◆ toLower()

PString PString::toLower ( ) const
inherited

Convert PString in lower case.

Returns
lower case PString

Definition at line 660 of file PString.cpp.

660  {
661  if(size() == 0lu){return *this;}
662  const PString & str = *this;
663  std::string strOut("");
664  char currentChar;
665  long unsigned int size(str.size());
666  for(long unsigned int i(0lu); i < size; ++i){
667  currentChar = str[i];
668  if(phoenix_isCharUpperCase(currentChar)){
669  strOut += currentChar + (char)32;
670  }else{
671  strOut += currentChar;
672  }
673  }
674  return strOut;
675 }

References phoenix_isCharUpperCase().

+ Here is the call graph for this function:

◆ toLowerUnderscore()

PString PString::toLowerUnderscore ( ) const
inherited

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

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

Definition at line 680 of file PString.cpp.

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

References phoenix_isCharUpperCase().

+ Here is the call graph for this function:

◆ toString()

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

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 testPString(), and testPStringConversion().

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

◆ toUpper()

PString PString::toUpper ( ) const
inherited

Convert std::string in upper case.

Returns
lower case std::string

Definition at line 701 of file PString.cpp.

701  {
702  if(size() == 0lu){return *this;}
703  const PString & str = *this;
704  std::string strOut("");
705  char currentChar;
706  long unsigned int size(str.size());
707  for(long unsigned int i(0); i < size; ++i){
708  currentChar = str[i];
709  if(phoenix_isCharLowerCase(currentChar)){
710  strOut += currentChar - (char)32;
711  }else{
712  strOut += currentChar;
713  }
714  }
715  return strOut;
716 }

References phoenix_isCharLowerCase().

+ Here is the call graph for this function:

◆ toValue() [1/2]

template<typename T >
T PString::toValue
inherited

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)
staticinherited

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:

Friends And Related Function Documentation

◆ operator/

PPath operator/ ( const PPath other1,
const PPath other2 
)
friend

Operator / for PPath to concatenate PPath.

Parameters
other1: PPath
other2: PPath
Returns
other1 / other2

Definition at line 119 of file PPath.cpp.

119  {
120  PPath out(other1);
121  if(other1.size() != 0lu){
122  out += PString("/");
123  }
124  out += other2;
125  return out;
126 }

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