From 4844e1c08a0f87f8c2bf4ba752630e1af0794a63 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 13 Apr 2011 20:14:59 -0400 Subject: 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. --- src/lib/ExtFmt.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/lib') 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); } } -- cgit v1.2.3