summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorArtur Ryt <artur.ryt@gmail.com>2019-02-26 20:25:00 (GMT)
committerArtur Ryt <artur.ryt@gmail.com>2019-02-26 20:39:10 (GMT)
commit9636b03cca8b812fa2e33adf9b30ab5268b6eefb (patch)
tree05b12999bad921e49d63a4d09318729354460060 /Source
parent78ff8d573777c099aea5bd2eb92d9866c0d85952 (diff)
downloadCMake-9636b03cca8b812fa2e33adf9b30ab5268b6eefb.zip
CMake-9636b03cca8b812fa2e33adf9b30ab5268b6eefb.tar.gz
CMake-9636b03cca8b812fa2e33adf9b30ab5268b6eefb.tar.bz2
cmFileCommand: Refactor HandleCMakePathCommand
Make use of cmJoin and fresh cmRange::transform to reduce function complexity. Move conversion logic to named functions.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmFileCommand.cxx47
1 files changed, 23 insertions, 24 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 59ef48d..a2018c3 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -2500,44 +2500,43 @@ bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
return true;
}
+namespace {
+std::string ToNativePath(const std::string& path)
+{
+ const auto& outPath = cmSystemTools::ConvertToOutputPath(path);
+ if (outPath.size() > 1 && outPath.front() == '\"' &&
+ outPath.back() == '\"') {
+ return outPath.substr(1, outPath.size() - 2);
+ }
+ return outPath;
+}
+
+std::string ToCMakePath(const std::string& path)
+{
+ auto temp = path;
+ cmSystemTools::ConvertToUnixSlashes(temp);
+ return temp;
+}
+}
+
bool cmFileCommand::HandleCMakePathCommand(
std::vector<std::string> const& args, bool nativePath)
{
- std::vector<std::string>::const_iterator i = args.begin();
if (args.size() != 3) {
this->SetError("FILE([TO_CMAKE_PATH|TO_NATIVE_PATH] path result) must be "
"called with exactly three arguments.");
return false;
}
- i++; // Get rid of subcommand
#if defined(_WIN32) && !defined(__CYGWIN__)
char pathSep = ';';
#else
char pathSep = ':';
#endif
- std::vector<std::string> path = cmSystemTools::SplitString(*i, pathSep);
- i++;
- const char* var = i->c_str();
- std::string value;
- for (std::vector<std::string>::iterator j = path.begin(); j != path.end();
- ++j) {
- if (j != path.begin()) {
- value += ";";
- }
- if (!nativePath) {
- cmSystemTools::ConvertToUnixSlashes(*j);
- } else {
- *j = cmSystemTools::ConvertToOutputPath(*j);
- // remove double quotes in the path
- std::string& s = *j;
+ std::vector<std::string> path = cmSystemTools::SplitString(args[1], pathSep);
- if (s.size() > 1 && s.front() == '\"' && s.back() == '\"') {
- s = s.substr(1, s.size() - 2);
- }
- }
- value += *j;
- }
- this->Makefile->AddDefinition(var, value.c_str());
+ std::string value = cmJoin(
+ cmMakeRange(path).transform(nativePath ? ToNativePath : ToCMakePath), ";");
+ this->Makefile->AddDefinition(args[2], value.c_str());
return true;
}