XmlDeclaration.cpp 1.5 KB

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