From ec012f9c63e6cf51771c250a10e15ff56250f9ea Mon Sep 17 00:00:00 2001 From: Raimon Grau Date: Fri, 26 Apr 2013 02:31:13 +0200 Subject: [PATCH] format supports ~% --- src/print.lisp | 53 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/src/print.lisp b/src/print.lisp index f4cd1bb..428b044 100644 --- a/src/print.lisp +++ b/src/print.lisp @@ -70,32 +70,31 @@ (write-line (prin1-to-string x)) x) -#+jscl -(progn - (defun format (destination fmt &rest args) - (let ((len (length fmt)) - (i 0) - (res "") - (arguments args)) - (cl:%while (< i len) - (let ((c (char fmt i))) - (if (char= c #\~) - (let ((next (char fmt (incf i)))) - (if (char= next #\~) - (progn (setq res (cl:concat res "~")) - (incf i)) - (progn - (format-special next (car arguments)) - (setq arguments (cdr arguments))))) - (progn - (setq res (cl:concat res (cl:char-to-string c))))) - (incf i))) - (if destination - (progn - (write-string res) - nil) - res))) +(defun format (destination fmt &rest args) + (let ((len (length fmt)) + (i 0) + (res "") + (arguments args)) + (while (< i len) + (let ((c (char fmt i))) + (if (char= c #\~) + (let ((next (char fmt (incf i)))) + (cond + ((char= next #\~) + (setq res (concat res "~"))) + ((char= next #\%) + (setq res (concat res *newline*))) + (t + (format-special next (car arguments)) + (setq arguments (cdr arguments))))) + (setq res (concat res (char-to-string c)))) + (incf i))) + (if destination + (progn + (write-string res) + nil) + res))) - (defun format-special (chr arg) - chr)) + (defun format-special (chr arg) + chr)) -- 1.7.10.4