formatting: use $snippet to make format strings stand out in docs.

db4
John Benediktsson 2012-09-24 09:48:28 -07:00
parent 833fde5671
commit 55a230f368
1 changed files with 63 additions and 59 deletions

View File

@ -6,47 +6,50 @@ IN: formatting
HELP: printf HELP: printf
{ $values { "format-string" string } } { $values { "format-string" string } }
{ $description { $description
"Writes the arguments (specified on the stack) formatted according to the format string.\n" "Writes the arguments (specified on the stack) formatted according to the format string."
$nl $nl
"Several format specifications exist for handling arguments of different types, and " "Several format specifications exist for handling arguments of different types, and "
"specifying attributes for the result string, including such things as maximum width, " "specifying attributes for the result string, including such things as maximum width, "
"padding, and decimals.\n" "padding, and decimals."
$nl
{ $table { $table
{ "%%" "Single %" "" } { { $snippet "%%" } "Single %" "" }
{ "%P.Ds" "String format" "string" } { { $snippet "%P.Ds" } "String format" "string" }
{ "%P.DS" "String format uppercase" "string" } { { $snippet "%P.DS" } "String format uppercase" "string" }
{ "%c" "Character format" "char" } { { $snippet "%c" } "Character format" "char" }
{ "%C" "Character format uppercase" "char" } { { $snippet "%C" } "Character format uppercase" "char" }
{ "%+Pd" "Integer format" "fixnum" } { { $snippet "%+Pd" } "Integer format" "fixnum" }
{ "%+P.De" "Scientific notation" "fixnum, float" } { { $snippet "%+P.De" } "Scientific notation" "fixnum, float" }
{ "%+P.DE" "Scientific notation" "fixnum, float" } { { $snippet "%+P.DE" } "Scientific notation" "fixnum, float" }
{ "%+P.Df" "Fixed format" "fixnum, float" } { { $snippet "%+P.Df" } "Fixed format" "fixnum, float" }
{ "%+Px" "Hexadecimal" "hex" } { { $snippet "%+Px" } "Hexadecimal" "hex" }
{ "%+PX" "Hexadecimal uppercase" "hex" } { { $snippet "%+PX" } "Hexadecimal uppercase" "hex" }
{ "%[%?, %]" "Sequence format" "sequence" } { { $snippet "%[%?, %]" } "Sequence format" "sequence" }
{ "%[%?: %? %]" "Assocs format" "assocs" } { { $snippet "%[%?: %? %]" } "Assocs format" "assocs" }
} }
$nl $nl
"A plus sign ('+') is used to optionally specify that the number should be " "A plus sign (" { $snippet "+" } ") is used to optionally specify that the number should be "
"formatted with a '+' preceeding it if positive.\n" "formatted with a " { $snippet "+" } " preceeding it if positive."
$nl $nl
"Padding ('P') is used to optionally specify the minimum width of the result " "Padding (" { $snippet "P" } ") is used to optionally specify the minimum width of the result "
"string, the padding character, and the alignment. By default, the padding " "string, the padding character, and the alignment. By default, the padding "
"character defaults to a space and the alignment defaults to right-aligned. " "character defaults to a space and the alignment defaults to right-aligned. "
"For example:\n" "For example:"
$nl
{ $list { $list
"\"%5s\" formats a string padding with spaces up to 5 characters wide." { { $snippet "%5s" } " formats a string padding with spaces up to 5 characters wide." }
"\"%03d\" formats an integer padding with zeros up to 3 characters wide." { { $snippet "%03d" } " formats an integer padding with zeros up to 3 characters wide." }
"\"%'#5f\" formats a float padding with '#' up to 3 characters wide." { { $snippet "%'#5f" } " formats a float padding with " { $snippet "#" } " up to 3 characters wide." }
"\"%-10d\" formats an integer to 10 characters wide and left-aligns." { { $snippet "%-10d" } " formats an integer to 10 characters wide and left-aligns." }
} }
$nl $nl
"Digits ('D') is used to optionally specify the maximum digits in the result " "Digits (" { $snippet "D" } ") is used to optionally specify the maximum digits in the result "
"string. For example:\n" "string. For example:"
$nl
{ $list { $list
"\"%.3s\" formats a string to truncate at 3 characters (from the left)." { { $snippet "%.3s" } " formats a string to truncate at 3 characters (from the left)." }
"\"%.10f\" formats a float to pad-tail with zeros up to 10 digits beyond the decimal point." { { $snippet "%.10f" } " formats a float to pad-tail with zeros up to 10 digits beyond the decimal point." }
"\"%.5E\" formats a float into scientific notation with zeros up to 5 digits beyond the decimal point, but before the exponent." { { $snippet "%.5E" } " formats a float into scientific notation with zeros up to 5 digits beyond the decimal point, but before the exponent." }
} }
} }
{ $examples { $examples
@ -88,32 +91,33 @@ HELP: sprintf
HELP: strftime HELP: strftime
{ $values { "format-string" string } } { $values { "format-string" string } }
{ $description { $description
"Writes the timestamp (specified on the stack) formatted according to the format string.\n" "Writes the timestamp (specified on the stack) formatted according to the format string."
$nl
"Different attributes of the timestamp can be retrieved using format specifications."
$nl $nl
"Different attributes of the timestamp can be retrieved using format specifications.\n"
{ $table { $table
{ "%a" "Abbreviated weekday name." } { { $snippet "%a" } "Abbreviated weekday name." }
{ "%A" "Full weekday name." } { { $snippet "%A" } "Full weekday name." }
{ "%b" "Abbreviated month name." } { { $snippet "%b" } "Abbreviated month name." }
{ "%B" "Full month name." } { { $snippet "%B" } "Full month name." }
{ "%c" "Date and time representation." } { { $snippet "%c" } "Date and time representation." }
{ "%d" "Day of the month as a decimal number [01,31]." } { { $snippet "%d" } "Day of the month as a decimal number [01,31]." }
{ "%H" "Hour (24-hour clock) as a decimal number [00,23]." } { { $snippet "%H" } "Hour (24-hour clock) as a decimal number [00,23]." }
{ "%I" "Hour (12-hour clock) as a decimal number [01,12]." } { { $snippet "%I" } "Hour (12-hour clock) as a decimal number [01,12]." }
{ "%j" "Day of the year as a decimal number [001,366]." } { { $snippet "%j" } "Day of the year as a decimal number [001,366]." }
{ "%m" "Month as a decimal number [01,12]." } { { $snippet "%m" } "Month as a decimal number [01,12]." }
{ "%M" "Minute as a decimal number [00,59]." } { { $snippet "%M" } "Minute as a decimal number [00,59]." }
{ "%p" "Either AM or PM." } { { $snippet "%p" } "Either AM or PM." }
{ "%S" "Second as a decimal number [00,59]." } { { $snippet "%S" } "Second as a decimal number [00,59]." }
{ "%U" "Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]." } { { $snippet "%U" } "Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]." }
{ "%w" "Weekday as a decimal number [0(Sunday),6]." } { { $snippet "%w" } "Weekday as a decimal number [0(Sunday),6]." }
{ "%W" "Week number of the year (Monday as the first day of the week) as a decimal number [00,53]." } { { $snippet "%W" } "Week number of the year (Monday as the first day of the week) as a decimal number [00,53]." }
{ "%x" "Date representation." } { { $snippet "%x" } "Date representation." }
{ "%X" "Time representation." } { { $snippet "%X" } "Time representation." }
{ "%y" "Year without century as a decimal number [00,99]." } { { $snippet "%y" } "Year without century as a decimal number [00,99]." }
{ "%Y" "Year with century as a decimal number." } { { $snippet "%Y" } "Year with century as a decimal number." }
{ "%Z" "Time zone name (no characters if no time zone exists)." } { { $snippet "%Z" } "Time zone name (no characters if no time zone exists)." }
{ "%%" "A literal '%' character." } { { $snippet "%%" } "A literal '%' character." }
} }
} }
{ $examples { $examples