diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:26 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2017-02-20 00:05:26 -0800 |
commit | f24b9140d6f74804d5599ec225717d38ca443813 (patch) | |
tree | 0da952f1a5a7c0eacfc05c296766523e32c05fe2 /printf.scm | |
parent | 8ffbc2df0fde83082610149d24e594c1cd879f4a (diff) | |
download | slib-f24b9140d6f74804d5599ec225717d38ca443813.tar.gz slib-f24b9140d6f74804d5599ec225717d38ca443813.zip |
Import Upstream version 2c0upstream/2c0
Diffstat (limited to 'printf.scm')
-rw-r--r-- | printf.scm | 25 |
1 files changed, 10 insertions, 15 deletions
@@ -56,7 +56,7 @@ (case fc ((#\n #\N) (out #\newline)) ((#\t #\T) (out slib:tab)) - ((#\r #\R) (out #\return)) + ;;((#\r #\R) (out #\return)) ((#\f #\F) (out slib:form-feed)) ((#\newline) #f) (else (out fc))) @@ -85,8 +85,12 @@ (string->number (string c))))) ((not (char-numeric? fc)) accum) (must-advance))))))) - (define integer-pad + (define integer-convert (lambda (s radix) + (set! s (cond ((symbol? s) (symbol->string s)) + ((number? s) (number->string s radix)) + ((or (not s) (null? s)) "0") + (else "1"))) (cond ((not (negative? precision)) (set! leading-0s #f))) (let* ((pre @@ -216,24 +220,15 @@ (out (make-string (- width (string-length os)) #\ )) (out os)))) (loop (cdr args))) - ((#\d #\D #\i #\I #\u #\U) - (out (integer-pad - (cond ((symbol? (car args)) - (symbol->string (car args))) - ((number? (car args)) - (number->string (car args))) - ((not (car args)) "0") - (else "1")) - 10)) + (out (integer-convert (car args) 10)) (loop (cdr args))) ((#\o #\O) - (out (integer-pad (number->string (car args) 8) 8)) + (out (integer-convert (car args) 8)) (loop (cdr args))) ((#\x #\X) - (out - ((if (char-upper-case? fc) string-upcase string-downcase) - (integer-pad (number->string (car args) 16) 16))) + (out ((if (char-upper-case? fc) string-upcase string-downcase) + (integer-convert (car args) 16))) (loop (cdr args))) ((#\%) (out #\%) (loop args)) |