Skip to content
Snippets Groups Projects
Commit 698b8044 authored by Brad King's avatar Brad King
Browse files

ENH: Simplify string attributes in Xcode generator

This change cleans up the implementation of cmXCodeObject to avoid
un-escaping and re-escaping string values.  There is no need to store
the string in escaped form.  It can be escaped once when it is printed
out to the generated project file.
parent 6eea8864
No related branches found
No related tags found
No related merge requests found
...@@ -689,7 +689,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen, ...@@ -689,7 +689,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen,
cmTarget::SourceFileFlags tsFlags = cmTarget::SourceFileFlags tsFlags =
cmtarget.GetTargetSourceFileFlags(*i); cmtarget.GetTargetSourceFileFlags(*i);
if(strcmp(filetype->GetString(), "\"compiled.mach-o.objfile\"") == 0) if(strcmp(filetype->GetString(), "compiled.mach-o.objfile") == 0)
{ {
externalObjFiles.push_back(xsf); externalObjFiles.push_back(xsf);
} }
...@@ -1957,22 +1957,8 @@ void cmGlobalXCodeGenerator::AppendOrAddBuildSetting(cmXCodeObject* settings, ...@@ -1957,22 +1957,8 @@ void cmGlobalXCodeGenerator::AppendOrAddBuildSetting(cmXCodeObject* settings,
else else
{ {
std::string oldValue = attr->GetString(); std::string oldValue = attr->GetString();
// unescape escaped quotes internal to the string:
cmSystemTools::ReplaceString(oldValue, "\\\"", "\"");
// remove surrounding quotes, if any:
std::string::size_type len = oldValue.length();
if(oldValue[0] == '\"' && oldValue[len-1] == '\"')
{
oldValue = oldValue.substr(1, len-2);
}
oldValue += " "; oldValue += " ";
oldValue += value; oldValue += value;
// SetString automatically escapes internal quotes and then surrounds
// the result with quotes if necessary...
attr->SetString(oldValue.c_str()); attr->SetString(oldValue.c_str());
} }
} }
......
...@@ -151,7 +151,9 @@ void cmXCodeObject::Print(std::ostream& out) ...@@ -151,7 +151,9 @@ void cmXCodeObject::Print(std::ostream& out)
if(j->second->TypeValue == STRING) if(j->second->TypeValue == STRING)
{ {
out << j->first << " = " << j->second->String << ";"; out << j->first << " = ";
j->second->PrintString(out);
out << ";";
} }
else if(j->second->TypeValue == OBJECT_LIST) else if(j->second->TypeValue == OBJECT_LIST)
{ {
...@@ -160,7 +162,8 @@ void cmXCodeObject::Print(std::ostream& out) ...@@ -160,7 +162,8 @@ void cmXCodeObject::Print(std::ostream& out)
{ {
if(j->second->List[k]->TypeValue == STRING) if(j->second->List[k]->TypeValue == STRING)
{ {
out << j->second->List[k]->String << ", "; j->second->List[k]->PrintString(out);
out << ", ";
} }
else else
{ {
...@@ -192,7 +195,9 @@ void cmXCodeObject::Print(std::ostream& out) ...@@ -192,7 +195,9 @@ void cmXCodeObject::Print(std::ostream& out)
} }
else if(object->TypeValue == STRING) else if(object->TypeValue == STRING)
{ {
out << i->first << " = " << object->String << ";" << separator; out << i->first << " = ";
object->PrintString(out);
out << ";" << separator;
} }
else else
{ {
...@@ -230,29 +235,32 @@ void cmXCodeObject::CopyAttributes(cmXCodeObject* copy) ...@@ -230,29 +235,32 @@ void cmXCodeObject::CopyAttributes(cmXCodeObject* copy)
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmXCodeObject::SetString(const char* s) void cmXCodeObject::PrintString(std::ostream& os) const
{ {
std::string ss = s; // The string needs to be quoted if it contains any characters
if(ss.size() == 0) // considered special by the Xcode project file parser.
{ bool needQuote =
this->String = "\"\""; (this->String.empty() ||
return; this->String.find_first_of(" <>.+-=@") != this->String.npos);
} const char* quote = needQuote? "\"" : "";
// escape quotes
cmSystemTools::ReplaceString(ss, "\"", "\\\""); // Print the string, quoted and escaped as necessary.
bool needQuote = false; os << quote;
this->String = ""; for(std::string::const_iterator i = this->String.begin();
if(ss.find_first_of(" <>.+-=@") != ss.npos) i != this->String.end(); ++i)
{
needQuote = true;
}
if(needQuote)
{
this->String = "\"";
}
this->String += ss;
if(needQuote)
{ {
this->String += "\""; if(*i == '"')
{
// Escape double-quotes.
os << '\\';
}
os << *i;
} }
os << quote;
}
//----------------------------------------------------------------------------
void cmXCodeObject::SetString(const char* s)
{
this->String = s;
} }
...@@ -147,6 +147,8 @@ public: ...@@ -147,6 +147,8 @@ public:
std::vector<cmXCodeObject*> const& GetObjectList() { return this->List;} std::vector<cmXCodeObject*> const& GetObjectList() { return this->List;}
void SetComment(const char* c) { this->Comment = c;} void SetComment(const char* c) { this->Comment = c;}
protected: protected:
void PrintString(std::ostream& os) const;
cmTarget* Target; cmTarget* Target;
Type TypeValue; Type TypeValue;
cmStdString Id; cmStdString Id;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment