diff options
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 16 | ||||
-rw-r--r-- | Source/cmXCodeObject.cxx | 58 | ||||
-rw-r--r-- | Source/cmXCodeObject.h | 2 |
3 files changed, 36 insertions, 40 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 4ca55c5..2e00d13 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -689,7 +689,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen, cmTarget::SourceFileFlags tsFlags = 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); } @@ -1957,22 +1957,8 @@ void cmGlobalXCodeGenerator::AppendOrAddBuildSetting(cmXCodeObject* settings, else { 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 += value; - - // SetString automatically escapes internal quotes and then surrounds - // the result with quotes if necessary... attr->SetString(oldValue.c_str()); } } 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; } diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h index eecb0e0..303fbf5 100644 --- a/Source/cmXCodeObject.h +++ b/Source/cmXCodeObject.h @@ -147,6 +147,8 @@ public: std::vector<cmXCodeObject*> const& GetObjectList() { return this->List;} void SetComment(const char* c) { this->Comment = c;} protected: + void PrintString(std::ostream& os) const; + cmTarget* Target; Type TypeValue; cmStdString Id; |