PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
path_completion.h File Reference
#include <string>
+ Include dependency graph for path_completion.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::string path_completion_all (const std::string &basePath)
 Return all path/files which match the basePath. More...
 
std::string path_completion_dirOnly (const std::string &basePath)
 Return all directories only which match the basePath. More...
 

Function Documentation

◆ path_completion_all()

std::string path_completion_all ( const std::string &  basePath)

Return all path/files which match the basePath.

Parameters
basePath: incomming path
Returns
all path/files which match the basePath

Definition at line 41 of file path_completion.cpp.

41  {
42 // std::cerr << "path_completion_all : basePath = '"<<basePath<<"'" << std::endl;
43  if(basePath == ""){return "./";}
44  if(isFileExist(basePath)){return "";}
45 
46  std::string listMatchingPath("");
47  if(isDirectoryExist(basePath)){
48  std::string completedPathDir(completePathDir(basePath));
49  std::string prefixPath(prefixPathDir(basePath));
50  DIR * dp = opendir(completedPathDir.c_str());
51  dirent * dptr = readdir(dp);
52  while(NULL != dptr){
53  std::string pathName(dptr->d_name);
54  if(pathName != "." && pathName != ".."){
55  listMatchingPath += prefixPath + pathName + "\n";
56  }
57  dptr = readdir(dp);
58  }
59  closedir(dp);
60  }else{
61  std::string baseDir(getDirectory(basePath)), startNewPath(getFileName(basePath));
62  std::string completedPathDir(completePathDir(baseDir));
63  std::string prefixPath(prefixPathDir(baseDir));
64  DIR * dp = opendir(completedPathDir.c_str());
65 
66  dirent * dptr = readdir(dp);
67  while(NULL != dptr){
68  std::string pathName(dptr->d_name);
69  if(pathName != "." && pathName != ".."){
70  if(isSameBegining(pathName, startNewPath)){
71  listMatchingPath += prefixPath + pathName + "\n";
72  }
73  }
74  dptr = readdir(dp);
75  }
76 
77  closedir(dp);
78  }
79 // std::cerr << "path_completion_all : listMatchingPath = '"<<listMatchingPath<<"'" << std::endl;
80  return listMatchingPath;
81 }

References completePathDir(), getDirectory(), getFileName(), isDirectoryExist(), isFileExist(), isSameBegining(), and prefixPathDir().

Referenced by OptionValue::bashCompletionValue().

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

◆ path_completion_dirOnly()

std::string path_completion_dirOnly ( const std::string &  basePath)

Return all directories only which match the basePath.

Parameters
basePath: incomming path
Returns
all directories which match the basePath

Definition at line 87 of file path_completion.cpp.

87  {
88  if(basePath == ""){return "./";}
89  std::string listMatchingPath("");
90  if(isDirectoryExist(basePath)){
91  DIR * dp = opendir(basePath.c_str());
92 
93  dirent * dptr = readdir(dp);
94  while(NULL != dptr){
95  if(dptr->d_type == DT_DIR){ //We search for directory only
96  std::string pathName(dptr->d_name);
97  if(pathName != "." && pathName != ".."){
98  listMatchingPath += basePath + "/" + pathName + "\n";
99  }
100  }
101  dptr = readdir(dp);
102  }
103  }else{
104  std::string baseDir(getDirectory(basePath)), startNewPath(getFileName(basePath));
105  DIR * dp = opendir(baseDir.c_str());
106 
107  dirent * dptr = readdir(dp);
108  while(NULL != dptr){
109  if(dptr->d_type == DT_DIR){ //We search for directory only
110  std::string pathName(dptr->d_name);
111  if(pathName != "." && pathName != ".."){
112  if(isSameBegining(pathName, startNewPath)){
113  listMatchingPath += baseDir + "/" + pathName + "\n";
114  }
115  }
116  }
117  dptr = readdir(dp);
118  }
119 
120  closedir(dp);
121  }
122  return listMatchingPath;
123 }

References getDirectory(), getFileName(), isDirectoryExist(), and isSameBegining().

Referenced by OptionValue::bashCompletionValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:
isDirectoryExist
bool isDirectoryExist(const std::string &dirName)
Says if the given direcotry exists.
Definition: string_filename.cpp:57
completePathDir
std::string completePathDir(const std::string &pathDir)
Complete the path directory.
Definition: path_completion.cpp:18
isSameBegining
bool isSameBegining(const std::string &str, const std::string &beginig)
Check if two string start the same way.
Definition: string_function.cpp:531
getFileName
std::string getFileName(const std::string &fileName)
fonction qui renvoie le nom du fichier du nom complet de fichier passé en paramètre
Definition: string_filename.cpp:231
prefixPathDir
std::string prefixPathDir(const std::string &pathDir)
Complete the path directory with a prefix.
Definition: path_completion.cpp:30
isFileExist
bool isFileExist(const std::string &fileName)
Say if a file exsits or not.
Definition: string_filename.cpp:27
getDirectory
std::string getDirectory(const std::string &fileName)
fonction qui renvoie le dossier parent du fichier
Definition: string_filename.cpp:156