Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use standard library functions where possible #215

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/hiccup/compiler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
1 (let [arg (first strs)]
(if (string? arg)
arg
`(String/valueOf (or ~arg ""))))
`(str (or ~arg ""))))
`(let [~w (StringBuilder.)]
~@(map (fn [arg]
(if (string? arg)
Expand Down Expand Up @@ -112,20 +112,26 @@
(or content
(and (html-mode?) (not (void-tags tag)))))

(def str-index-of
(or (resolve 'str/index-of)
(fn [^String tag ^String value]
(let [index (.indexOf tag value)]
(when (pos? index)
index)))))

(defn- parse-tag [^String tag]
(let [id-index (let [index (.indexOf tag "#")] (when (pos? index) index))
class-index (let [index (.indexOf tag ".")] (when (pos? index) index))]
(defn- parse-tag [tag]
(let [id-index (str-index-of tag "#")
class-index (str-index-of tag ".")]
[(cond
id-index (.substring tag 0 id-index)
class-index (.substring tag 0 class-index)
id-index (subs tag 0 id-index)
class-index (subs tag 0 class-index)
:else tag)
(when id-index
(if class-index
(.substring tag (unchecked-inc-int id-index) class-index)
(.substring tag (unchecked-inc-int id-index))))
(subs tag (unchecked-inc-int id-index) class-index)
(subs tag (unchecked-inc-int id-index))))
(when class-index
(.substring tag (unchecked-inc-int class-index)))]))
(subs tag (unchecked-inc-int class-index)))]))

(defn merge-classes [class classes]
(cond
Expand Down
Loading