about summary refs log tree commit diff
path: root/src/libserialize
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/libserialize
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/libserialize')
-rw-r--r--src/libserialize/json.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs
index a5c2042c979..8dfd4e778c2 100644
--- a/src/libserialize/json.rs
+++ b/src/libserialize/json.rs
@@ -430,6 +430,7 @@ impl<'a> ::Encoder<io::IoError> for Encoder<'a> {
                  _name: &str,
                  f: |&mut Encoder<'a>| -> EncodeResult) -> EncodeResult { f(self) }
 
+    #[cfg(stage0)]
     fn emit_enum_variant(&mut self,
                          name: &str,
                          _id: uint,
@@ -448,6 +449,25 @@ impl<'a> ::Encoder<io::IoError> for Encoder<'a> {
             write!(self.wr, "]\\}")
         }
     }
+    #[cfg(not(stage0))]
+    fn emit_enum_variant(&mut self,
+                         name: &str,
+                         _id: uint,
+                         cnt: uint,
+                         f: |&mut Encoder<'a>| -> EncodeResult) -> EncodeResult {
+        // enums are encoded as strings or objects
+        // Bunny => "Bunny"
+        // Kangaroo(34,"William") => {"variant": "Kangaroo", "fields": [34,"William"]}
+        if cnt == 0 {
+            write!(self.wr, "{}", escape_str(name))
+        } else {
+            try!(write!(self.wr, "{{\"variant\":"));
+            try!(write!(self.wr, "{}", escape_str(name)));
+            try!(write!(self.wr, ",\"fields\":["));
+            try!(f(self));
+            write!(self.wr, "]}}")
+        }
+    }
 
     fn emit_enum_variant_arg(&mut self,
                              idx: uint,
@@ -473,6 +493,7 @@ impl<'a> ::Encoder<io::IoError> for Encoder<'a> {
         self.emit_enum_variant_arg(idx, f)
     }
 
+    #[cfg(stage0)]
     fn emit_struct(&mut self,
                    _: &str,
                    _: uint,
@@ -481,6 +502,15 @@ impl<'a> ::Encoder<io::IoError> for Encoder<'a> {
         try!(f(self));
         write!(self.wr, r"\}")
     }
+    #[cfg(not(stage0))]
+    fn emit_struct(&mut self,
+                   _: &str,
+                   _: uint,
+                   f: |&mut Encoder<'a>| -> EncodeResult) -> EncodeResult {
+        try!(write!(self.wr, "{{"));
+        try!(f(self));
+        write!(self.wr, "}}")
+    }
 
     fn emit_struct_field(&mut self,
                          name: &str,
@@ -533,11 +563,18 @@ impl<'a> ::Encoder<io::IoError> for Encoder<'a> {
         f(self)
     }
 
+    #[cfg(stage0)]
     fn emit_map(&mut self, _len: uint, f: |&mut Encoder<'a>| -> EncodeResult) -> EncodeResult {
         try!(write!(self.wr, r"\{"));
         try!(f(self));
         write!(self.wr, r"\}")
     }
+    #[cfg(not(stage0))]
+    fn emit_map(&mut self, _len: uint, f: |&mut Encoder<'a>| -> EncodeResult) -> EncodeResult {
+        try!(write!(self.wr, "{{"));
+        try!(f(self));
+        write!(self.wr, "}}")
+    }
 
     fn emit_map_elt_key(&mut self,
                         idx: uint,
@@ -670,6 +707,7 @@ impl<'a> ::Encoder<io::IoError> for PrettyEncoder<'a> {
     }
 
 
+    #[cfg(stage0)]
     fn emit_struct(&mut self,
                    _: &str,
                    len: uint,
@@ -684,6 +722,21 @@ impl<'a> ::Encoder<io::IoError> for PrettyEncoder<'a> {
             write!(self.wr, "\n{}\\}", spaces(self.indent))
         }
     }
+    #[cfg(not(stage0))]
+    fn emit_struct(&mut self,
+                   _: &str,
+                   len: uint,
+                   f: |&mut PrettyEncoder<'a>| -> EncodeResult) -> EncodeResult {
+        if len == 0 {
+            write!(self.wr, "{{}}")
+        } else {
+            try!(write!(self.wr, "{{"));
+            self.indent += 2;
+            try!(f(self));
+            self.indent -= 2;
+            write!(self.wr, "\n{}}}", spaces(self.indent))
+        }
+    }
 
     fn emit_struct_field(&mut self,
                          name: &str,
@@ -755,6 +808,7 @@ impl<'a> ::Encoder<io::IoError> for PrettyEncoder<'a> {
         f(self)
     }
 
+    #[cfg(stage0)]
     fn emit_map(&mut self,
                 len: uint,
                 f: |&mut PrettyEncoder<'a>| -> EncodeResult) -> EncodeResult {
@@ -768,6 +822,20 @@ impl<'a> ::Encoder<io::IoError> for PrettyEncoder<'a> {
             write!(self.wr, "\n{}\\}", spaces(self.indent))
         }
     }
+    #[cfg(not(stage0))]
+    fn emit_map(&mut self,
+                len: uint,
+                f: |&mut PrettyEncoder<'a>| -> EncodeResult) -> EncodeResult {
+        if len == 0 {
+            write!(self.wr, "{{}}")
+        } else {
+            try!(write!(self.wr, "{{"));
+            self.indent += 2;
+            try!(f(self));
+            self.indent -= 2;
+            write!(self.wr, "\n{}}}", spaces(self.indent))
+        }
+    }
 
     fn emit_map_elt_key(&mut self,
                         idx: uint,