Skip to content

Commit

Permalink
feat: less reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
erdos committed Aug 11, 2022
1 parent a96ae89 commit 82c07c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/stencil/merger.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns stencil.merger
"Token listaban a text tokenekbol kiszedi a parancsokat es action tokenekbe teszi."
(:require [clojure.data.xml :as xml]
[clojure.string :refer [index-of ends-with?]]
[stencil.postprocess.ignored-tag :as ignored-tag]
[stencil
[types :refer [open-tag close-tag]]
Expand Down Expand Up @@ -29,17 +30,14 @@

(defn find-first-code [^String s]
(assert (string? s))
(let [ind (.indexOf s (str open-tag))]
(when-not (neg? ind)
(let [after-idx (.indexOf s (str close-tag) ind)]
(if (neg? after-idx)
(cond-> {:action-part (.substring s (+ ind (count open-tag)))}
(not (zero? ind)) (assoc :before (.substring s 0 ind)))
(cond-> {:action (.substring s (+ ind (count open-tag))
after-idx)}
(not (zero? ind)) (assoc :before (.substring s 0 ind))
(not (= (+ (count close-tag) after-idx) (count s)))
(assoc :after (.substring s (+ (count close-tag) after-idx)))))))))
(when-let [ind (index-of s (str open-tag))]
(if-let [after-idx (index-of s (str close-tag) ind)]
(cond-> {:action (subs s (+ ind (count open-tag)) after-idx)}
(pos? ind) (assoc :before (subs s 0 ind))
(not= (+ (count close-tag) after-idx) (count s))
(assoc :after (subs s (+ (count close-tag) after-idx))))
(cond-> {:action-part (subs s (+ ind (count open-tag)))}
(not (zero? ind)) (assoc :before (subs s 0 ind))))))

(defn text-split-tokens [^String s]
(assert (string? s))
Expand Down Expand Up @@ -71,7 +69,7 @@
(defn -last-chars-count [sts-tokens]
(assert (sequential? sts-tokens))
(when-let [last-text (some-> sts-tokens last :text string)]
(some #(when (.endsWith last-text (string %))
(some #(when (ends-with? last-text (string %))
(count %))
(prefixes open-tag))))

Expand Down
1 change: 1 addition & 0 deletions test/stencil/merger_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"asdf{%xy%}" {:action "xy" :before "asdf"}
"{%xy%}" {:action "xy"}
"a{%xy" {:action-part "xy" :before "a"}
"a{%x%" {:action-part "x%" :before "a"}
"{%xy" {:action-part "xy"})))

(deftest text-split-tokens-test
Expand Down

0 comments on commit 82c07c8

Please sign in to comment.