Skip to content

Commit

Permalink
be able to parse SmallRye-like arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
source-c committed Nov 2, 2022
1 parent 943d96a commit fd09468
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 8 additions & 0 deletions resources/test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ front.2.1.type=ttt
front.4.2.mode=zzz
front.4.2.type=1

tomato.0 = "vvv"
tomato.1 = "zzz"

service[0]="foo"
service[1].bar = "bar"
service[2][1]= "baz"
service[2][2].zoo = 11
service[4][3]= true

foo[0].maa[0] = 1
foo[0].maa[1] = 2

scheduler."threadPool.threadCount"=12
12 changes: 9 additions & 3 deletions src/java_properties/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@
(def ^:private pairs (atom {}))

(defn extract-strings [line]
(let [strings (re-seq #"\"[^\"]+\"" line)]
(let [line' (-> line
(s/replace #"\[(\d+)\]\." ".$1.")
(s/replace #"\[(\d+)\]\s*=" ".$1=")
(s/replace #"\[(\d+)\]" ".$1.")
(s/replace #"\.+" ".")
(s/replace #"\.+$" ""))
strings (re-seq #"\"[^\"]+\"" line')]
(if (empty? strings)
line
(loop [li line st strings]
line'
(loop [li line' st strings]
(let [term (first st)
hashed (some-> term .getBytes hex)]
(swap! pairs assoc hashed (some-> term (s/replace "\"" "") keyword))
Expand Down

0 comments on commit fd09468

Please sign in to comment.