module RemiLib::Format
Overview
The RemiLib::Format
module contains alternate methods to format strings with
various arguments. Unlike printf
/sprintf
, the format strings for this
module are based on those for Common Lisp's FORMAT
function.
Note that not all of the directives from Common Lisp are supported. These are currently implemented:
~a
: Same asto_s
~s
: Same asto_s
, except strings are automatically wrapped in double quotes.~d
: Formats an integer in decimal. All modifiers supported.~x
: Formats an integer in hexadecimal. All modifiers supported.~b
: Formats an integer in binary. All modifiers supported.~o
: Formats an integer in octal. All modifiers supported.~r
: Formats an integer in English words usingInt#toSpoken
, orInt#toRoman
if the @ modifier is used. The : modifier is not yet supported.~e
: Only partially supported, currently the same as.to_f.to_s
.~f
: Only partially supported, currently the same as.to_f.to_s
.~g
: Only partially supported, currently the same as.to_f.to_s
.~$
: Only partially supported, currently the same as.to_f.to_s
.~p
: Plural-izes a word. All modifiers supported.~%
: Prints a newline. All modifiers supported.~{
: Iteration. Currently broken.~^
: Used with iteration.~~
: Prints a literal~
. All modifiers supported.~*
: Skips around within the argument list. All modifiers supported.~[
: Conditional formatting. All modifiers except # supported.
Documentation for the original Common Lisp function can be found here: http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm
Defined in:
remilib/format.crClass Method Summary
-
.format(fmtString : String, *args) : String
Formats
fmtString
with the given arguments using aRemiLib::Format::Formatter
, then returns the resulting string. -
.format(io : IO, fmtString : String, *args) : IO
Formats
fmtString
with the given arguments using aRemiLib::Format::Formatter
, then writes the results toio
.
Class Method Detail
Formats fmtString
with the given arguments using a
RemiLib::Format::Formatter
, then returns the resulting string.
Formats fmtString
with the given arguments using a
RemiLib::Format::Formatter
, then writes the results to io
. This returns
the io
.