Closed aengelberg closed 9 years ago
This may be part of the problem:
cljs.user=> (require '[instaparse.failure :as fail])
nil
cljs.user=> (fail/line-seq "a\nb\nc")
("a" "b" "c")
cljs.user=> (fail/line-seq "a\n\nb")
("a" "b")
line-seq
on "a\n\nb"
should return a blank line in the middle, but it is skipped over by your partition-by
strategy.
Perhaps it would be more elegant (and performant) to skip line-seq
altogether and write a more straightforward function to get the nth line of the text.
(defn get-line
[n text]
(loop [chars (seq (clojure.string/replace text "\r\n" "\n"))
n n]
(cond
(empty? chars) ""
(= n 1) (apply str (take-while (complement newline-chars?) chars))
(newline-chars? (first chars)) (recur (next chars) (dec n))
:else (recur (next chars) n))))
Incorporated your suggested, more elegant, get-line into master. Thanks.
This works properly:
This does not: