std::wstring Path::to_string_generic (wchar_t separator) const { assert (isRelative || path.size () >= 1 || has_drive_letter ()); std::wostringstream strm; List::const_iterator cit = path.begin (); bool first = true; for (; cit != path.end (); cit++) { if (!first) strm << separator; strm << (*cit); first = false; } if (!isRelative && has_drive_letter ()) return std::wstring (1, drive) + L':' + separator + strm.str (); else return strm.str (); }
// common part of constructors void Path::init (const std::wstring& pathStr) { // Must not contain repeated '\\' if (pathStr.find (L"\\\\") != std::wstring::npos) throw InvalidPath (pathStr, L" found the sequence of \\"); // Can contain ':' only in the position 1 if (pathStr.find (L':', 2) != std::wstring::npos) throw InvalidPath (pathStr, L" found ':' in a path"); // Check passed path if (pathStr.length () >= 2 && pathStr[1] == L':') //FIXME check a-zA-Z drive = pathStr[0]; else drive = L'?'; isRelative = ! (pathStr.length () >= 1 && pathStr[0] == L'\\' || pathStr.length () >= 3 && has_drive_letter () && pathStr[2] == L'\\'); #ifdef MATT_PATHES // Absolute path is accepted only with a drive if (!isRelative && !has_drive_letter ()) throw InvalidPath (pathStr, L" absolute path must contain a drive letter"); #endif #if 0 if (isRelative && path.length () > MAX_PATH) throw InvalidPath (path, L" too long and relative"); // UT for dir creation MAX_PATH - 12 (8.3 is leaved for files) #endif parse_path (pathStr); assert (isRelative || path.size () >= 1 || has_drive_letter () ); }
/* TODO Should we skip? */ static int detect_prefix(SgObject path) { /* network address or so e.g. \\foo\bar */ if (dirsep_p(S(path,0)) && dirsep_p(S(path,1))) { int skipped = 2; while (dirsep_p(S(path, skipped))) { skipped++; } if ((skipped = next_dirsep(path, skipped)) < SG_STRING_SIZE(path) && skipped+1 < SG_STRING_SIZE(path) && !dirsep_p(S(path, skipped+1))) { skipped = next_dirsep(path, skipped+1); } return skipped; } if (has_drive_letter(path)) { return 2; } return 0; }
// from string to list of directories void Path::parse_path (const std::wstring& pathStr) { std::wstring::size_type from = 0; bool firstIsDrive = has_drive_letter (); while (from < pathStr.length ()) { std::wstring::size_type pos = pathStr.find_first_of (L"\\:", from); if (pos == std::wstring::npos) { path.push_back (pathStr.substr (from, pathStr.length () - from)); return; } if (from == pos) { from++; continue; } // ":\\" // FIXME check only one ':' in a path above if (pos > 0) { if (firstIsDrive) { std::wstring driveLetter = pathStr.substr (from, pos - from); assert (driveLetter.length () == 1); drive = std::tolower (driveLetter.at (0), loc); firstIsDrive = false; } else path.push_back (pathStr.substr (from, pos - from)); from = pos + 1; } } }
ShieSSHPath::ShieSSHPath (const std::wstring& _path) : Path (get_standard_form (_path)) { isRelative = !has_drive_letter (); }