cmXMLSafe.h 945 B

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