syntax | since v0.0-1853 | in clojure | in edn | Edit |
A string of characters.
"..."
"single line string"
"multi
line
string"
ClojureScript strings compile to JavaScript strings.
Standard escape characters such as \"
are supported, as well as unicode
escape characters:
unicode characters | constraints |
---|---|
\uXXXX |
XXXX must have 4 digits outside 0xD7FF-0xE000 |
\oXXX |
XXX is octal between 0 and 0377 |
"foo"
;;=> "foo"
"hello
world"
;;=> "hello\n world"
Characters can be escaped:
(println "foo\nbar")
;; prints:
;; foo
;; bar
(defn- read-string*
[reader _ opts pending-forms]
(loop [sb (StringBuilder.)
ch (read-char reader)]
(case ch
nil (err/throw-eof-reading reader :string sb)
\\ (recur (doto sb (.append (escape-char sb reader)))
(read-char reader))
\" (str sb)
(recur (doto sb (.append ch)) (read-char reader)))))
(defn- macros [ch]
(case ch
\" read-string*
\: read-keyword
\; read-comment
\' (wrapping-reader 'quote)
\@ (wrapping-reader 'clojure.core/deref)
\^ read-meta
\` read-syntax-quote ;;(wrapping-reader 'syntax-quote)
\~ read-unquote
\( read-list
\) read-unmatched-delimiter
\[ read-vector
\] read-unmatched-delimiter
\{ read-map
\} read-unmatched-delimiter
\\ read-char*
\% read-arg
\# read-dispatch
nil))