#include <dirent.h>
#include "path_completion.h"
Go to the source code of this file.
◆ completePathDir()
Complete the path directory.
- Parameters
-
pathDir | : path of the directory |
- Returns
- completed directory
Definition at line 15 of file path_completion.cpp.
16 if(pathDir ==
""){
return PString(
".");}
17 else if(pathDir[0] ==
'/'){
return pathDir;}
Path of a directory or a file.
bool isSameBegining(const PString &beginStr) const
Say if the current PString has the same begining of beginStr.
References PString::isSameBegining().
Referenced by path_completion_all().
◆ path_completion_all()
PPath path_completion_all |
( |
const PPath & |
basePath | ) |
|
Return all path/files which match the basePath.
- Parameters
-
- Returns
- all path/files which match the basePath
Definition at line 37 of file path_completion.cpp.
39 if(basePath ==
""){
return PString(
"./");}
42 PPath listMatchingPath(
"");
46 DIR * dp = opendir(completedPathDir.c_str());
47 dirent * dptr = readdir(dp);
49 PPath pathName(dptr->d_name);
50 if(pathName !=
"." && pathName !=
".."){
51 listMatchingPath += prefixPath + pathName +
PString(
"\n");
60 DIR * dp = opendir(completedPathDir.c_str());
62 dirent * dptr = readdir(dp);
64 PPath pathName(dptr->d_name);
65 if(pathName !=
"." && pathName !=
".."){
66 if(pathName.isSameBegining(startNewPath)){
67 listMatchingPath += prefixPath + pathName +
PString(
"\n");
76 return listMatchingPath;
PPath getParentDirectory() const
Get path of parent directory of current path.
bool isDirectoryExist() const
Say if the current directory path does exist.
bool isFileExist() const
Say if the current file path does exist.
PPath getFileName() const
Get the name of the file, from last char to /.
PPath prefixPathDir(const PPath &pathDir)
Complete the path directory with a prefix.
PPath completePathDir(const PPath &pathDir)
Complete the path directory.
References completePathDir(), PPath::getFileName(), PPath::getParentDirectory(), PPath::isDirectoryExist(), PPath::isFileExist(), PString::isSameBegining(), and prefixPathDir().
Referenced by OptionValue::bashCompletionValue().
◆ path_completion_dirOnly()
PPath path_completion_dirOnly |
( |
const PPath & |
basePath | ) |
|
Return all directories only which match the basePath.
- Parameters
-
- Returns
- all directories which match the basePath
Definition at line 83 of file path_completion.cpp.
84 if(basePath ==
""){
return PString(
"./");}
85 PPath listMatchingPath(
"");
87 DIR * dp = opendir(basePath.c_str());
88 dirent * dptr = readdir(dp);
90 if(dptr->d_type == DT_DIR){
91 PPath pathName(dptr->d_name);
92 if(pathName !=
"." && pathName !=
".."){
93 listMatchingPath += basePath / pathName +
PString(
"\n");
100 DIR * dp = opendir(baseDir.c_str());
102 dirent * dptr = readdir(dp);
104 if(dptr->d_type == DT_DIR){
105 PPath pathName(dptr->d_name);
106 if(pathName !=
"." && pathName !=
".."){
107 if(pathName.isSameBegining(startNewPath)){
108 listMatchingPath += baseDir / pathName +
PString(
"\n");
117 return listMatchingPath;
References PPath::getFileName(), PPath::getParentDirectory(), PPath::isDirectoryExist(), and PString::isSameBegining().
Referenced by OptionValue::bashCompletionValue().
◆ prefixPathDir()
Complete the path directory with a prefix.
- Parameters
-
pathDir | : path of the directory |
- Returns
- completed directory
Definition at line 26 of file path_completion.cpp.
27 if(pathDir ==
""){
return pathDir;}
28 else if(pathDir[pathDir.size() - 1lu] ==
'/'){
return pathDir;}
29 else if(pathDir[pathDir.size() - 1lu] !=
'/'){
return PPath(pathDir +
PString(
"/"));}
Referenced by path_completion_all().