Format package¶
The Format package provides support for formatting strings. It can be used to set things like width, padding and alignment, as well as controlling the way numbers are displayed (decimal, octal, hexadecimal).
Example program¶
use "format"
actor Main
fun disp(desc: String, v: I32, fmt: FormatInt = FormatDefault): String =>
Format(desc where width = 10)
+ ":"
+ Format.int[I32](v where width = 10, align = AlignRight, fmt = fmt)
new create(env: Env) =>
try
(let x, let y) = (env.args(1)?.i32()?, env.args(2)?.i32()?)
env.out.print(disp("x", x))
env.out.print(disp("y", y))
env.out.print(disp("hex(x)", x, FormatHex))
env.out.print(disp("hex(y)", y, FormatHex))
env.out.print(disp("x * y", x * y))
else
let exe = try env.args(0)? else "fmt_example" end
env.err.print("Usage: " + exe + " NUMBER1 NUMBER2")
end
Public Types¶
- type Align
- primitive AlignCenter
- primitive AlignLeft
- primitive AlignRight
- primitive Format
- primitive FormatBinary
- primitive FormatBinaryBare
- primitive FormatDefault
- primitive FormatExp
- primitive FormatExpLarge
- primitive FormatFix
- primitive FormatFixLarge
- type FormatFloat
- primitive FormatGeneral
- primitive FormatGeneralLarge
- primitive FormatHex
- primitive FormatHexBare
- primitive FormatHexSmall
- primitive FormatHexSmallBare
- type FormatInt
- primitive FormatOctal
- primitive FormatOctalBare
- trait FormatSpec
- primitive FormatUTF32
- primitive PrefixDefault
- type PrefixNumber
- primitive PrefixSign
- primitive PrefixSpace
- trait PrefixSpec