Shinmera / plump

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

get-elements-by-tag-name in order that is the same as how them appear in the documents #29

Closed Inc0n closed 3 years ago

Inc0n commented 4 years ago

There has been a issue address this https://github.com/Shinmera/plump/issues/22, but it lacks a solution.

proposed fix:

(defun get-elements-by-tag-name (node tag)
  (loop :for child :across (plump:children node)
        :when (plump:element-p child)
          :when (string-equal tag (plump:tag-name child))
            :collect child
        :when (plump:element-p child)
          :append (get-elms-by-tag-name child tag)))

reason for a fix:

I assumed that using reverse or nreverse at the end of the function might introduce unwanted overhead, which is why I produce this "fix".

I sometimes parse some item listings, such as TOC of a book in xml, it would be much more convenient that the order is preserved as is.

This could potentially be a breaking change, but I would suggest that this would be more beneficial than being a breaking change, for those that relies on the nature that this function would return items in reversed order.