plString cdUp(plString path) { // Check for root paths, we can't go up from there! #ifdef WIN32 if (path.mid(1) == ":\\") return path; #else if (path == "/") return path; #endif // Not very robust, but it works for one level of parent scanning if (path.empty()) return ".." PATHSEPSTR; // Strip the ending slash, if necessary, and then go up one dir if (path[path.len()-1] == PATHSEP) path = path.left(path.len() - 1); plString up = path.beforeLast(PATHSEP); if (path[0] == PATHSEP) { // Absolute path specified -- make sure we keep it that way return up + PATHSEP; } else { // Relative path specified return up.empty() ? "" : up + PATHSEP; } }
plString FixSlashes(const plString& src) { if (src.empty()) return plString(); char* pbuf = strdup(src); for (char* pc = pbuf; *pc != 0; pc++) { if (*pc == '/' || *pc == '\\') *pc = PATHSEP; } plString dest(pbuf); free(pbuf); return dest; }