XmlDeclaration.cpp 1.7 KB

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