53 if (path.length() == 0) {
56 while (path[path.length() - 1] ==
'/' || path[path.length() - 1] ==
'\\') {
57 path.erase(path.end() - 1);
59 if (path.length() == 0) {
68 struct _stat64 fileInfo;
74 throw ProcessError(
TLF(
"Cannot get file attributes for file '%'!", path));
76 return (fileInfo.st_mode & S_IFMT) == S_IFDIR;
85 const auto beg = path.find_last_of(
"\\/");
86 if (beg == std::string::npos) {
89 return path.substr(0, beg + 1);
96 if (removeExtension) {
97 const auto begExtension = path.find_last_of(
".");
98 if (begExtension != std::string::npos) {
99 path = path.substr(0, begExtension);
103 const auto begPath = path.find_last_of(
"\\/");
104 if (begPath != std::string::npos) {
105 path = path.substr(begPath + 1, path.size());
115 }
else if (extension.empty()) {
117 }
else if (path == extension) {
119 }
else if (path.size() < extension.size()) {
120 return path + extension;
123 std::string::const_reverse_iterator it_path = path.rbegin();
124 std::string::const_reverse_iterator it_extension = extension.rbegin();
126 while (it_extension != extension.rend()) {
128 if (*it_path != *it_extension) {
129 return path + extension;
143 return retPath + path;
149 const std::string::size_type colonPos = name.find(
":");
150 return (colonPos != std::string::npos) && (colonPos > 1 || name[0] ==
'[');
160 if (path.length() > 0 && path[0] ==
'/') {
164 if (path.length() > 0 && path[0] ==
'\\') {
167 if (path.length() > 1 && path[1] ==
':') {
170 if (path ==
"nul" || path ==
"NUL") {
179 if (filename ==
"stdout" || filename ==
"STDOUT" || filename ==
"-") {
182 if (filename ==
"stderr" || filename ==
"STDERR") {
185 if (filename ==
"nul" || filename ==
"NUL") {
198 char* answer = getcwd(buffer,
sizeof(buffer));
206std::vector<std::string>
208 std::vector<std::string> result;
210 if (d ==
".." && !result.empty() && result.back() !=
"..") {
212 }
else if ((d ==
"" && result.empty()) || (d !=
"" && d !=
".")) {
222 if (filename ==
"stdout" || filename ==
"STDOUT" || filename ==
"-") {
225 if (filename ==
"stderr" || filename ==
"STDERR") {
228 if (filename ==
"nul" || filename ==
"NUL" || filename ==
"/dev/null") {
234 std::vector<std::string> filePathSplit =
splitDirs(filename);
235 std::vector<std::string> basePathSplit =
splitDirs(basePath);
243 filePathSplit =
splitDirs(curDir +
"/" + filename);
246 basePathSplit =
splitDirs(curDir +
"/" + basePath);
248 if (filePathSplit[0] != basePathSplit[0]) {
253 while (!filePathSplit.empty() && !basePathSplit.empty() && filePathSplit[0] == basePathSplit[0]) {
254 filePathSplit.erase(filePathSplit.begin());
255 basePathSplit.erase(basePathSplit.begin());
257 for (
int i = 0; i < (int)basePathSplit.size() - 1; i++) {
258 filePathSplit.insert(filePathSplit.begin(),
"..");
266 const std::string::size_type sep_index = path.find_last_of(
"\\/");
267 if (sep_index == std::string::npos) {
268 return prefix + path;
270 return path.substr(0, sep_index + 1) + prefix + path.substr(sep_index + 1);
278 const std::string::size_type sep_index = path.find_last_of(
"\\/");
279 if (sep_index == std::string::npos) {
282 return path.substr(0, sep_index + 1) +
appendBeforeExtension(path.substr(sep_index + 1), suffix,
false);
286 for (
int i = (
int)components.size() - 1; i >= 0; i--) {
288 if (i == 0 || components[i].size() > 4) {
289 components[i] += suffix;
303 strm.write((
char*) &value,
sizeof(
int));
310 strm.write((
char*) &value,
sizeof(
double));
317 strm.write((
char*) &value,
sizeof(
char));
324 int size = (int)value.length();
325 const char* cstr = value.c_str();
327 strm.write((
char*) cstr, (std::streamsize)(
sizeof(
char)*size));
334 strm.write((
char*) &value,
sizeof(
SUMOTime));
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
static std::string fixRelative(const std::string &filename, const std::string &basePath, const bool force, std::string curDir="")
Fixes the relative path for the given filename in relation to the basePath (usually a config file).
static bool isAbsolute(const std::string &path)
Returns the information whether the given path is absolute.
static std::ostream & writeFloat(std::ostream &strm, double value)
Writes a float binary.
static std::string getConfigurationRelative(const std::string &configPath, const std::string &path)
Returns the second path as a relative path to the first file.
static std::string checkForRelativity(const std::string &filename, const std::string &basePath)
Returns the path from a configuration so that it is accessible from the current working directory.
static std::string addExtension(const std::string &path, const std::string &extension)
Add an extension to the given file path.
static std::ostream & writeString(std::ostream &strm, const std::string &value)
Writes a string binary.
static bool isReadable(std::string path)
Checks whether the given file is readable.
static std::string appendBeforeExtension(const std::string &path, const std::string &suffix, bool checkSep=true)
append the given suffix after the file name but before the extension
static std::vector< std::string > splitDirs(const std::string &filename)
Splits the given file path into directory components.
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
static std::ostream & writeTime(std::ostream &strm, SUMOTime value)
Writes a time description binary.
static std::ostream & writeInt(std::ostream &strm, int value)
Writes an integer binary.
static bool isSocket(const std::string &name)
Returns the information whether the given name represents a socket.
static std::string getFileFromPath(std::string path, const bool removeExtension)
Removes the path information from the given path.
static bool isDirectory(std::string path)
Checks whether the given file is a directory.
static std::string getCurrentDir()
Get the current working directory.
static std::ostream & writeByte(std::ostream &strm, unsigned char value)
Writes a byte binary.
static std::string prependToLastPathComponent(const std::string &prefix, const std::string &path)
prepend the given prefix to the last path component of the given file path
std::vector< std::string > getVector()
return vector of strings
static std::string transcodeToLocal(const std::string &utf8String)
convert a string from UTF-8 to the local codepage