about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-08-25 21:49:06 -0700
committerBrian Anderson <banderson@mozilla.com>2011-08-27 15:54:44 -0700
commit7284f820d57e13b10fd9f1c3fc771fac52b6b66a (patch)
tree9f047d06d8239636e49b1fca640ac489877af0af
parent6b3f0b21bec623eb878735601c514a383c606bed (diff)
Support istrs in #fmt. Issue #855
The format string may be an istr and istr args may be used with %S
-rw-r--r--src/comp/syntax/ext/fmt.rs2
-rw-r--r--src/lib/extfmt.rs9
-rw-r--r--src/test/run-pass/syntax-extension-fmt-istr.rs6
3 files changed, 16 insertions, 1 deletions
diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs
index 093799714a7..2a441341f49 100644
--- a/src/comp/syntax/ext/fmt.rs
+++ b/src/comp/syntax/ext/fmt.rs
@@ -241,6 +241,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
         }
         alt cnv.ty {
           ty_str. { ret make_conv_call(cx, arg.span, "str", cnv, arg); }
+          ty_istr. { ret make_conv_call(cx, arg.span, "istr", cnv, arg); }
           ty_int(sign) {
             alt sign {
               signed. { ret make_conv_call(cx, arg.span, "int", cnv, arg); }
@@ -297,6 +298,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
         alt c.ty {
           ty_bool. { log "type: bool"; }
           ty_str. { log "type: str"; }
+          ty_istr. { log "type: istr"; }
           ty_char. { log "type: char"; }
           ty_int(s) {
             alt s {
diff --git a/src/lib/extfmt.rs b/src/lib/extfmt.rs
index d3e507f1b89..84c642d2883 100644
--- a/src/lib/extfmt.rs
+++ b/src/lib/extfmt.rs
@@ -41,8 +41,9 @@ mod ct {
         ty_bits;
         ty_hex(caseness);
         ty_octal;
+        // FIXME: Transitional
+        ty_istr;
         // FIXME: More types
-
     }
     tag flag {
         flag_left_justify;
@@ -225,6 +226,8 @@ mod ct {
                 ty_bool
             } else if str::eq(tstr, "s") {
                 ty_str
+            } else if str::eq(tstr, "S") {
+                ty_istr
             } else if str::eq(tstr, "c") {
                 ty_char
             } else if str::eq(tstr, "d") || str::eq(tstr, "i") {
@@ -322,6 +325,10 @@ mod rt {
         ret pad(cv, unpadded, pad_nozero);
     }
 
+    fn conv_istr(cv: &conv, s: &istr) -> str {
+        ret conv_str(cv, istr::to_estr(s));
+    }
+
     // Convert an int to string with minimum number of digits. If precision is
     // 0 and num is 0 then the result is the empty string.
     fn int_to_str_prec(num: int, radix: uint, prec: uint) -> str {
diff --git a/src/test/run-pass/syntax-extension-fmt-istr.rs b/src/test/run-pass/syntax-extension-fmt-istr.rs
new file mode 100644
index 00000000000..9f2b7ae8291
--- /dev/null
+++ b/src/test/run-pass/syntax-extension-fmt-istr.rs
@@ -0,0 +1,6 @@
+// FIXME: This test is transitional until estrs are gone.
+use std;
+fn main() {
+    let s = #fmt[~"%S", ~"test"];
+    assert s == "test";
+}
\ No newline at end of file