From bab29af449a200572d04593f6410dc94c1d20263 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 15 Aug 2011 15:45:52 -0700 Subject: [PATCH] Continue migrating the std #fmt interface to ivecs Only thing left is to remove some duplicate interfaces in std::extfmt::rt after the next snapshot --- src/comp/syntax/ext/fmt.rs | 2 +- src/lib/extfmt.rs | 54 ++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs index cc3d4fef52ee..369fc7be0c39 100644 --- a/src/comp/syntax/ext/fmt.rs +++ b/src/comp/syntax/ext/fmt.rs @@ -182,7 +182,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], } fn make_conv_call(cx: &ext_ctxt, sp: span, conv_type: str, cnv: &conv, arg: @ast::expr) -> @ast::expr { - let fname = "conv_" + conv_type + "_ivec"; + let fname = "conv_" + conv_type; let path = make_path_vec(cx, fname); let cnv_expr = make_rt_conv_expr(cx, sp, cnv); let args = ~[cnv_expr, arg]; diff --git a/src/lib/extfmt.rs b/src/lib/extfmt.rs index 13cfda6e1900..25cdc2a46c88 100644 --- a/src/lib/extfmt.rs +++ b/src/lib/extfmt.rs @@ -268,34 +268,26 @@ mod rt { // FIXME: May not want to use a vector here for flags; // instead just use a bool per flag - type conv = {flags: vec[flag], width: count, precision: count, ty: ty}; + type conv = {flags: [flag], width: count, precision: count, ty: ty}; - type conv_ivec = {flags: [flag], width: count, precision: count, ty: ty}; - - fn to_conv_ivec(cv: &conv) -> conv_ivec { - {flags: ivec::from_vec(cv.flags), - width: cv.width, - precision: cv.precision, - ty: cv.ty} + // FIXME: Remove these transitional *_ivec interfaces + fn conv_int_ivec(cv: &conv, i: int) -> str { + conv_int(cv, i) + } + fn conv_uint_ivec(cv: &conv, u: uint) -> str { + conv_uint(cv, u) + } + fn conv_bool_ivec(cv: &conv, b: bool) -> str { + conv_bool(cv, b) + } + fn conv_char_ivec(cv: &conv, c: char) -> str { + conv_char(cv, c) + } + fn conv_str_ivec(cv: &conv, s: str) -> str { + conv_str(cv, s) } fn conv_int(cv: &conv, i: int) -> str { - conv_int_ivec(to_conv_ivec(cv), i) - } - fn conv_uint(cv: &conv, u: uint) -> str { - conv_uint_ivec(to_conv_ivec(cv), u) - } - fn conv_bool(cv: &conv, b: bool) -> str { - conv_bool_ivec(to_conv_ivec(cv), b) - } - fn conv_char(cv: &conv, c: char) -> str { - conv_char_ivec(to_conv_ivec(cv), c) - } - fn conv_str(cv: &conv, s: str) -> str { - conv_str_ivec(to_conv_ivec(cv), s) - } - - fn conv_int_ivec(cv: &conv_ivec, i: int) -> str { let radix = 10u; let prec = get_int_precision(cv); let s = int_to_str_prec(i, radix, prec); @@ -308,7 +300,7 @@ mod rt { } ret pad(cv, s, pad_signed); } - fn conv_uint_ivec(cv: &conv_ivec, u: uint) -> str { + fn conv_uint(cv: &conv, u: uint) -> str { let prec = get_int_precision(cv); let rs = alt cv.ty { @@ -320,17 +312,17 @@ mod rt { }; ret pad(cv, rs, pad_unsigned); } - fn conv_bool_ivec(cv: &conv_ivec, b: bool) -> str { + fn conv_bool(cv: &conv, b: bool) -> str { let s = if b { "true" } else { "false" }; // run the boolean conversion through the string conversion logic, // giving it the same rules for precision, etc. ret conv_str_ivec(cv, s); } - fn conv_char_ivec(cv: &conv_ivec, c: char) -> str { + fn conv_char(cv: &conv, c: char) -> str { ret pad(cv, str::from_char(c), pad_nozero); } - fn conv_str_ivec(cv: &conv_ivec, s: str) -> str { + fn conv_str(cv: &conv, s: str) -> str { // For strings, precision is the maximum characters // displayed @@ -371,7 +363,7 @@ mod rt { } else { s } }; } - fn get_int_precision(cv: &conv_ivec) -> uint { + fn get_int_precision(cv: &conv) -> uint { ret alt cv.precision { count_is(c) { c as uint } count_implied. { 1u } @@ -385,7 +377,7 @@ mod rt { ret str::unsafe_from_bytes(svec); } tag pad_mode { pad_signed; pad_unsigned; pad_nozero; } - fn pad(cv: &conv_ivec, s: str, mode: pad_mode) -> str { + fn pad(cv: &conv, s: str, mode: pad_mode) -> str { let uwidth; alt cv.width { count_implied. { ret s; } @@ -413,7 +405,7 @@ mod rt { pad_signed. { might_zero_pad = true; signed = true; } pad_unsigned. { might_zero_pad = true; } } - fn have_precision(cv: &conv_ivec) -> bool { + fn have_precision(cv: &conv) -> bool { ret alt cv.precision { count_implied. { false } _ { true } }; } let zero_padding = false;