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: 2021-04-23
  7. *
  8. * */
  9. #include <ls_std/io/xml/XMLDeclaration.hpp>
  10. ls_std::XMLDeclaration::XMLDeclaration(std::string _version) : ls_std::Class("XMLDeclaration")
  11. {
  12. this->version.setValue(std::move(_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(std::string _encoding)
  27. {
  28. this->encoding.setValue(std::move(_encoding));
  29. }
  30. void ls_std::XMLDeclaration::setStandalone(std::string _standalone)
  31. {
  32. this->standalone.setValue(std::move(_standalone));
  33. }
  34. void ls_std::XMLDeclaration::setVersion(std::string _version)
  35. {
  36. this->version.setValue(std::move(_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. }