formatting: support space prefix for numbers.
parent
b0ba4a5925
commit
50725002be
|
@ -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
|
[ "+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
|
[ " -10" ] [ -10 "%5d" sprintf ] unit-test
|
||||||
[ "-0010" ] [ -10 "%05d" sprintf ] unit-test
|
[ "-0010" ] [ -10 "%05d" sprintf ] unit-test
|
||||||
[ "+0010" ] [ 10 "%+05d" sprintf ] unit-test
|
[ "+0010" ] [ 10 "%+05d" sprintf ] unit-test
|
||||||
|
|
|
@ -48,7 +48,8 @@ pad-align = ("-")? => [[ \ pad-tail \ pad-head ? ]]
|
||||||
pad-width = ([0-9])* => [[ >digits ]]
|
pad-width = ([0-9])* => [[ >digits ]]
|
||||||
pad = pad-align pad-char pad-width => [[ <reversed> >quotation dup first 0 = [ drop [ ] ] when ]]
|
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_ = "." ([0-9])* => [[ second >digits '[ _ short head ] ]]
|
||||||
width = (width_)? => [[ [ ] or ]]
|
width = (width_)? => [[ [ ] or ]]
|
||||||
|
|
Loading…
Reference in New Issue