Function: org-babel--script-escape-inner
org-babel--script-escape-inner is a byte-compiled function defined in
ob-core.el.gz.
Signature
(org-babel--script-escape-inner STR)
Source Code
;; Defined in /usr/src/emacs/lisp/org/ob-core.el.gz
(defun org-babel--script-escape-inner (str)
(let (in-single in-double backslash out)
(mapc
(lambda (ch)
(setq
out
(if backslash
(progn
(setq backslash nil)
(cond
((and in-single (eq ch ?'))
;; Escaped single quote inside single quoted string:
;; emit just a single quote, since we've changed the
;; outer quotes to double.
(cons ch out))
((eq ch ?\")
;; Escaped double quote
(if in-single
;; This should be interpreted as backslash+quote,
;; not an escape. Emit a three backslashes
;; followed by a quote (because one layer of
;; quoting will be stripped by `org-babel-read').
(append (list ch ?\\ ?\\ ?\\) out)
;; Otherwise we are in a double-quoted string. Emit
;; a single escaped quote
(append (list ch ?\\) out)))
((eq ch ?\\)
;; Escaped backslash: emit a single escaped backslash
(append (list ?\\ ?\\) out))
;; Other: emit a quoted backslash followed by whatever
;; the character was (because one layer of quoting will
;; be stripped by `org-babel-read').
(t (append (list ch ?\\ ?\\) out))))
(cl-case ch
(?\[ (if (or in-double in-single)
(cons ?\[ out)
(cons ?\( out)))
(?\] (if (or in-double in-single)
(cons ?\] out)
(cons ?\) out)))
(?\{ (if (or in-double in-single)
(cons ?\{ out)
(cons ?\( out)))
(?\} (if (or in-double in-single)
(cons ?\} out)
(cons ?\) out)))
(?, (if (or in-double in-single)
(cons ?, out) (cons ?\s out)))
(?\' (if in-double
(cons ?\' out)
(setq in-single (not in-single)) (cons ?\" out)))
(?\" (if in-single
(append (list ?\" ?\\) out)
(setq in-double (not in-double)) (cons ?\" out)))
(?\\ (unless (or in-single in-double)
(error "Can't handle backslash outside string in `org-babel-script-escape'"))
(setq backslash t)
out)
(t (cons ch out))))))
(string-to-list str))
(when (or in-single in-double)
(error "Unterminated string in `org-babel-script-escape'"))
(apply #'string (reverse out))))