Skip to content

Commit 25e4945

Browse files
bostonouswannodette
authored andcommitted
CLJS-1291: pprint whitespace/letter checks are incomplete
Use Google Closure fns instead of incomplete fns for testing whitespace and isLetter.
1 parent f75da4e commit 25e4945

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/main/cljs/cljs/pprint.cljs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
defdirectives formatter-out]])
1515
(:require
1616
[cljs.core :refer [IWriter IDeref]]
17-
[clojure.string :as string])
17+
[clojure.string :as string]
18+
[goog.string :as gstring])
1819
(:import [goog.string StringBuffer]))
1920

2021
(def ^:dynamic *out* nil)
@@ -1956,19 +1957,12 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm"
19561957
;;TODO need to enforce integers only?
19571958
(-write writer (string/upper-case (char c))))))))
19581959

1959-
;;TODO: This is an oversimplied version. Needs to be fully implemented
1960-
(defn- is-letter? [s]
1961-
(boolean
1962-
(#{"A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
1963-
"a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"}
1964-
s)))
1965-
19661960
(defn- capitalize-string
19671961
"Capitalizes the words in a string. If first? is false, don't capitalize the
19681962
first character of the string even if it's a letter."
19691963
[s first?]
19701964
(let [f (first s)
1971-
s (if (and first? f (is-letter? f))
1965+
s (if (and first? f (gstring/isUnicodeChar f))
19721966
(str (string/upper-case f) (subs s 1))
19731967
s)]
19741968
(apply str
@@ -1986,11 +1980,6 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm"
19861980
[s nil]))))
19871981
s)))))
19881982

1989-
;;TODO: This is an oversimplied version. Needs to be fully implemented
1990-
(defn- is-whitespace? [s]
1991-
(boolean
1992-
(#{\space \newline} s)))
1993-
19941983
(defn- capitalize-word-writer
19951984
"Returns a proxy that wraps writer, capitalizing all words"
19961985
[writer]
@@ -2009,13 +1998,13 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm"
20091998
(-write writer
20101999
(capitalize-string (.toLowerCase s) @last-was-whitespace?))
20112000
(when (pos? (.-length s))
2012-
(reset! last-was-whitespace? (is-whitespace? (nth s (dec (count s)))))))
2001+
(reset! last-was-whitespace? (gstring/isEmptyOrWhitespace (nth s (dec (count s)))))))
20132002

20142003
js/Number
20152004
(let [c (char x)]
20162005
(let [mod-c (if @last-was-whitespace? (string/upper-case c) c)]
20172006
(-write writer mod-c)
2018-
(reset! last-was-whitespace? (is-whitespace? c)))))))))
2007+
(reset! last-was-whitespace? (gstring/isEmptyOrWhitespace c)))))))))
20192008

20202009
(defn- init-cap-writer
20212010
"Returns a proxy that wraps writer, capitalizing the first word"
@@ -2046,7 +2035,7 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm"
20462035

20472036
js/Number
20482037
(let [c (char x)]
2049-
(if (and (not @capped) (is-letter? c))
2038+
(if (and (not @capped) (gstring/isUnicodeChar c))
20502039
(do
20512040
(reset! capped true)
20522041
(-write writer (string/upper-case c)))

0 commit comments

Comments
 (0)