about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-06-13 14:42:03 +0000
committerbors <bors@rust-lang.org>2014-06-13 14:42:03 +0000
commit0422934e243ed57a7662ec878db9d4e01ca5b0f9 (patch)
tree5e7bcd1009b105bae30dac48beb5ffed9a53f256 /src/libcore
parentc119903f621a11643d5f299423a2c72eefffec4c (diff)
parentcac7a2053aba7be214d5e58e13867089638a8f50 (diff)
downloadrust-0422934e243ed57a7662ec878db9d4e01ca5b0f9.tar.gz
rust-0422934e243ed57a7662ec878db9d4e01ca5b0f9.zip
auto merge of #14831 : alexcrichton/rust/format-intl, r=brson
* The select/plural methods from format strings are removed
* The # character no longer needs to be escaped
* The \-based escapes have been removed
* '{{' is now an escape for '{'
* '}}' is now an escape for '}'

Closes #14810
[breaking-change]
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/fmt/mod.rs103
-rw-r--r--src/libcore/fmt/rt.rs40
2 files changed, 12 insertions, 131 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index 0770c44dfbc..053dbbe5da9 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -98,12 +98,6 @@ pub struct Formatter<'a> {
     args: &'a [Argument<'a>],
 }
 
-enum CurrentlyFormatting<'a> {
-    Nothing,
-    RawString(&'a str),
-    Number(uint),
-}
-
 /// This struct represents the generic "argument" which is taken by the Xprintf
 /// family of functions. It contains a function to format the given value. At
 /// compile time it is ensured that the function and the value have the correct
@@ -280,7 +274,7 @@ pub fn write(output: &mut FormatWriter, args: &Arguments) -> Result {
         curarg: args.args.iter(),
     };
     for piece in args.fmt.iter() {
-        try!(formatter.run(piece, Nothing));
+        try!(formatter.run(piece));
     }
     Ok(())
 }
