PageRenderTime 6ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/cl-json-patches.lisp

http://github.com/mtravers/wuwei
Lisp | 38 lines | 18 code | 8 blank | 12 comment | 0 complexity | c15ca2938ef3cc08636d1d133f7906dd MD5 | raw file
 1(in-package :json)
 2
 3#|
 4Extensions to cl-json/src/encoder.lisp
 5
 6New features, for encoding functions:
 7:empty-list ==> "[]"
 8:empty-dict ==> "{}"
 9(:raw "function(foo) ...") ==>
10  produces unquoted string for javascript
11
12TODO:  make these work in the decoding direction
13|#
14
15(#+:ALLEGRO excl:without-redefinition-warnings #-:ALLEGRO progn
16
17;;; changed to compatible with cl-json 0.4 -- will break in earlier versions
18(defmethod encode-json ((s (eql :empty-dict)) &optional (stream *json-output*))
19  (write-string "{}" stream))
20
21(defmethod encode-json ((s (eql :empty-list)) &optional (stream *json-output*))
22  (write-string "[]" stream))
23
24(defmethod encode-json ((s list) &optional (stream *json-output*))
25  (cond ((eq (car s) :raw)			
26	 (write-string (cadr s) stream))
27	((alistp s)
28	 (encode-json-alist s stream))
29	(t (call-next-method s stream))))
30
31(defun alistp (l)
32  (dolist (elt l t)
33    (unless (and (consp elt)
34		 (typep (car elt) '(or symbol string)))
35      (return-from alistp nil))))
36
37
38);excl:without-redefinition-warnings