Remove usage of <regex> 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.
This commit is contained in:
Philip Rideout
2020-02-12 10:03:06 -08:00
parent c0e2cfb684
commit cb953b4203
+6 -7
View File
@@ -19,7 +19,6 @@
#include <sstream>
#include <ostream>
#include <iterator>
#include <regex>
#if defined(WIN32)
# include <utils/compiler.h>
@@ -185,12 +184,12 @@ std::vector<std::string> 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 {