Skip to content

Commit 51b141e

Browse files
committed
fmt: simplify parse_type
1 parent 0a17ab2 commit 51b141e

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

src/libcore/extfmt.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -310,34 +310,23 @@ pub mod ct {
310310
pub fn parse_type(s: &str, i: uint, lim: uint, err: ErrorFn) ->
311311
Parsed<Ty> {
312312
if i >= lim { err(~"missing type in conversion"); }
313-
let tstr = str::slice(s, i, i+1u);
314313
// FIXME (#2249): Do we really want two signed types here?
315314
// How important is it to be printf compatible?
316-
let t =
317-
if tstr == ~"b" {
318-
TyBool
319-
} else if tstr == ~"s" {
320-
TyStr
321-
} else if tstr == ~"c" {
322-
TyChar
323-
} else if tstr == ~"d" || tstr == ~"i" {
324-
TyInt(Signed)
325-
} else if tstr == ~"u" {
326-
TyInt(Unsigned)
327-
} else if tstr == ~"x" {
328-
TyHex(CaseLower)
329-
} else if tstr == ~"X" {
330-
TyHex(CaseUpper)
331-
} else if tstr == ~"t" {
332-
TyBits
333-
} else if tstr == ~"o" {
334-
TyOctal
335-
} else if tstr == ~"f" {
336-
TyFloat
337-
} else if tstr == ~"?" {
338-
TyPoly
339-
} else { err(~"unknown type in conversion: " + tstr) };
340-
return Parsed::new(t, i + 1u);
315+
let t = match s[i] {
316+
'b' as u8 => TyBool,
317+
's' as u8 => TyStr,
318+
'c' as u8 => TyChar,
319+
'd' as u8 | 'i' as u8 => TyInt(Signed),
320+
'u' as u8 => TyInt(Unsigned),
321+
'x' as u8 => TyHex(CaseLower),
322+
'X' as u8 => TyHex(CaseUpper),
323+
't' as u8 => TyBits,
324+
'o' as u8 => TyOctal,
325+
'f' as u8 => TyFloat,
326+
'?' as u8 => TyPoly,
327+
_ => err(~"unknown type in conversion: " + s.substr(i, 1))
328+
};
329+
Parsed::new(t, i + 1)
341330
}
342331
}
343332

0 commit comments

Comments
 (0)