XmlDeclaration.cpp 1.6 KB

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