Skip to content

Commit f0a4615

Browse files
tomfaulhaberstuarthalloway
authored andcommitted
Fix handling of the ~:(~) directive when the contents are the empty string. Refs #751
Signed-off-by: Stuart Halloway <[email protected]>
1 parent dd49d07 commit f0a4615

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/clj/clojure/pprint/cl_format.clj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,10 +1088,11 @@ Note this should only be used for the last one in the sequence"
10881088
(let [s ^String x]
10891089
(.write writer
10901090
^String (capitalize-string (.toLowerCase s) @last-was-whitespace?))
1091-
(dosync
1092-
(ref-set last-was-whitespace?
1093-
(Character/isWhitespace
1094-
^Character (nth s (dec (count s)))))))
1091+
(when (pos? (.length s))
1092+
(dosync
1093+
(ref-set last-was-whitespace?
1094+
(Character/isWhitespace
1095+
^Character (nth s (dec (count s))))))))
10951096

10961097
Integer
10971098
(let [c (char x)]

test/clojure/test_clojure/pprint/test_cl_format.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@
253253
(cl-format nil "~:(~A~)" 'kludgy-hash-search) "Kludgy-Hash-Search"
254254
(cl-format nil "~:(~A~)" "DON'T!") "Don'T!" ;not "Don't!"
255255
(cl-format nil "~:(~A~)" "pipe 13a, foo16c") "Pipe 13a, Foo16c"
256+
(cl-format nil "~:(~A~)" nil) "Nil"
257+
(cl-format nil "~:(~A~)" "") ""
256258
)
257259

258260
(simple-tests square-bracket-tests

0 commit comments

Comments
 (0)