From 51b141e3e499558ddfece1f00dd6714f442c2404 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Mon, 7 Jan 2013 14:36:46 -0500 Subject: [PATCH] fmt: simplify parse_type --- src/libcore/extfmt.rs | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 98cd9910f50..3cc7e2458b2 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -310,34 +310,23 @@ pub mod ct { pub fn parse_type(s: &str, i: uint, lim: uint, err: ErrorFn) -> Parsed { if i >= lim { err(~"missing type in conversion"); } - let tstr = str::slice(s, i, i+1u); // FIXME (#2249): Do we really want two signed types here? // How important is it to be printf compatible? - let t = - if tstr == ~"b" { - TyBool - } else if tstr == ~"s" { - TyStr - } else if tstr == ~"c" { - TyChar - } else if tstr == ~"d" || tstr == ~"i" { - TyInt(Signed) - } else if tstr == ~"u" { - TyInt(Unsigned) - } else if tstr == ~"x" { - TyHex(CaseLower) - } else if tstr == ~"X" { - TyHex(CaseUpper) - } else if tstr == ~"t" { - TyBits - } else if tstr == ~"o" { - TyOctal - } else if tstr == ~"f" { - TyFloat - } else if tstr == ~"?" { - TyPoly - } else { err(~"unknown type in conversion: " + tstr) }; - return Parsed::new(t, i + 1u); + let t = match s[i] { + 'b' as u8 => TyBool, + 's' as u8 => TyStr, + 'c' as u8 => TyChar, + 'd' as u8 | 'i' as u8 => TyInt(Signed), + 'u' as u8 => TyInt(Unsigned), + 'x' as u8 => TyHex(CaseLower), + 'X' as u8 => TyHex(CaseUpper), + 't' as u8 => TyBits, + 'o' as u8 => TyOctal, + 'f' as u8 => TyFloat, + '?' as u8 => TyPoly, + _ => err(~"unknown type in conversion: " + s.substr(i, 1)) + }; + Parsed::new(t, i + 1) } }