]> gitweb.factorcode.org Git - factor.git/commitdiff
formatting: new format specifier for unparsed representation
authorBjörn Lindqvist <bjourne@gmail.com>
Mon, 10 Feb 2014 01:52:15 +0000 (02:52 +0100)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 10 Feb 2014 05:09:24 +0000 (21:09 -0800)
basis/formatting/formatting-docs.factor
basis/formatting/formatting.factor

index 314db3618317d7f51181d2aa9a1456505e67e25e..1030b2212a932cdc13e69cc58ac72d334854a971 100755 (executable)
@@ -6,7 +6,7 @@ IN: formatting
 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, "
@@ -16,8 +16,9 @@ HELP: printf
         { { $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" }
@@ -81,11 +82,15 @@ 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
 { $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
@@ -136,5 +141,3 @@ ARTICLE: "formatting" "Formatted printing"
 } ;
 
 ABOUT: "formatting"
-
-
index c2169bac2beb38e715375f352f64ad708f8f593c..030e9f4ed111e50f25650b950de1d84694c52ada 100644 (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