From 7e833c6aa927d9cb4222c215aa0369b2cbfbf4e8 Mon Sep 17 00:00:00 2001 From: Adlai Chandrasekhar Date: Sat, 24 Oct 2009 09:07:13 +0200 Subject: [PATCH] Added left trim option for format-expand strings --- primitives.lisp | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-) diff --git a/primitives.lisp b/primitives.lisp index 4fd7e41..b0f9224 100644 --- a/primitives.lisp +++ b/primitives.lisp @@ -706,9 +706,11 @@ do: (setf cur (cdr cur)) (let* ((tmp (loop while (and cur (char<= #\0 (car cur) #\9)) collect (pop cur))) - (len (and tmp (parse-integer (coerce tmp 'string))))) + (len (and tmp (parse-integer (coerce tmp 'string)))) + ;; So that eg "%25^t" will trim from the left + (from-left-p (when (char= #\^ (car cur)) (pop cur)))) (if (null cur) - (format t "%~a" len) + (format t "address@hidden" len from-end-p) (let* ((fmt (cadr (assoc (car cur) fmt-alist :test 'char=))) (str (cond (fmt ;; it can return any type, not jut as string. @@ -718,9 +720,12 @@ do: (t (concatenate 'string (string #\%) (string (car cur))))))) ;; crop string if needed - (setf output (concatenate 'string output (if len - (subseq str 0 (min len (length str))) - str))) + (setf output (concatenate 'string output + (cond ((null len) str) + ((not from-left-p) ; Default behavior + (subseq str 0 (min len (length str)))) + ;; New behavior -- trim from the left + (t (subseq str (max 0 (- (length str) len))))))) (setf cur (cdr cur)))))) (t (setf output (concatenate 'string output (string (car cur))) -- 1.6.5.1