formatting: new format specifier for unparsed representation

db4
Björn Lindqvist 2014-02-10 02:52:15 +01:00 committed by John Benediktsson
parent c9badc9dd9
commit a82dc84f2d
2 changed files with 13 additions and 9 deletions

View File

@ -16,6 +16,7 @@ HELP: printf
{ { $snippet "%%" } "Single %" "" }
{ { $snippet "%P.Ds" } "String format" "string" }
{ { $snippet "%P.DS" } "String format uppercase" "string" }
{ { $snippet "%P.Du" } "Unparsed format" "object" }
{ { $snippet "%c" } "Character format" "char" }
{ { $snippet "%C" } "Character format uppercase" "char" }
{ { $snippet "%+Pd" } "Integer format" "fixnum" }
@ -81,6 +82,10 @@ HELP: printf
"USING: formatting ;"
"H{ { 1 2 } { 3 4 } } \"%[%d: %d %]\" printf"
"{ 1:2, 3:4 }" }
{ $example
"USING: calendar formatting ;"
"3 years \"%u\" printf"
"T{ duration { year 3 } }" }
} ;
HELP: sprintf
@ -136,5 +141,3 @@ ARTICLE: "formatting" "Formatted printing"
} ;
ABOUT: "formatting"

View File

@ -2,8 +2,8 @@
! See http://factorcode.org/license.txt for BSD license
USING: accessors arrays assocs calendar combinators fry kernel
generalizations io io.streams.string macros math math.functions
math.parser peg.ebnf quotations sequences splitting strings
unicode.categories unicode.case vectors combinators.smart
math.parser peg.ebnf prettyprint quotations sequences splitting
strings unicode.categories unicode.case vectors combinators.smart
present ;
FROM: math.parser.private => format-float ;
IN: formatting
@ -61,6 +61,7 @@ fmt-c = "c" => [[ [ 1string ] ]]
fmt-C = "C" => [[ [ 1string >upper ] ]]
fmt-s = "s" => [[ [ present ] ]]
fmt-S = "S" => [[ [ present >upper ] ]]
fmt-u = "u" => [[ [ unparse ] ]]
fmt-d = "d" => [[ [ >integer number>string ] ]]
fmt-e = digits "e" => [[ first '[ _ format-scientific ] ]]
fmt-E = digits "E" => [[ first '[ _ format-scientific >upper ] ]]
@ -69,7 +70,7 @@ fmt-x = "x" => [[ [ >hex ] ]]
fmt-X = "X" => [[ [ >hex >upper ] ]]
unknown = (.)* => [[ unknown-printf-directive ]]
strings_ = fmt-c|fmt-C|fmt-s|fmt-S
strings_ = fmt-c|fmt-C|fmt-s|fmt-S|fmt-u
strings = pad width strings_ => [[ <reversed> compose-all ]]
numbers_ = fmt-d|fmt-e|fmt-E|fmt-f|fmt-x|fmt-X