Skip to content

Commit 6a649e6

Browse files
committed
auto merge of #8710 : pnkfelix/rust/fsk-issue5516-codepoint-fix, r=alexcrichton
...bytes. (removing previous note about eff-eye-ex'ing #5516 since it actually does not do so, it just gets us half-way.)
2 parents bed8489 + ca0e7b1 commit 6a649e6

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

Diff for: src/libextra/getopts.rs

+32-5
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,9 @@ pub mod groups {
689689
}
690690
}
691691

692-
// FIXME: #5516
692+
// FIXME: #5516 should be graphemes not codepoints
693693
// here we just need to indent the start of the description
694-
let rowlen = row.len();
694+
let rowlen = row.char_len();
695695
if rowlen < 24 {
696696
do (24 - rowlen).times {
697697
row.push_char(' ')
@@ -707,14 +707,14 @@ pub mod groups {
707707
desc_normalized_whitespace.push_char(' ');
708708
}
709709

710-
// FIXME: #5516
710+
// FIXME: #5516 should be graphemes not codepoints
711711
let mut desc_rows = ~[];
712712
do each_split_within(desc_normalized_whitespace, 54) |substr| {
713713
desc_rows.push(substr.to_owned());
714714
true
715715
};
716716

717-
// FIXME: #5516
717+
// FIXME: #5516 should be graphemes not codepoints
718718
// wrapped description
719719
row.push_str(desc_rows.connect(desc_sep));
720720

@@ -798,7 +798,7 @@ pub mod groups {
798798
cont
799799
};
800800

801-
ss.iter().enumerate().advance(|x| machine(x));
801+
ss.char_offset_iter().advance(|x| machine(x));
802802

803803
// Let the automaton 'run out' by supplying trailing whitespace
804804
while cont && match state { B | C => true, A => false } {
@@ -1580,4 +1580,31 @@ Options:
15801580
debug!("generated: <<%s>>", usage);
15811581
assert!(usage == expected)
15821582
}
1583+
1584+
#[test]
1585+
fn test_groups_usage_description_multibyte_handling() {
1586+
let optgroups = ~[
1587+
groups::optflag("k", "k\u2013w\u2013",
1588+
"The word kiwi is normally spelled with two i's"),
1589+
groups::optflag("a", "apple",
1590+
"This \u201Cdescription\u201D has some characters that could \
1591+
confuse the line wrapping; an apple costs 0.51€ in some parts of Europe."),
1592+
];
1593+
1594+
let expected =
1595+
~"Usage: fruits
1596+
1597+
Options:
1598+
-k --k–w– The word kiwi is normally spelled with two i's
1599+
-a --apple This “description” has some characters that could
1600+
confuse the line wrapping; an apple costs 0.51in
1601+
some parts of Europe.
1602+
";
1603+
1604+
let usage = groups::usage("Usage: fruits", optgroups);
1605+
1606+
debug!("expected: <<%s>>", expected);
1607+
debug!("generated: <<%s>>", usage);
1608+
assert!(usage == expected)
1609+
}
15831610
}

0 commit comments

Comments
 (0)