XmlDeclaration.cpp 1.5 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: 2021-07-16
  7. *
  8. * */
  9. #include <ls_std/io/xml/XmlDeclaration.hpp>
  10. ls_std::XmlDeclaration::XmlDeclaration(const std::string& _version) : ls_std::Class("XmlDeclaration")
  11. {
  12. this->version.setValue(_version);
  13. }
  14. std::string ls_std::XmlDeclaration::getEncoding()
  15. {
  16. return this->encoding.getValue();
  17. }
  18. std::string ls_std::XmlDeclaration::getStandalone()
  19. {
  20. return this->standalone.getValue();
  21. }
  22. std::string ls_std::XmlDeclaration::getVersion()
  23. {
  24. return this->version.getValue();
  25. }
  26. void ls_std::XmlDeclaration::setEncoding(const std::string& _encoding)
  27. {
  28. this->encoding.setValue(_encoding);
  29. }
  30. void ls_std::XmlDeclaration::setStandalone(const std::string& _standalone)
  31. {
  32. this->standalone.setValue(_standalone);
  33. }
  34. void ls_std::XmlDeclaration::setVersion(const std::string& _version)
  35. {
  36. this->version.setValue(_version);
  37. }
  38. std::string ls_std::XmlDeclaration::toXml()
  39. {
  40. std::string declaration = "<?xml";
  41. declaration += ls_std::XmlDeclaration::_toXmlAttribute(this->version);
  42. declaration += ls_std::XmlDeclaration::_toXmlAttribute(this->encoding);
  43. declaration += ls_std::XmlDeclaration::_toXmlAttribute(this->standalone);
  44. return declaration + " ?>";
  45. }
  46. std::string ls_std::XmlDeclaration::_toXmlAttribute(ls_std::XmlAttribute _attribute)
  47. {
  48. std::string xmlString{};
  49. if (!_attribute.getValue().empty())
  50. {
  51. xmlString = " " + _attribute.toXml();
  52. }
  53. return xmlString;
  54. }