summaryrefslogtreecommitdiffstats
path: root/Source/cmXMLSafe.h
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-02-05 21:31:37 (GMT)
committerBrad King <brad.king@kitware.com>2009-02-05 21:31:37 (GMT)
commitdc13914cd698b49cbae491c1e1aebbcd44fbe932 (patch)
tree4eaa716c3e2160a7e81125360d83dc9f87241ede /Source/cmXMLSafe.h
parentf16a471576199ec275463e35ff17849350c0da79 (diff)
downloadCMake-dc13914cd698b49cbae491c1e1aebbcd44fbe932.zip
CMake-dc13914cd698b49cbae491c1e1aebbcd44fbe932.tar.gz
CMake-dc13914cd698b49cbae491c1e1aebbcd44fbe932.tar.bz2
ENH: Create cmXMLSafe to help escapes in XML
This class provides easy syntax to efficiently insert blocks of data into XML documents with proper escapes. It replaces the old cmCTest::MakeXMLSafe and cmSystemTools::MakeXMLSafe methods which allocated extra memory instead of directly streaming the data.
Diffstat (limited to 'Source/cmXMLSafe.h')
-rw-r--r--Source/cmXMLSafe.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/Source/cmXMLSafe.h b/Source/cmXMLSafe.h
new file mode 100644
index 0000000..6352ad6
--- /dev/null
+++ b/Source/cmXMLSafe.h
@@ -0,0 +1,49 @@
+/*=========================================================================
+
+ Program: CMake - Cross-Platform Makefile Generator
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+ Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
+ See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*/
+#ifndef cmXMLSafe_h
+#define cmXMLSafe_h
+
+#include <cmsys/stl/string>
+#include <cmsys/ios/iosfwd>
+
+/** \class cmXMLSafe
+ * \brief Write strings to XML with proper escapes
+ */
+class cmXMLSafe
+{
+public:
+ /** Construct with the data to be written. This assumes the data
+ will exist for the duration of this object's life. */
+ cmXMLSafe(const char* s);
+ cmXMLSafe(cmsys_stl::string const& str);
+
+ /** Specify whether to escape quotes too. This is needed when
+ writing the content of an attribute value. By default quotes
+ are escaped. */
+ cmXMLSafe& Quotes(bool b = true);
+
+ /** Get the escaped data as a string. */
+ cmsys_stl::string str();
+private:
+ char const* Data;
+ unsigned long Size;
+ bool DoQuotes;
+ friend cmsys_ios::ostream& operator<<(cmsys_ios::ostream&,
+ cmXMLSafe const&);
+};
+
+#endif