diff options
| author | Brian Anderson <[email protected]> | 2011-04-13 20:14:59 -0400 |
|---|---|---|
| committer | Brian Anderson <[email protected]> | 2011-04-13 22:14:24 -0400 |
| commit | 4844e1c08a0f87f8c2bf4ba752630e1af0794a63 (patch) | |
| tree | a7d877e2298ac884441ab73002a48f05e897e7c7 /src/lib/ExtFmt.rs | |
| parent | Move #fmt conversion model into ExtFmt.CT namespace (diff) | |
| download | rust-4844e1c08a0f87f8c2bf4ba752630e1af0794a63.tar.xz rust-4844e1c08a0f87f8c2bf4ba752630e1af0794a63.zip | |
Add support for printing uints as lower-case hex to ExtFmt.
Begin passing an ExtFmt.RT.conv parsed format description to each of the
ExtFmt.RT.conv* functions.
Diffstat (limited to 'src/lib/ExtFmt.rs')
| -rw-r--r-- | src/lib/ExtFmt.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/lib/ExtFmt.rs b/src/lib/ExtFmt.rs index 35b9c5dd..229a0c5d 100644 --- a/src/lib/ExtFmt.rs +++ b/src/lib/ExtFmt.rs @@ -264,15 +264,32 @@ mod CT { // Functions used by the fmt extension at runtime mod RT { - fn conv_int(int i) -> str { + + tag ty { + ty_default; + ty_bits; + ty_hex_upper; + ty_hex_lower; + } + + type conv = rec(ty ty); + + fn conv_int(&conv cv, int i) -> str { ret _int.to_str(i, 10u); } - fn conv_uint(uint u) -> str { - ret _uint.to_str(u, 10u); + fn conv_uint(&conv cv, uint u) -> str { + alt (cv.ty) { + case (ty_default) { + ret _uint.to_str(u, 10u); + } + case (ty_hex_lower) { + ret _uint.to_str(u, 16u); + } + } } - fn conv_bool(bool b) -> str { + fn conv_bool(&conv cv, bool b) -> str { if (b) { ret "true"; } else { @@ -280,7 +297,7 @@ mod RT { } } - fn conv_char(char c) -> str { + fn conv_char(&conv cv, char c) -> str { ret _str.from_char(c); } } |