Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmXMLSafe.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmXMLSafe_h
13 #define cmXMLSafe_h
14
15 #include <cmsys/stl/string>
16 #include <cmsys/ios/iosfwd>
17
18 /** \class cmXMLSafe
19  * \brief Write strings to XML with proper escapes
20  */
21 class cmXMLSafe
22 {
23 public:
24   /** Construct with the data to be written.  This assumes the data
25       will exist for the duration of this object's life.  */
26   cmXMLSafe(const char* s);
27   cmXMLSafe(cmsys_stl::string const& s);
28
29   /** Specify whether to escape quotes too.  This is needed when
30       writing the content of an attribute value.  By default quotes
31       are escaped.  */
32   cmXMLSafe& Quotes(bool b = true);
33
34   /** Get the escaped data as a string.  */
35   cmsys_stl::string str();
36 private:
37   char const* Data;
38   unsigned long Size;
39   bool DoQuotes;
40   friend cmsys_ios::ostream& operator<<(cmsys_ios::ostream&,
41                                         cmXMLSafe const&);
42 };
43
44 #endif