cmLocalUnixMakefileGenerator3: Re-organize ConvertToQuotedOutputPath

Use one code path whether the components list is empty or not.
Fix indentation accordingly.
This commit is contained in:
Jiri Malak 2014-03-25 07:17:45 +01:00 committed by Brad King
parent a29ea834de
commit a863a8fecd
1 changed files with 33 additions and 34 deletions

View File

@ -2183,52 +2183,51 @@ cmLocalUnixMakefileGenerator3
std::string std::string
cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p) cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p)
{ {
// Split the path into its components. // Split the path into its components.
std::vector<std::string> components; std::vector<std::string> components;
cmSystemTools::SplitPath(p, components); cmSystemTools::SplitPath(p, components);
// Return an empty path if there are no components. // Open the quoted result.
if(components.empty()) std::string result = "\"";
{
return "\"\"";
}
// Choose a slash direction and fix root component. // Return an empty path if there are no components.
const char* slash = "/"; if(!components.empty())
{
// Choose a slash direction and fix root component.
const char* slash = "/";
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
if(!cmSystemTools::GetForceUnixPaths()) if(!cmSystemTools::GetForceUnixPaths())
{ {
slash = "\\"; slash = "\\";
for(std::string::iterator i = components[0].begin(); for(std::string::iterator i = components[0].begin();
i != components[0].end(); ++i) i != components[0].end(); ++i)
{ {
if(*i == '/') if(*i == '/')
{ {
*i = '\\'; *i = '\\';
} }
} }
} }
#endif #endif
// Begin the quoted result with the root component. // Begin the quoted result with the root component.
std::string result = "\""; result += components[0];
result += components[0];
// Now add the rest of the components separated by the proper slash // Now add the rest of the components separated by the proper slash
// direction for this platform. // direction for this platform.
bool first = true; bool first = true;
for(unsigned int i=1; i < components.size(); ++i) for(unsigned int i=1; i < components.size(); ++i)
{
// Only the last component can be empty to avoid double slashes.
if(components[i].length() > 0 || (i == (components.size()-1)))
{ {
if(!first) // Only the last component can be empty to avoid double slashes.
if(components[i].length() > 0 || (i == (components.size()-1)))
{ {
result += slash; if(!first)
{
result += slash;
}
result += components[i];
first = false;
} }
result += components[i];
first = false;
} }
} }