Fork me on GitHub
#off-topic
<
2019-03-02
>
vemv10:03:17

Anyone has a snippet that will unescape a redundantly-escaped string? (I don't mind the lang) e.g the specimen contains "\\\n" rather than "\n", and "\\\"" rather than "\"" I rolled my own, works fine except if the specimen contains literally \n (i.e. not a newline: but a \ followed by the letter n)

qythium12:03:09

here's somewhat of a hack:

(defn unescape [s]
  (read-string (format "\"%s\"" s)))

vemv13:03:56

🙌 will try and let you know

vemv14:03:10

ace, works like a charm and passes the "literal \n" test thanks!

souenzzo21:03:48

try to read something like "#=(prn :hello)" Then use edn/read-string

qythium04:03:41

good point, read-string shouldn't be used on untrusted input - however the above doesn't result in (prn :hello) being evaluated for me since the reader only reads a single form "" and stops there

vlaaad16:03:40

Can't wait for new inside clojure post...

alexmiller17:03:22

I should probably go write it :)