1 (in-package :cl-mediawiki
)
2 ;; This file has a few necessary random utility functions
5 "just ensure that you have alist"
6 (if (listp x
) x
(list x
)))
8 (defun symbolize-string (str &optional
(package :keyword
))
9 "Turns a string into a happy symbol
11 ex: ''foo bar_bast'' -> FOO-BAR-BAST
14 (string (intern (nsubstitute
16 (nsubstitute #\-
#\space
(string-upcase str
) :test
#'char
=)
21 (defun map-sxml-tree (fn tree
)
22 "Do a depth first traversal of some set of trees calling fn on every non-nil element. "
26 (dolist (n (cddr tree
))
31 (defun find-tree (pred tree
)
32 "find a tree based on a predicate"
34 (flet ((handler (node)
35 (when (funcall pred node
)
36 (push node results
))))
37 (map-sxml-tree #'handler tree
)
40 (defun find-nodes-by-name (name tree
)
41 "find all sxml nodes with a given name "
42 (find-tree (lambda (n)
44 (when (and (listp n
) (stringp (car n
)))
45 (car n
)) name
)) tree
))