@@ -291,16 +285,9 @@ impl<'a> Formatter<'a> {
     // at runtime. This consumes all of the compile-time statics generated by
     // the format! syntax extension.
 
-    fn run(&mut self, piece: &rt::Piece, cur: CurrentlyFormatting) -> Result {
+    fn run(&mut self, piece: &rt::Piece) -> Result {
         match *piece {
             rt::String(s) => self.buf.write(s.as_bytes()),
-            rt::CurrentArgument(()) => {
-                match cur {
-                    Nothing => Ok(()),
-                    Number(n) => secret_show(&radix(n, 10), self),
-                    RawString(s) => self.buf.write(s.as_bytes()),
-                }
-            }
             rt::Argument(ref arg) => {
                 // Fill in the format parameters into the formatter
                 self.fill = arg.format.fill;
@@ -316,10 +303,7 @@ impl<'a> Formatter<'a> {
                 };
 
                 // Then actually do some printing
-                match arg.method {
-                    None => (value.formatter)(value.value, self),
-                    Some(ref method) => self.execute(*method, value)
-                }
+                (value.formatter)(value.value, self)
             }
         }
     }
@@ -339,82 +323,6 @@ impl<'a> Formatter<'a> {
         }
     }
 
-    fn execute(&mut self, method: &rt::Method, arg: Argument) -> Result {
-        match *method {
-            // Pluralization is selection upon a numeric value specified as the
-            // parameter.
-            rt::Plural(offset, ref selectors, ref default) => {
-                // This is validated at compile-time to be a pointer to a
-                // '&uint' value.
-                let value: &uint = unsafe { mem::transmute(arg.value) };
-                let value = *value;
-
-                // First, attempt to match against explicit values without the
-                // offsetted value
-                for s in selectors.iter() {
-                    match s.selector {
-                        rt::Literal(val) if value == val => {
-                            return self.runplural(value, s.result);
-                        }
-                        _ => {}
-                    }
-                }
-
-                // Next, offset the value and attempt to match against the
-                // keyword selectors.
-                let value = value - match offset { Some(i) => i, None => 0 };
-                for s in selectors.iter() {
-                    let run = match s.selector {
-                        rt::Keyword(rt::Zero) => value == 0,
-                        rt::Keyword(rt::One) => value == 1,
-                        rt::Keyword(rt::Two) => value == 2,
-
-                        // FIXME: Few/Many should have a user-specified boundary
-                        //      One possible option would be in the function
-                        //      pointer of the 'arg: Argument' struct.
-                        rt::Keyword(rt::Few) => value < 8,
-                        rt::Keyword(rt::Many) => value >= 8,
-
-                        rt::Literal(..) => false
-                    };
-                    if run {
-                        return self.runplural(value, s.result);
-                    }
-                }
-
-                self.runplural(value, *default)
-            }
-
-            // Select is just a matching against the string specified.
-            rt::Select(ref selectors, ref default) => {
-                // This is validated at compile-time to be a pointer to a
-                // string slice,
-                let value: & &str = unsafe { mem::transmute(arg.value) };
-                let value = *value;
-
-                for s in selectors.iter() {
-                    if s.selector == value {
-                        for piece in s.result.iter() {
-                            try!(self.run(piece, RawString(value)));
-                        }
-                        return Ok(());
-                    }
-                }
-                for piece in default.iter() {
-                    try!(self.run(piece, RawString(value)));
-                }
-                Ok(())
-            }
-        }
-    }
-
-    fn runplural(&mut self, value: uint, pieces: &[rt::Piece]) -> Result {
-        for piece in pieces.iter() {
-            try!(self.run(piece, Number(value)));
-        }
-        Ok(())
-    }
-
     // Helper methods used for padding and processing formatting arguments that
     // all formatting traits can use.
 
@@ -836,9 +744,14 @@ impl Show for () {
 }
 
 impl<T: Copy + Show> Show for Cell<T> {
+    #[cfg(stage0)]
     fn fmt(&self, f: &mut Formatter) -> Result {
         write!(f, r"Cell \{ value: {} \}", self.get())
     }
+    #[cfg(not(stage0))]
+    fn fmt(&self, f: &mut Formatter) -> Result {
+        write!(f, "Cell {{ value: {} }}", self.get())
+    }
 }
 
 impl<'b, T: Show> Show for Ref<'b, T> {
diff --git a/src/libcore/fmt/rt.rs b/src/libcore/fmt/rt.rs
index 1feebbb35b6..6d3edeabca9 100644
--- a/src/libcore/fmt/rt.rs
+++ b/src/libcore/fmt/rt.rs
@@ -14,13 +14,13 @@
 //! These definitions are similar to their `ct` equivalents, but differ in that
 //! these can be statically allocated and are slightly optimized for the runtime
 
+
+#[cfg(stage0)]
 use option::Option;
 
 #[doc(hidden)]
 pub enum Piece<'a> {
     String(&'a str),
-    // FIXME(#8259): this shouldn't require the unit-value here
-    CurrentArgument(()),
     Argument(Argument<'a>),
 }
 
@@ -28,7 +28,8 @@ pub enum Piece<'a> {
 pub struct Argument<'a> {
     pub position: Position,
     pub format: FormatSpec,
-    pub method: Option<&'a Method<'a>>
+    #[cfg(stage0)]
+    pub method: Option<uint>,
 }
 
 #[doc(hidden)]
@@ -80,36 +81,3 @@ pub enum Flag {
     /// being aware of the sign to be printed.
     FlagSignAwareZeroPad,
 }
-
-#[doc(hidden)]
-pub enum Method<'a> {
-    Plural(Option<uint>, &'a [PluralArm<'a>], &'a [Piece<'a>]),
-    Select(&'a [SelectArm<'a>], &'a [Piece<'a>]),
-}
-
-#[doc(hidden)]
-pub enum PluralSelector {
-    Keyword(PluralKeyword),
-    Literal(uint),
-}
-
-#[doc(hidden)]
-pub enum PluralKeyword {
-    Zero,
-    One,
-    Two,
-    Few,
-    Many,
-}
-
-#[doc(hidden)]
-pub struct PluralArm<'a> {
-    pub selector: PluralSelector,
-    pub result: &'a [Piece<'a>],
-}
-
-#[doc(hidden)]
-pub struct SelectArm<'a> {
-    pub selector: &'a str,
-    pub result: &'a [Piece<'a>],
-}