about summary refs log tree commit diff
path: root/src/libstd
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/libstd
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/libstd')
-rw-r--r--src/libstd/collections/hashmap.rs24
-rw-r--r--src/libstd/collections/lru_cache.rs20
-rw-r--r--src/libstd/fmt.rs86
-rw-r--r--src/libstd/path/windows.rs6
4 files changed, 54 insertions, 82 deletions
diff --git a/src/libstd/collections/hashmap.rs b/src/libstd/collections/hashmap.rs
index 34851265409..f11e68c7a46 100644
--- a/src/libstd/collections/hashmap.rs
+++ b/src/libstd/collections/hashmap.rs
@@ -1424,6 +1424,7 @@ impl<K: Eq + Hash<S>, V: PartialEq, S, H: Hasher<S>> PartialEq for HashMap<K, V,
 impl<K: Eq + Hash<S>, V: Eq, S, H: Hasher<S>> Eq for HashMap<K, V, H> {}
 
 impl<K: Eq + Hash<S> + Show, V: Show, S, H: Hasher<S>> Show for HashMap<K, V, H> {
+    #[cfg(stage0)]
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         try!(write!(f, r"\{"));
 
@@ -1434,6 +1435,17 @@ impl<K: Eq + Hash<S> + Show, V: Show, S, H: Hasher<S>> Show for HashMap<K, V, H>
 
         write!(f, r"\}")
     }
