(mystery-function "a neat\nstring\"")
=> "\"a neat \\nstring\\\""
This question was asked on freenode#emacs
by user dropdrive
. How could I write (or use) a function that takes a string literal and returns the string literal that, when read
, would return the original string? That is,
(let ((s (any-string)))
(should (equal s (read (mystery-function s)))))
Note that this let
-form is a bit misleading – the session at the very top of this question should be used for testing. Sorry for any confusion!