summaryrefslogtreecommitdiffstats
path: root/Source/cmXCodeObject.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2008-09-02 14:27:15 (GMT)
committerBrad King <brad.king@kitware.com>2008-09-02 14:27:15 (GMT)
commit698b8044a627293dd6a453c2fa10284000b2f5b1 (patch)
treed285499547a628d8861dc91bec4e4b9520f450c1 /Source/cmXCodeObject.cxx
parent6eea886474541c7cee58a24a6432d12e598f3f28 (diff)
downloadCMake-698b8044a627293dd6a453c2fa10284000b2f5b1.zip
CMake-698b8044a627293dd6a453c2fa10284000b2f5b1.tar.gz
CMake-698b8044a627293dd6a453c2fa10284000b2f5b1.tar.bz2
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.
Diffstat (limited to 'Source/cmXCodeObject.cxx')
-rw-r--r--Source/cmXCodeObject.cxx58
1 files changed, 33 insertions, 25 deletions
diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx
index b6c5be2..0a430f5 100644
--- a/Source/cmXCodeObject.cxx
+++ b/Source/cmXCodeObject.cxx
@@ -151,7 +151,9 @@ void cmXCodeObject::Print(std::ostream& out)
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)
{
@@ -160,7 +162,8 @@ void cmXCodeObject::Print(std::ostream& out)
{
if(j->second->List[k]->TypeValue == STRING)
{
- out << j->second->List[k]->String << ", ";
+ j->second->List[k]->PrintString(out);
+ out << ", ";
}
else
{
@@ -192,7 +195,9 @@ void cmXCodeObject::Print(std::ostream& out)
}
else if(object->TypeValue == STRING)
{
- out << i->first << " = " << object->String << ";" << separator;
+ out << i->first << " = ";
+ object->PrintString(out);
+ out << ";" << separator;
}
else
{
@@ -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;
- if(ss.size() == 0)
- {
- this->String = "\"\"";
- return;
- }
- // escape quotes
- cmSystemTools::ReplaceString(ss, "\"", "\\\"");
- bool needQuote = false;
- this->String = "";
- if(ss.find_first_of(" <>.+-=@") != ss.npos)
- {
- needQuote = true;
- }
- if(needQuote)
- {
- this->String = "\"";
- }
- this->String += ss;
- if(needQuote)
+ // The string needs to be quoted if it contains any characters
+ // considered special by the Xcode project file parser.
+ bool needQuote =
+ (this->String.empty() ||
+ this->String.find_first_of(" <>.+-=@") != this->String.npos);
+ const char* quote = needQuote? "\"" : "";
+
+ // Print the string, quoted and escaped as necessary.
+ os << quote;
+ for(std::string::const_iterator i = this->String.begin();
+ i != this->String.end(); ++i)
{
- this->String += "\"";
+ if(*i == '"')
+ {
+ // Escape double-quotes.
+ os << '\\';
+ }
+ os << *i;
}
+ os << quote;
+}
+
+//----------------------------------------------------------------------------
+void cmXCodeObject::SetString(const char* s)
+{
+ this->String = s;
}