Skip to content

Commit

Permalink
core: Fix for string escapes
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Sep 5, 2024
1 parent ae1e8f2 commit 4d385e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 4 additions & 0 deletions core/src/yamlscript/builder.clj
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@
(-> string
(str/replace #"\\\$" "$")
(str/replace #"\\ " " ")
(str/replace #"\\b" "\b")
(str/replace #"\\f" "\f")
(str/replace #"\\n" "\n")
(str/replace #"\\r" "\r")
(str/replace #"\\t" "\t")
Str))

(defn build-vstr [node]
Expand Down
6 changes: 5 additions & 1 deletion core/src/yamlscript/printer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
(def string-escape
{\\ "\\\\"
\" "\\\""
\newline "\\n"})
\backspace "\\b"
\formfeed "\\f"
\newline "\\n"
\return "\\r"
\tab "\\t"})

(defn pr-string [s]
(str/escape s string-escape))
Expand Down
10 changes: 0 additions & 10 deletions core/src/yamlscript/ysreader.clj
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,6 @@
(let [[form tokens] (read-form tokens)]
(recur tokens (if form (conj list form) list))))))

#_(def unescapes
{"\\\\" "\\"
"\\n" "\n"
"\\t" "\t"
"\\\"" "\""})

#_(defn str-unescape [s]
(str/replace s #"(?:\\\\|\\n|\\t|\\\")"
(fn [m] (get unescapes m))))

;; TODO do in one call
(defn str-unescape [s]
(-> s
Expand Down

0 comments on commit 4d385e8

Please sign in to comment.