From: John Benediktsson Date: Sat, 18 Apr 2015 00:50:00 +0000 (-0700) Subject: formatting: support space prefix for numbers. X-Git-Tag: unmaintained~2892 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=50725002be0baa6c942a63f16dd290a018407522 formatting: support space prefix for numbers. --- diff --git a/basis/formatting/formatting-tests.factor b/basis/formatting/formatting-tests.factor index a5a463ff04..92b28650cc 100755 --- a/basis/formatting/formatting-tests.factor +++ b/basis/formatting/formatting-tests.factor @@ -11,6 +11,8 @@ IN: formatting.tests [ "10" ] [ 10 "%d" sprintf ] unit-test [ "+10" ] [ 10 "%+d" sprintf ] unit-test [ "-10" ] [ -10 "%d" sprintf ] unit-test +[ " 23" ] [ 23 "% d" sprintf ] unit-test +[ "-23" ] [ -23 "% d" sprintf ] unit-test [ " -10" ] [ -10 "%5d" sprintf ] unit-test [ "-0010" ] [ -10 "%05d" sprintf ] unit-test [ "+0010" ] [ 10 "%+05d" sprintf ] unit-test diff --git a/basis/formatting/formatting.factor b/basis/formatting/formatting.factor index aa7d6c0f80..69d8f544e2 100644 --- a/basis/formatting/formatting.factor +++ b/basis/formatting/formatting.factor @@ -48,7 +48,8 @@ pad-align = ("-")? => [[ \ pad-tail \ pad-head ? ]] pad-width = ([0-9])* => [[ >digits ]] pad = pad-align pad-char pad-width => [[ >quotation dup first 0 = [ drop [ ] ] when ]] -sign = ("+")? => [[ [ dup CHAR: - swap index [ "+" prepend ] unless ] [ ] ? ]] +sign_ = [+ ] => [[ '[ dup CHAR: - swap index [ _ prefix ] unless ] ]] +sign = (sign_)? => [[ [ ] or ]] width_ = "." ([0-9])* => [[ second >digits '[ _ short head ] ]] width = (width_)? => [[ [ ] or ]]