Added optional `path_separator` parameter to `Path` constructor. This defaults to `os::PATH_SEPARATOR` and so by default retains the previous behavior. However, now `Path` can be arbitrarily used with, e.g., URLs on Windows by providing `/` as the separator.
Review: https://reviews.apache.org/r/67951/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/de4917a3 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/de4917a3 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/de4917a3 Branch: refs/heads/master Commit: de4917a3c38c347a4fb85dc14a9fbf378ebd47ac Parents: 0519403 Author: Andrew Schwartzmeyer <and...@schwartzmeyer.com> Authored: Tue Jul 17 15:00:46 2018 -0700 Committer: Andrew Schwartzmeyer <and...@schwartzmeyer.com> Committed: Tue Jul 24 10:58:52 2018 -0700 ---------------------------------------------------------------------- 3rdparty/stout/include/stout/path.hpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/de4917a3/3rdparty/stout/include/stout/path.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/path.hpp b/3rdparty/stout/include/stout/path.hpp index 27438d3..ef5a2f3 100644 --- a/3rdparty/stout/include/stout/path.hpp +++ b/3rdparty/stout/include/stout/path.hpp @@ -145,10 +145,13 @@ inline bool absolute(const std::string& path) class Path { public: - Path() : value() {} + Path() : value(), separator(os::PATH_SEPARATOR) {} - explicit Path(const std::string& path) - : value(strings::remove(path, "file://", strings::PREFIX)) {} + explicit Path( + const std::string& path, const char path_separator = os::PATH_SEPARATOR) + : value(strings::remove(path, "file://", strings::PREFIX)), + separator(path_separator) + {} // TODO(cmaloney): Add more useful operations such as 'directoryname()', // 'filename()', etc. @@ -185,18 +188,18 @@ public: size_t end = value.size() - 1; // Remove trailing slashes. - if (value[end] == os::PATH_SEPARATOR) { - end = value.find_last_not_of(os::PATH_SEPARATOR, end); + if (value[end] == separator) { + end = value.find_last_not_of(separator, end); // Paths containing only slashes result into "/". if (end == std::string::npos) { - return stringify(os::PATH_SEPARATOR); + return stringify(separator); } } // 'start' should point towards the character after the last slash // that is non trailing. - size_t start = value.find_last_of(os::PATH_SEPARATOR, end); + size_t start = value.find_last_of(separator, end); if (start == std::string::npos) { start = 0; @@ -244,12 +247,12 @@ public: size_t end = value.size() - 1; // Remove trailing slashes. - if (value[end] == os::PATH_SEPARATOR) { - end = value.find_last_not_of(os::PATH_SEPARATOR, end); + if (value[end] == separator) { + end = value.find_last_not_of(separator, end); } // Remove anything trailing the last slash. - end = value.find_last_of(os::PATH_SEPARATOR, end); + end = value.find_last_of(separator, end); // Paths containing no slashes result in ".". if (end == std::string::npos) { @@ -258,16 +261,16 @@ public: // Paths containing only slashes result in "/". if (end == 0) { - return stringify(os::PATH_SEPARATOR); + return stringify(separator); } // 'end' should point towards the last non slash character // preceding the last slash. - end = value.find_last_not_of(os::PATH_SEPARATOR, end); + end = value.find_last_not_of(separator, end); // Paths containing no non slash characters result in "/". if (end == std::string::npos) { - return stringify(os::PATH_SEPARATOR); + return stringify(separator); } return value.substr(0, end + 1); @@ -321,6 +324,7 @@ public: private: std::string value; + char separator; };