XmlDeclaration.cpp 1.6 KB

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