XmlDeclaration.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Co-Author: Claude Sonnet 4.6 (LLM)
  4. * Company: Lynar Studios
  5. * E-Mail: webmaster@lynarstudios.com
  6. * Created: 2020-09-29
  7. * Changed: 2026-06-23
  8. *
  9. * */
  10. #include <ls-std/io/xml/XmlDeclaration.hpp>
  11. using ls::standard::core::Class;
  12. using ls::standard::io::XmlAttribute;
  13. using ls::standard::io::XmlDeclaration;
  14. using std::string;
  15. XmlDeclaration::XmlDeclaration(const string &_version) : Class("XmlDeclaration")
  16. {
  17. this->version.setValue(_version);
  18. }
  19. XmlDeclaration::~XmlDeclaration() noexcept = default;
  20. string XmlDeclaration::getEncoding() const
  21. {
  22. return this->encoding.getValue();
  23. }
  24. string XmlDeclaration::getStandalone() const
  25. {
  26. return this->standalone.getValue();
  27. }
  28. string XmlDeclaration::getVersion() const
  29. {
  30. return this->version.getValue();
  31. }
  32. void XmlDeclaration::setEncoding(const string &_encoding)
  33. {
  34. this->encoding.setValue(_encoding);
  35. }
  36. void XmlDeclaration::setStandalone(const string &_standalone)
  37. {
  38. this->standalone.setValue(_standalone);
  39. }
  40. void XmlDeclaration::setVersion(const string &_version)
  41. {
  42. this->version.setValue(_version);
  43. }
  44. string XmlDeclaration::toXml() const
  45. {
  46. string declaration = "<?xml";
  47. declaration += _toXmlAttribute(this->version);
  48. declaration += _toXmlAttribute(this->encoding);
  49. declaration += _toXmlAttribute(this->standalone);
  50. return declaration + " ?>";
  51. }
  52. string XmlDeclaration::_toXmlAttribute(const XmlAttribute &_attribute)
  53. {
  54. string xmlString{};
  55. if (!_attribute.getValue().empty())
  56. {
  57. xmlString = " " + _attribute.toXml();
  58. }
  59. return xmlString;
  60. }