52 if (path.length() == 0) {
55 while (path[path.length() - 1] ==
'/' || path[path.length() - 1] ==
'\\') {
56 path.erase(path.end() - 1);
58 if (path.length() == 0) {
67 struct _stat64 fileInfo;
73 throw ProcessError(
TLF(
"Cannot get file attributes for file '%'!", path));
75 return (fileInfo.st_mode & S_IFMT) == S_IFDIR;
84 const auto beg = path.find_last_of(
"\\/");
85 if (beg == std::string::npos) {
88 return path.substr(0, beg + 1);
95 if (removeExtension) {
96 const auto begExtension = path.find_last_of(
".");
97 if (begExtension != std::string::npos) {
98 path = path.substr(0, begExtension);
102 const auto begPath = path.find_last_of(
"\\/");
103 if (begPath != std::string::npos) {
104 path = path.substr(begPath + 1, path.size());
114 }
else if (extension.empty()) {
116 }
else if (path == extension) {
118 }
else if (path.size() < extension.size()) {
119 return path + extension;
122 std::string::const_reverse_iterator it_path = path.rbegin();
123 std::string::const_reverse_iterator it_extension = extension.rbegin();
125 while (it_extension != extension.rend()) {
127 if (*it_path != *it_extension) {
128 return path + extension;
142 return retPath + path;
148 const std::string::size_type colonPos = name.find(
":");
149 return (colonPos != std::string::npos) && (colonPos > 1 || name[0] ==
'[');
159 if (path.length() > 0 && path[0] ==
'/') {
163 if (path.length() > 0 && path[0] ==
'\\') {
166 if (path.length() > 1 && path[1] ==
':') {
169 if (path ==
"nul" || path ==
"NUL") {
178 if (filename ==
"stdout" || filename ==
"STDOUT" || filename ==
"-") {
181 if (filename ==
"stderr" || filename ==
"STDERR") {
184 if (filename ==
"nul" || filename ==
"NUL") {
197 char* answer = getcwd(buffer,
sizeof(buffer));
205std::vector<std::string>
207 std::vector<std::string> result;
209 if (d ==
".." && !result.empty() && result.back() !=
"..") {
211 }
else if ((d ==
"" && result.empty()) || (d !=
"" && d !=
".")) {
221 if (filename ==
"stdout" || filename ==
"STDOUT" || filename ==
"-") {
224 if (filename ==
"stderr" || filename ==
"STDERR") {
227 if (filename ==
"nul" || filename ==
"NUL" || filename ==
"/dev/null") {
233 std::vector<std::string> filePathSplit =
splitDirs(filename);
234 std::vector<std::string> basePathSplit =
splitDirs(basePath);
242 filePathSplit =
splitDirs(curDir +
"/" + filename);
245 basePathSplit =
splitDirs(curDir +
"/" + basePath);
247 if (filePathSplit[0] != basePathSplit[0]) {
252 while (!filePathSplit.empty() && !basePathSplit.empty() && filePathSplit[0] == basePathSplit[0]) {
253 filePathSplit.erase(filePathSplit.begin());
254 basePathSplit.erase(basePathSplit.begin());
256 for (
int i = 0; i < (int)basePathSplit.size() - 1; i++) {
257 filePathSplit.insert(filePathSplit.begin(),
"..");
265 const std::string::size_type sep_index = path.find_last_of(
"\\/");
266 if (sep_index == std::string::npos) {
267 return prefix + path;
269 return path.substr(0, sep_index + 1) + prefix + path.substr(sep_index + 1);
279 strm.write((
char*) &value,
sizeof(
int));
286 strm.write((
char*) &value,
sizeof(
double));
293 strm.write((
char*) &value,
sizeof(
char));
300 int size = (int)value.length();
301 const char* cstr = value.c_str();
303 strm.write((
char*) cstr, (std::streamsize)(
sizeof(
char)*size));
310 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 accessable 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::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