aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/lazy_xml
diff options
context:
space:
mode:
authorChouser <chouser@n01se.net>2009-02-22 01:16:40 +0000
committerChouser <chouser@n01se.net>2009-02-22 01:16:40 +0000
commit8cd98884452912454d297f217e0840d84553c49c (patch)
tree0803a218a96961123f6baac31181a8084f592c74 /src/clojure/contrib/lazy_xml
parent46a05fd000b4123fae3a9a4b2762f73908e52409 (diff)
lazy-xml: update for lazier Clojure
Diffstat (limited to 'src/clojure/contrib/lazy_xml')
-rw-r--r--src/clojure/contrib/lazy_xml/with_pull.clj34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/clojure/contrib/lazy_xml/with_pull.clj b/src/clojure/contrib/lazy_xml/with_pull.clj
index 7d70d479..06181569 100644
--- a/src/clojure/contrib/lazy_xml/with_pull.clj
+++ b/src/clojure/contrib/lazy_xml/with_pull.clj
@@ -27,22 +27,24 @@
(into {} (concat (ns-decs xpp) (attrs xpp))))
(defn- pull-step [xpp]
- (case (.next xpp)
- XmlPullParser/START_TAG
- (lazy-cons (struct node :start-element
- (keyword (.getName xpp))
- (attr-hash xpp))
- (pull-step xpp))
- XmlPullParser/END_TAG
- (lazy-cons (struct node :end-element
- (keyword (.getName xpp)))
- (pull-step xpp))
- XmlPullParser/TEXT
- (let [text (.trim (.getText xpp))]
- (if (seq text)
- (lazy-cons (struct node :characters nil nil text)
- (pull-step xpp))
- (recur xpp)))))
+ (let [step (fn [xpp]
+ (condp = (.next xpp)
+ XmlPullParser/START_TAG
+ (cons (struct node :start-element
+ (keyword (.getName xpp))
+ (attr-hash xpp))
+ (pull-step xpp))
+ XmlPullParser/END_TAG
+ (cons (struct node :end-element
+ (keyword (.getName xpp)))
+ (pull-step xpp))
+ XmlPullParser/TEXT
+ (let [text (.trim (.getText xpp))]
+ (if (empty? text)
+ (recur xpp)
+ (cons (struct node :characters nil nil text)
+ (pull-step xpp))))))]
+ (lazy-seq (step xpp))))
(def #^{:private true} factory
(doto (XmlPullParserFactory/newInstance)