+    #[cfg(not(stage0))]
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        try!(write!(f, "{{"));
+
+        for (i, (k, v)) in self.iter().enumerate() {
+            if i != 0 { try!(write!(f, ", ")); }
+            try!(write!(f, "{}: {}", *k, *v));
+        }
+
+        write!(f, "}}")
+    }
 }
 
 impl<K: Eq + Hash<S>, V, S, H: Hasher<S> + Default> Default for HashMap<K, V, H> {
@@ -1617,6 +1629,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> {
 }
 
 impl<T: Eq + Hash<S> + fmt::Show, S, H: Hasher<S>> fmt::Show for HashSet<T, H> {
+    #[cfg(stage0)]
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         try!(write!(f, r"\{"));
 
@@ -1627,6 +1640,17 @@ impl<T: Eq + Hash<S> + fmt::Show, S, H: Hasher<S>> fmt::Show for HashSet<T, H> {
 
         write!(f, r"\}")
     }
+    #[cfg(not(stage0))]
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        try!(write!(f, "{{"));
+
+        for (i, x) in self.iter().enumerate() {
+            if i != 0 { try!(write!(f, ", ")); }
+            try!(write!(f, "{}", *x));
+        }
+
+        write!(f, "}}")
+    }
 }
 
 impl<T: Eq + Hash<S>, S, H: Hasher<S> + Default> FromIterator<T> for HashSet<T, H> {
diff --git a/src/libstd/collections/lru_cache.rs b/src/libstd/collections/lru_cache.rs
index 72d96804d6d..0075a50f389 100644
--- a/src/libstd/collections/lru_cache.rs
+++ b/src/libstd/collections/lru_cache.rs
@@ -208,6 +208,7 @@ impl<K: Hash + Eq, V> LruCache<K, V> {
 impl<A: fmt::Show + Hash + Eq, B: fmt::Show> fmt::Show for LruCache<A, B> {
     /// Return a string that lists the key-value pairs from most-recently
     /// used to least-recently used.
+    #[cfg(stage0)]
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         try!(write!(f, r"\{"));
         let mut cur = self.head;
@@ -224,6 +225,25 @@ impl<A: fmt::Show + Hash + Eq, B: fmt::Show> fmt::Show for LruCache<A, B> {
         }
         write!(f, r"\}")
     }
+    /// Return a string that lists the key-value pairs from most-recently
+    /// used to least-recently used.
+    #[cfg(not(stage0))]
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        try!(write!(f, "{{"));
+        let mut cur = self.head;
+        for i in range(0, self.len()) {
+            if i > 0 { try!(write!(f, ", ")) }
+            unsafe {
+                cur = (*cur).next;
+                try!(write!(f, "{}", (*cur).key));
+            }
+            try!(write!(f, ": "));
+            unsafe {
+                try!(write!(f, "{}", (*cur).value));
+            }
+        }
+        write!(f, r"}}")
+    }
 }
 
 impl<K: Hash + Eq, V> Collection for LruCache<K, V> {
diff --git a/src/libstd/fmt.rs b/src/libstd/fmt.rs
index fd3df63ebd4..af76defc8f6 100644
--- a/src/libstd/fmt.rs
+++ b/src/libstd/fmt.rs
@@ -317,76 +317,6 @@ checks provided by the compiler. The `format_args!` macro is the only method of
 safely creating these structures, but they can be unsafely created with the
 constructor provided.
 
-## Internationalization
-
-The formatting syntax supported by the `format!` extension supports
-internationalization by providing "methods" which execute various different
-outputs depending on the input. The syntax and methods provided are similar to
-other internationalization systems, so again nothing should seem alien.
-Currently two methods are supported by this extension: "select" and "plural".
-
-Each method will execute one of a number of clauses, and then the value of the
-clause will become what's the result of the argument's format. Inside of the
-cases, nested argument strings may be provided, but all formatting arguments
-must not be done through implicit positional means. All arguments inside of each
-case of a method must be explicitly selected by their name or their integer
-position.
-
-Furthermore, whenever a case is running, the special character `#` can be used
-to reference the string value of the argument which was selected upon. As an
-example:
-
-```rust
-format!("{0, select, other{#}}", "hello"); // => "hello"
-```
-
-This example is the equivalent of `{0:s}` essentially.
-
-### Select
-
-The select method is a switch over a `&str` parameter, and the parameter *must*
-be of the type `&str`. An example of the syntax is:
-
-```text
-{0, select, male{...} female{...} other{...}}
-```
-
-Breaking this down, the `0`-th argument is selected upon with the `select`
-method, and then a number of cases follow. Each case is preceded by an
-identifier which is the match-clause to execute the given arm. In this case,
-there are two explicit cases, `male` and `female`. The case will be executed if
-the string argument provided is an exact match to the case selected.
-
-The `other` case is also a required case for all `select` methods. This arm will
-be executed if none of the other arms matched the word being selected over.
-
-### Plural
-
-The plural method is a switch statement over a `uint` parameter, and the
-parameter *must* be a `uint`. A plural method in its full glory can be specified
-as:
-
-```text
-{0, plural, offset=1 =1{...} two{...} many{...} other{...}}
-```
-
-To break this down, the first `0` indicates that this method is selecting over
-the value of the first positional parameter to the format string. Next, the
-`plural` method is being executed. An optionally-supplied `offset` is then given
-which indicates a number to subtract from argument `0` when matching. This is
-then followed by a list of cases.
-
-Each case is allowed to supply a specific value to match upon with the syntax
-`=N`. This case is executed if the value at argument `0` matches N exactly,
-without taking the offset into account. A case may also be specified by one of
-five keywords: `zero`, `one`, `two`, `few`, and `many`. These cases are matched
-on after argument `0` has the offset taken into account. Currently the
-definitions of `many` and `few` are hardcoded, but they are in theory defined by
-the current locale.
-
-Finally, all `plural` methods must have an `other` case supplied which will be
-executed if none of the other cases match.
-
 ## Syntax
 
 The syntax for the formatting language used is drawn from other languages, so it
@@ -396,7 +326,7 @@ actual grammar for the formatting syntax is:
 
 ```text
 format_string := <text> [ format <text> ] *
-format := '{' [ argument ] [ ':' format_spec ] [ ',' function_spec ] '}'
+format := '{' [ argument ] [ ':' format_spec ] '}'
 argument := integer | identifier
 
 format_spec := [[fill]align][sign]['#'][0][width]['.' precision][type]
@@ -408,13 +338,6 @@ precision := count | '*'
 type := identifier | ''
 count := parameter | integer
 parameter := integer '$'
-
-function_spec := plural | select
-select := 'select' ',' ( identifier arm ) *
-plural := 'plural' ',' [ 'offset:' integer ] ( selector arm ) *
-selector := '=' integer | keyword
-keyword := 'zero' | 'one' | 'two' | 'few' | 'many' | 'other'
-arm := '{' format_string '}'
 ```
 
 ## Formatting Parameters
@@ -483,10 +406,9 @@ should be printed.
 
 ## Escaping
 
-The literal characters `{`, `}`, or `#` may be included in a string by
-preceding them with the `\` character. Since `\` is already an
-escape character in Rust strings, a string literal using this escape
-will look like `"\\{"`.
+The literal characters `{` and `}` may be included in a string by preceding them
+with the same character. For example, the `{` character is escaped with `{{` and
+the `}` character is escaped with `}}`.
 
 */
 
diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs
index e3209c5c186..b9bb0054d44 100644
--- a/src/libstd/path/windows.rs
+++ b/src/libstd/path/windows.rs
@@ -899,10 +899,16 @@ pub fn make_non_verbatim(path: &Path) -> Option<Path> {
             // \\?\D:\
             Path::new(repr.slice_from(4))
         }
+        #[cfg(stage0)]
         Some(VerbatimUNCPrefix(_,_)) => {
             // \\?\UNC\server\share
             Path::new(format!(r"\\{}", repr.slice_from(7)))
         }
+        #[cfg(not(stage0))]
+        Some(VerbatimUNCPrefix(_,_)) => {
+            // \\?\UNC\server\share
+            Path::new(format!(r"\{}", repr.slice_from(7)))
+        }
     };
     if new_path.prefix.is_none() {
         // \\?\UNC\server is a VerbatimUNCPrefix