summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx45
1 files changed, 45 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 45fa836..85d1786 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -1353,6 +1353,51 @@ bool cmSystemTools::PutEnv(const char* value)
return ret == 0;
}
+std::string cmSystemTools::MakeXMLSafe(const char* str)
+{
+ std::vector<char> result;
+ result.reserve(500);
+ const char* pos = str;
+ for ( ;*pos; ++pos)
+ {
+ char ch = *pos;
+ if ( (ch > 126 || ch < 32) && ch != 9 && ch != 10 && ch != 13 && ch != '\r' )
+ {
+ char buffer[33];
+ sprintf(buffer, "&lt;%d&gt;", (int)ch);
+ //sprintf(buffer, "&#x%0x;", (unsigned int)ch);
+ result.insert(result.end(), buffer, buffer+strlen(buffer));
+ }
+ else
+ {
+ const char* const encodedChars[] = {
+ "&amp;",
+ "&lt;",
+ "&gt;"
+ };
+ switch ( ch )
+ {
+ case '&':
+ result.insert(result.end(), encodedChars[0], encodedChars[0]+5);
+ break;
+ case '<':
+ result.insert(result.end(), encodedChars[1], encodedChars[1]+4);
+ break;
+ case '>':
+ result.insert(result.end(), encodedChars[2], encodedChars[2]+4);
+ break;
+ case '\n':
+ result.push_back('\n');
+ break;
+ case '\r': break; // Ignore \r
+ default:
+ result.push_back(ch);
+ }
+ }
+ }
+ return std::string(&*result.begin(), result.size());
+}
+
bool cmSystemTools::IsPathToFramework(const char* path)
{
if(cmSystemTools::FileIsFullPath(path))