Shinmera / plump

Practically Lenient and Unimpressive Markup Parser for Common Lisp
https://shinmera.github.io/plump
zlib License
119 stars 21 forks source link

Serialize <?xml with version first; if version not parsed, add it #35

Closed VaclavSynacek closed 3 years ago

VaclavSynacek commented 3 years ago

Small free form test:

(ql:quickload '(:plump :str))

(defun roundtrip (xml-string)
  (with-output-to-string (*standard-output*)
    (plump:serialize (plump:parse xml-string))))

(assert
  (str:starts-with-p "<?xml version=\"1.1\""
    (roundtrip       "<?xml version=\"1.1\" encoding=\"UTF-8\"?>")))
(assert
  (str:starts-with-p "<?xml version=\"1.1\""
    (roundtrip       "<?xml encoding=\"UTF-8\" version=\"1.1\"?>")))
(assert
  (str:starts-with-p "<?xml version=\"1.1\""
    (roundtrip       "<?xml version=\"1.1\"")))
(assert
  (str:starts-with-p "<?xml version=\"1.0\""
    (roundtrip       "<?xml encoding=\"UTF-8\"?>")))
Shinmera commented 3 years ago

Your proposed solution would introduce a lot of unnecessary consing. I've fixed it up and cleaned some style issues.