about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-09-12 08:05:42 +0000
committerbors <bors@rust-lang.org>2014-09-12 08:05:42 +0000
commit22e749ded10822a3063fa26800aaa3f229e97c4d (patch)
treeea904ca9f23211f91e77a38dbce2a633fde5e41c
parent805cf81b778f7b0d17a4afa3af93f975d5351307 (diff)
parent5b3c3511c9f69c047a5eb804c91f984d83779c83 (diff)
downloadrust-22e749ded10822a3063fa26800aaa3f229e97c4d.tar.gz
rust-22e749ded10822a3063fa26800aaa3f229e97c4d.zip
auto merge of #17145 : ahmedcharles/rust/unicode, r=alexcrichton
-rw-r--r--src/libcore/fmt/mod.rs4
-rw-r--r--src/test/run-pass/ifmt.rs8
2 files changed, 10 insertions, 2 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index be75bfec32c..3244a72897f 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -476,7 +476,7 @@ impl<'a> Formatter<'a> {
 
         let mut prefixed = false;
         if self.flags & (1 << (FlagAlternate as uint)) != 0 {
-            prefixed = true; width += prefix.len();
+            prefixed = true; width += prefix.char_len();
         }
 
         // Writes the sign if it exists, and then the prefix if it was requested
@@ -562,7 +562,7 @@ impl<'a> Formatter<'a> {
             // If we're under both the maximum and the minimum width, then fill
             // up the minimum width with the specified string + some alignment.
             Some(width) => {
-                self.with_padding(width - s.len(), rt::AlignLeft, |me| {
+                self.with_padding(width - s.char_len(), rt::AlignLeft, |me| {
                     me.buf.write(s.as_bytes())
                 })
             }
diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs
index d582209a79e..78e17bb22bd 100644
--- a/src/test/run-pass/ifmt.rs
+++ b/src/test/run-pass/ifmt.rs
@@ -25,6 +25,7 @@ use std::str;
 
 struct A;
 struct B;
+struct C;
 
 impl fmt::Signed for A {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -36,6 +37,11 @@ impl fmt::Signed for B {
         f.write("adios".as_bytes())
     }
 }
+impl fmt::Show for C {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.pad_integral(true, "☃", "123".as_bytes())
+    }
+}
 
 macro_rules! t(($a:expr, $b:expr) => { assert_eq!($a.as_slice(), $b) })
 
@@ -81,6 +87,7 @@ pub fn main() {
     t!(format!("{} {0}", "a"), "a a");
     t!(format!("{foo_bar}", foo_bar=1i), "1");
     t!(format!("{:d}", 5i + 5i), "10");
+    t!(format!("{:#4}", C), "☃123");
 
     let a: &fmt::Show = &1i;
     t!(format!("{}", a), "1");
@@ -88,6 +95,7 @@ pub fn main() {
     // Formatting strings and their arguments
     t!(format!("{:s}", "a"), "a");
     t!(format!("{:4s}", "a"), "a   ");
+    t!(format!("{:4s}", "☃"), "☃   ");
     t!(format!("{:>4s}", "a"), "   a");
     t!(format!("{:<4s}", "a"), "a   ");
     t!(format!("{:^5s}", "a"),  "  a  ");