cmXMLSafe.h 1.4 KB

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