formatting: support space prefix for numbers.

db4
John Benediktsson 2015-04-17 17:50:00 -07:00
parent b0ba4a5925
commit 50725002be
2 changed files with 4 additions and 1 deletions

View File

@ -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

View File

@ -48,7 +48,8 @@ pad-align = ("-")? => [[ \ pad-tail \ pad-head ? ]]
pad-width = ([0-9])* => [[ >digits ]]
pad = pad-align pad-char pad-width => [[ <reversed> >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 ]]