Verified Commit cb936db7 authored by Vladimir Sedach's avatar Vladimir Sedach
Browse files

Better output of Unicode strings

parent 8cc921d0
......@@ -158,30 +158,30 @@ vice-versa.")
(newline-and-indent))))
(defparameter *js-lisp-escaped-chars*
'((#\' . #\')
(#\" . #\")
(#\\ . #\\)
(#\b . #\Backspace)
(#\f . #.(code-char 12))
(#\n . #\Newline)
(#\r . #\Return)
(#\t . #\Tab)))
(list #\' #\'
#\" #\"
#\\ #\\
#\Backspace #\b
(code-char 12) #\f
#\Newline #\n
#\Return #\r
#\Tab #\t))
(defmethod ps-print ((char character))
(ps-print (string char)))
(defmethod ps-print ((string string))
(flet ((lisp-special-char-to-js (lisp-char)
(car (rassoc lisp-char *js-lisp-escaped-chars*))))
(psw *js-string-delimiter*)
(loop for char across string
for code = (char-code char)
for special = (lisp-special-char-to-js char)
do (cond (special (psw #\\) (psw special))
((or (<= code #x1f) (>= code #x80))
(format *psw-stream* "\\u~:@(~4,'0x~)" code))
(t (psw char))))
(psw *js-string-delimiter*)))
(psw *js-string-delimiter*)
(loop for char across string do
(acond ((getf *js-lisp-escaped-chars* char)
(psw #\\ it))
((or (<= (char-code char) #x1F)
(<= #x80 (char-code char) #x9F)
(member (char-code char) '(#xA0 #xAD #x200B #x200C)))
(format *psw-stream* "\\u~:@(~4,'0x~)" (char-code char)))
(t
(psw char))))
(psw *js-string-delimiter*))
(defmethod ps-print ((number number))
(format *psw-stream* (if (integerp number) "~D" "~F") number))
......
......@@ -1019,15 +1019,19 @@ return element.innerHTML = ['<textarea', disabled || !authorized ? [' disabled=\
`((#\\ . #\\)
(#\b . #\Backspace)
(#\f . ,(code-char 12))
("u000B" . ,(code-char #x000b)) ; vertical tab
("u000B" . ,(code-char #xB)) ; vertical tab
(#\n . #\Newline)
(#\r . #\Return)
(#\' . #\')
(#\" . #\")
(#\t . #\Tab)
("u001F" . ,(code-char #x001f)) ; character below 32
("u001F" . ,(code-char #x1F)) ; character below 32
("u0080" . ,(code-char 128)) ; character over 127
("uABCD" . ,(code-char #xabcd))))) ; well above ASCII
("u00A0" . ,(code-char 160)) ; non-breaking space
("u00AD" . ,(code-char 173)) ; soft hyphen
("u200B" . ,(code-char #x200B)) ; zero-width space
("u200C" . ,(code-char #x200C)) ; zero-width non-joiner
)))
(loop for (js-escape . lisp-char) in escapes
for generated = (ps-doc* (format nil "hello~ahi" lisp-char))
for wanted = (format nil "'hello\\~ahi';" js-escape)
......@@ -4121,6 +4125,10 @@ function foo(x) {
return { 'abc' : (x = obj['blah'], x ? 123 : 456) };
};")
(test-ps-js unicode-strings
"фоо бар"
"'фоо бар';")
;;; broken
;; (test-ps-js let-defun-toplevel
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment