From cb953b4203cda98ef44ad7c796709f2a3b7348d5 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Wed, 12 Feb 2020 08:26:01 -0800 Subject: [PATCH] Remove usage of from Path. There was actually no need to give special treatment to leading drive designators since they effectively form the first path segment anyway. To help prevent regressions, I added a few unit tests in a previous CL. The motivation for the CL is to remove a dependency on `locale.cpp`, which can result in shorter build times and reduced binary sizes. --- libs/utils/src/Path.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libs/utils/src/Path.cpp b/libs/utils/src/Path.cpp index e31fa3469d..781508e086 100644 --- a/libs/utils/src/Path.cpp +++ b/libs/utils/src/Path.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #if defined(WIN32) # include @@ -185,12 +184,12 @@ std::vector Path::split() const { size_t current; ssize_t next = -1; - // Matches a leading disk designator (C:\), forward slash (/), or back slash (\) - const static std::regex driveDesignationRegex(R"_regex(^([a-zA-Z]:\\|\\|\/))_regex"); - std::smatch match; - if (std::regex_search(m_path, match, driveDesignationRegex)) { - segments.push_back(match[0]); - next = match[0].length() - 1; + // If there is a leading disk designator such as C:, this naturally becomes the first segment. + // However if there there is leading slash or back slash, we need to explicitly preserve it. + // Note that we are guaranteed to have at least one char in the path at this point. + if (m_path[0] == '/' || m_path[0] == '\\') { + segments.push_back(m_path.substr(0, 1)); + next = 0; } do {