HELP: printf
{ $values { "format-string" string } }
{ $description
- "Writes the arguments (specified on the stack) formatted according to the format string."
+ "Writes the arguments (specified on the stack) formatted according to the format string."
$nl
"Several format specifications exist for handling arguments of different types, and "
"specifying attributes for the result string, including such things as maximum width, "
{ { $snippet "%%" } "Single %" "" }
{ { $snippet "%P.Ds" } "String format" "string" }
{ { $snippet "%P.DS" } "String format uppercase" "string" }
- { { $snippet "%c" } "Character format" "char" }
- { { $snippet "%C" } "Character format uppercase" "char" }
+ { { $snippet "%P.Du" } "Unparsed format" "object" }
+ { { $snippet "%c" } "Character format" "char" }
+ { { $snippet "%C" } "Character format uppercase" "char" }
{ { $snippet "%+Pd" } "Integer format" "fixnum" }
{ { $snippet "%+P.De" } "Scientific notation" "fixnum, float" }
{ { $snippet "%+P.DE" } "Scientific notation" "fixnum, float" }
"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
{ $values { "format-string" string } { "result" string } }
-{ $description "Returns the arguments (specified on the stack) formatted according to the format string as a result string." }
+{ $description "Returns the arguments (specified on the stack) formatted according to the format string as a result string." }
{ $see-also printf } ;
HELP: strftime
} ;
ABOUT: "formatting"
-
-
! 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
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 ] ]]
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