]> gitweb.factorcode.org Git - factor.git/commitdiff
formatting: support space prefix for numbers.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 18 Apr 2015 00:50:00 +0000 (17:50 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 18 Apr 2015 00:50:00 +0000 (17:50 -0700)
basis/formatting/formatting-tests.factor
basis/formatting/formatting.factor

index a5a463ff04f67f60eb3d0506151aebaf186495a3..92b28650cc99568c8bf06f0aa6bd9fe9c3f1e80e 100755 (executable)
@@ -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
index aa7d6c0f8012c85445cf700c8a9bbe1c1ab7da05..69d8f544e2dd24bd1490201e0fe899b611d5360b 100644 (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 ]]