Skip to content

Commit 22e749d

Browse files
committed
auto merge of #17145 : ahmedcharles/rust/unicode, r=alexcrichton
2 parents 805cf81 + 5b3c351 commit 22e749d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/libcore/fmt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl<'a> Formatter<'a> {
476476

477477
let mut prefixed = false;
478478
if self.flags & (1 << (FlagAlternate as uint)) != 0 {
479-
prefixed = true; width += prefix.len();
479+
prefixed = true; width += prefix.char_len();
480480
}
481481

482482
// Writes the sign if it exists, and then the prefix if it was requested
@@ -562,7 +562,7 @@ impl<'a> Formatter<'a> {
562562
// If we're under both the maximum and the minimum width, then fill
563563
// up the minimum width with the specified string + some alignment.
564564
Some(width) => {
565-
self.with_padding(width - s.len(), rt::AlignLeft, |me| {
565+
self.with_padding(width - s.char_len(), rt::AlignLeft, |me| {
566566
me.buf.write(s.as_bytes())
567567
})
568568
}

src/test/run-pass/ifmt.rs

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use std::str;
2525

2626
struct A;
2727
struct B;
28+
struct C;
2829

2930
impl fmt::Signed for A {
3031
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -36,6 +37,11 @@ impl fmt::Signed for B {
3637
f.write("adios".as_bytes())
3738
}
3839
}
40+
impl fmt::Show for C {
41+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42+
f.pad_integral(true, "☃", "123".as_bytes())
43+
}
44+
}
3945

4046
macro_rules! t(($a:expr, $b:expr) => { assert_eq!($a.as_slice(), $b) })
4147

@@ -81,13 +87,15 @@ pub fn main() {
8187
t!(format!("{} {0}", "a"), "a a");
8288
t!(format!("{foo_bar}", foo_bar=1i), "1");
8389
t!(format!("{:d}", 5i + 5i), "10");
90+
t!(format!("{:#4}", C), "☃123");
8491

8592
let a: &fmt::Show = &1i;
8693
t!(format!("{}", a), "1");
8794

8895
// Formatting strings and their arguments
8996
t!(format!("{:s}", "a"), "a");
9097
t!(format!("{:4s}", "a"), "a ");
98+
t!(format!("{:4s}", "☃"), "☃ ");
9199
t!(format!("{:>4s}", "a"), " a");
92100
t!(format!("{:<4s}", "a"), "a ");
93101
t!(format!("{:^5s}", "a"), " a ");

0 commit comments

Comments
 (0)