Skip to content

Commit

Permalink
Add stream argument to WRITE-* invocations in ENCODE methods. Next ti…
Browse files Browse the repository at this point in the history
…me, I'll go for "patch" instead of doing patches received by hand. Thanks to Nathan Froyd for patiently reporting ;).
  • Loading branch information
hanshuebner committed Jan 26, 2009
1 parent 88d10cd commit 8160819
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions encode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
#\Tab "\\t")))

(defmethod encode ((string string) &optional (stream *standard-output*))
(write-char #\")
(write-char #\" stream)
(dotimes (i (length string))
(let* ((char (aref string i))
(replacement (gethash char *char-replacements*)))
(if replacement
(write-string replacement)
(write-char char))))
(write-char #\")
(write-string replacement stream)
(write-char char stream))))
(write-char #\" stream)
string)

(defmethod encode ((object rational) &optional (stream *standard-output*))
Expand All @@ -53,41 +53,41 @@
(princ object stream))

(defmethod encode ((object hash-table) &optional (stream *standard-output*))
(write-char #\{)
(write-char #\{ stream)
(let (printed)
(maphash (lambda (key value)
(if printed
(write-char #\,)
(write-char #\, stream)
(setf printed t))
(encode key stream)
(write-char #\:)
(write-char #\: stream)
(encode value stream))
object))
(write-char #\})
(write-char #\} stream)
object)

(defmethod encode ((object vector) &optional (stream *standard-output*))
(write-char #\[)
(write-char #\[ stream)
(let (printed)
(loop
for value across object
do
(when printed
(write-char #\,))
(write-char #\, stream))
(setf printed t)
(encode value stream)))
(write-char #\])
(write-char #\] stream)
object)

(defmethod encode ((object list) &optional (stream *standard-output*))
(write-char #\[)
(write-char #\[ stream)
(let (printed)
(dolist (value object)
(if printed
(write-char #\,)
(write-char #\, stream)
(setf printed t))
(encode value stream)))
(write-char #\])
(write-char #\] stream)
object)

(defmethod encode ((object (eql 'true)) &optional (stream *standard-output*))
Expand Down

0 comments on commit 8160819

Please sign in to comment.