cmXMLSafe.h 974 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmXMLSafe_h
  4. #define cmXMLSafe_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <iosfwd>
  7. #include <string>
  8. /** \class cmXMLSafe
  9. * \brief Write strings to XML with proper escapes
  10. */
  11. class cmXMLSafe
  12. {
  13. public:
  14. /** Construct with the data to be written. This assumes the data
  15. will exist for the duration of this object's life. */
  16. cmXMLSafe(const char* s);
  17. cmXMLSafe(std::string const& s);
  18. /** Specify whether to escape quotes too. This is needed when
  19. writing the content of an attribute value. By default quotes
  20. are escaped. */
  21. cmXMLSafe& Quotes(bool b = true);
  22. /** Get the escaped data as a string. */
  23. std::string str();
  24. private:
  25. char const* Data;
  26. unsigned long Size;
  27. bool DoQuotes;
  28. friend std::ostream& operator<<(std::ostream&, cmXMLSafe const&);
  29. };
  30. #endif