stringapi: Use strings in Convert methods in LocalGenerator

The C strings were turned into std::strings internally anyways and most
callers used .c_str().
This commit is contained in:
Ben Boeckel 2014-02-04 13:31:39 -05:00 committed by Brad King
parent ce5114354c
commit a6ae2ea72b
3 changed files with 31 additions and 27 deletions

View File

@ -1230,7 +1230,7 @@ void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string std::string
cmLocalGenerator::ConvertToOutputForExistingCommon(const char* remote, cmLocalGenerator::ConvertToOutputForExistingCommon(const std::string& remote,
std::string const& result, std::string const& result,
OutputFormat format) OutputFormat format)
{ {
@ -1238,10 +1238,10 @@ cmLocalGenerator::ConvertToOutputForExistingCommon(const char* remote,
// already exists, we can use a short-path to reference it without a // already exists, we can use a short-path to reference it without a
// space. // space.
if(this->WindowsShell && result.find(' ') != result.npos && if(this->WindowsShell && result.find(' ') != result.npos &&
cmSystemTools::FileExists(remote)) cmSystemTools::FileExists(remote.c_str()))
{ {
std::string tmp; std::string tmp;
if(cmSystemTools::GetShortPath(remote, tmp)) if(cmSystemTools::GetShortPath(remote.c_str(), tmp))
{ {
return this->Convert(tmp.c_str(), NONE, format, true); return this->Convert(tmp.c_str(), NONE, format, true);
} }
@ -1253,7 +1253,7 @@ cmLocalGenerator::ConvertToOutputForExistingCommon(const char* remote,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string std::string
cmLocalGenerator::ConvertToOutputForExisting(const char* remote, cmLocalGenerator::ConvertToOutputForExisting(const std::string& remote,
RelativeRoot local, RelativeRoot local,
OutputFormat format) OutputFormat format)
{ {
@ -1267,7 +1267,7 @@ cmLocalGenerator::ConvertToOutputForExisting(const char* remote,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string std::string
cmLocalGenerator::ConvertToOutputForExisting(RelativeRoot remote, cmLocalGenerator::ConvertToOutputForExisting(RelativeRoot remote,
const char* local, const std::string& local,
OutputFormat format) OutputFormat format)
{ {
// Perform standard conversion. // Perform standard conversion.
@ -2513,7 +2513,8 @@ cmLocalGenerator::ConstructComment(const cmCustomCommand& cc,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string std::string
cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(const char* remote) cmLocalGenerator::ConvertToOptionallyRelativeOutputPath(
const std::string& remote)
{ {
return this->Convert(remote, START_OUTPUT, SHELL, true); return this->Convert(remote, START_OUTPUT, SHELL, true);
} }
@ -2533,7 +2534,7 @@ const char* cmLocalGenerator::GetRelativeRootPath(RelativeRoot relroot)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmLocalGenerator::Convert(const char* source, std::string cmLocalGenerator::Convert(const std::string& source,
RelativeRoot relative, RelativeRoot relative,
OutputFormat output, OutputFormat output,
bool optional) bool optional)
@ -2585,7 +2586,7 @@ std::string cmLocalGenerator::Convert(const char* source,
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmLocalGenerator::ConvertToOutputFormat(const char* source, std::string cmLocalGenerator::ConvertToOutputFormat(const std::string& source,
OutputFormat output) OutputFormat output)
{ {
std::string result = source; std::string result = source;
@ -2627,7 +2628,7 @@ std::string cmLocalGenerator::ConvertToOutputFormat(const char* source,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmLocalGenerator::Convert(RelativeRoot remote, std::string cmLocalGenerator::Convert(RelativeRoot remote,
const char* local, const std::string& local,
OutputFormat output, OutputFormat output,
bool optional) bool optional)
{ {
@ -2636,10 +2637,10 @@ std::string cmLocalGenerator::Convert(RelativeRoot remote,
// The relative root must have a path (i.e. not FULL or NONE) // The relative root must have a path (i.e. not FULL or NONE)
assert(remotePath != 0); assert(remotePath != 0);
if(local && (!optional || this->UseRelativePaths)) if(!local.empty() && (!optional || this->UseRelativePaths))
{ {
std::vector<std::string> components; std::vector<std::string> components;
cmSystemTools::SplitPath(local, components); cmSystemTools::SplitPath(local.c_str(), components);
std::string result = this->ConvertToRelativePath(components, remotePath); std::string result = this->ConvertToRelativePath(components, remotePath);
return this->ConvertToOutputFormat(result.c_str(), output); return this->ConvertToOutputFormat(result.c_str(), output);
} }
@ -2722,7 +2723,8 @@ static bool cmLocalGeneratorNotAbove(const char* a, const char* b)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string std::string
cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local, cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
const char* in_remote, bool force) const std::string& in_remote,
bool force)
{ {
// The path should never be quoted. // The path should never be quoted.
assert(in_remote[0] != '\"'); assert(in_remote[0] != '\"');
@ -2731,7 +2733,7 @@ cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
assert(local.size() > 0 && !(local[local.size()-1] == "")); assert(local.size() > 0 && !(local[local.size()-1] == ""));
// If the path is already relative then just return the path. // If the path is already relative then just return the path.
if(!cmSystemTools::FileIsFullPath(in_remote)) if(!cmSystemTools::FileIsFullPath(in_remote.c_str()))
{ {
return in_remote; return in_remote;
} }
@ -2750,11 +2752,11 @@ cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
std::string local_path = cmSystemTools::JoinPath(local); std::string local_path = cmSystemTools::JoinPath(local);
if(!((cmLocalGeneratorNotAbove(local_path.c_str(), if(!((cmLocalGeneratorNotAbove(local_path.c_str(),
this->RelativePathTopBinary.c_str()) && this->RelativePathTopBinary.c_str()) &&
cmLocalGeneratorNotAbove(in_remote, cmLocalGeneratorNotAbove(in_remote.c_str(),
this->RelativePathTopBinary.c_str())) || this->RelativePathTopBinary.c_str())) ||
(cmLocalGeneratorNotAbove(local_path.c_str(), (cmLocalGeneratorNotAbove(local_path.c_str(),
this->RelativePathTopSource.c_str()) && this->RelativePathTopSource.c_str()) &&
cmLocalGeneratorNotAbove(in_remote, cmLocalGeneratorNotAbove(in_remote.c_str(),
this->RelativePathTopSource.c_str())))) this->RelativePathTopSource.c_str()))))
{ {
return in_remote; return in_remote;
@ -2764,7 +2766,7 @@ cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
// Identify the longest shared path component between the remote // Identify the longest shared path component between the remote
// path and the local path. // path and the local path.
std::vector<std::string> remote; std::vector<std::string> remote;
cmSystemTools::SplitPath(in_remote, remote); cmSystemTools::SplitPath(in_remote.c_str(), remote);
unsigned int common=0; unsigned int common=0;
while(common < remote.size() && while(common < remote.size() &&
common < local.size() && common < local.size() &&
@ -2982,7 +2984,7 @@ bool cmLocalGeneratorCheckObjectName(std::string& objName,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string& std::string&
cmLocalGenerator cmLocalGenerator
::CreateSafeUniqueObjectFileName(const char* sin, ::CreateSafeUniqueObjectFileName(const std::string& sin,
std::string const& dir_max) std::string const& dir_max)
{ {
// Look for an existing mapped name for this object file. // Look for an existing mapped name for this object file.

View File

@ -106,11 +106,12 @@ public:
*/ */
enum RelativeRoot { NONE, FULL, HOME, START, HOME_OUTPUT, START_OUTPUT }; enum RelativeRoot { NONE, FULL, HOME, START, HOME_OUTPUT, START_OUTPUT };
enum OutputFormat { UNCHANGED, MAKEFILE, SHELL, RESPONSE }; enum OutputFormat { UNCHANGED, MAKEFILE, SHELL, RESPONSE };
std::string ConvertToOutputFormat(const char* source, OutputFormat output); std::string ConvertToOutputFormat(const std::string& source,
std::string Convert(const char* remote, RelativeRoot local, OutputFormat output);
std::string Convert(const std::string& remote, RelativeRoot local,
OutputFormat output = UNCHANGED, OutputFormat output = UNCHANGED,
bool optional = false); bool optional = false);
std::string Convert(RelativeRoot remote, const char* local, std::string Convert(RelativeRoot remote, const std::string& local,
OutputFormat output = UNCHANGED, OutputFormat output = UNCHANGED,
bool optional = false); bool optional = false);
@ -125,7 +126,7 @@ public:
* remote path must use forward slashes and not already be escaped * remote path must use forward slashes and not already be escaped
* or quoted. * or quoted.
*/ */
std::string ConvertToOptionallyRelativeOutputPath(const char* remote); std::string ConvertToOptionallyRelativeOutputPath(const std::string& remote);
///! set/get the parent generator ///! set/get the parent generator
cmLocalGenerator* GetParent(){return this->Parent;} cmLocalGenerator* GetParent(){return this->Parent;}
@ -198,14 +199,14 @@ public:
std::string& dep); std::string& dep);
///! for existing files convert to output path and short path if spaces ///! for existing files convert to output path and short path if spaces
std::string ConvertToOutputForExisting(const char* remote, std::string ConvertToOutputForExisting(const std::string& remote,
RelativeRoot local = START_OUTPUT, RelativeRoot local = START_OUTPUT,
OutputFormat format = SHELL); OutputFormat format = SHELL);
/** For existing path identified by RelativeRoot convert to output /** For existing path identified by RelativeRoot convert to output
path and short path if spaces. */ path and short path if spaces. */
std::string ConvertToOutputForExisting(RelativeRoot remote, std::string ConvertToOutputForExisting(RelativeRoot remote,
const char* local = 0, const std::string& local = "",
OutputFormat format = SHELL); OutputFormat format = SHELL);
virtual std::string ConvertToIncludeReference(std::string const& path, virtual std::string ConvertToIncludeReference(std::string const& path,
@ -309,7 +310,8 @@ public:
* or quoted. * or quoted.
*/ */
std::string ConvertToRelativePath(const std::vector<std::string>& local, std::string ConvertToRelativePath(const std::vector<std::string>& local,
const char* remote, bool force=false); const std::string& remote,
bool force=false);
/** /**
* Get the relative path from the generator output directory to a * Get the relative path from the generator output directory to a
@ -410,7 +412,7 @@ protected:
std::ostream& os, const char* config, std::ostream& os, const char* config,
std::vector<std::string> const& configurationTypes); std::vector<std::string> const& configurationTypes);
std::string& CreateSafeUniqueObjectFileName(const char* sin, std::string& CreateSafeUniqueObjectFileName(const std::string& sin,
std::string const& dir_max); std::string const& dir_max);
void ComputeObjectMaxPath(); void ComputeObjectMaxPath();
@ -472,7 +474,7 @@ protected:
cmIML_INT_uint64_t BackwardsCompatibility; cmIML_INT_uint64_t BackwardsCompatibility;
bool BackwardsCompatibilityFinal; bool BackwardsCompatibilityFinal;
private: private:
std::string ConvertToOutputForExistingCommon(const char* remote, std::string ConvertToOutputForExistingCommon(const std::string& remote,
std::string const& result, std::string const& result,
OutputFormat format); OutputFormat format);

View File

@ -269,7 +269,7 @@ protected:
//================================================================== //==================================================================
// Convenience routines that do nothing more than forward to // Convenience routines that do nothing more than forward to
// implementaitons // implementaitons
std::string Convert(const char* source, std::string Convert(const std::string& source,
cmLocalGenerator::RelativeRoot relative, cmLocalGenerator::RelativeRoot relative,
cmLocalGenerator::OutputFormat output = cmLocalGenerator::OutputFormat output =
cmLocalGenerator::UNCHANGED, cmLocalGenerator::UNCHANGED,