@@ -689,9 +689,9 @@ pub mod groups {
689
689
}
690
690
}
691
691
692
- // FIXME: #5516
692
+ // FIXME: #5516 should be graphemes not codepoints
693
693
// here we just need to indent the start of the description
694
- let rowlen = row. len ( ) ;
694
+ let rowlen = row. char_len ( ) ;
695
695
if rowlen < 24 {
696
696
do ( 24 - rowlen) . times {
697
697
row. push_char ( ' ' )
@@ -707,14 +707,14 @@ pub mod groups {
707
707
desc_normalized_whitespace. push_char ( ' ' ) ;
708
708
}
709
709
710
- // FIXME: #5516
710
+ // FIXME: #5516 should be graphemes not codepoints
711
711
let mut desc_rows = ~[ ] ;
712
712
do each_split_within ( desc_normalized_whitespace, 54 ) |substr| {
713
713
desc_rows. push ( substr. to_owned ( ) ) ;
714
714
true
715
715
} ;
716
716
717
- // FIXME: #5516
717
+ // FIXME: #5516 should be graphemes not codepoints
718
718
// wrapped description
719
719
row. push_str ( desc_rows. connect ( desc_sep) ) ;
720
720
@@ -798,7 +798,7 @@ pub mod groups {
798
798
cont
799
799
} ;
800
800
801
- ss. iter ( ) . enumerate ( ) . advance ( |x| machine ( x) ) ;
801
+ ss. char_offset_iter ( ) . advance ( |x| machine ( x) ) ;
802
802
803
803
// Let the automaton 'run out' by supplying trailing whitespace
804
804
while cont && match state { B | C => true , A => false } {
@@ -1580,4 +1580,31 @@ Options:
1580
1580
debug!(" generated: <<%s>>", usage);
1581
1581
assert!(usage == expected)
1582
1582
}
1583
+
1584
+ #[test]
1585
+ fn test_groups_usage_description_multibyte_handling() {
1586
+ let optgroups = ~[
1587
+ groups::optflag(" k", " k\u2013 w\u2013 ",
1588
+ "The word kiwi is normally spelled with two i's" ) ,
1589
+ groups:: optflag( "a" , "apple" ,
1590
+ "This \u201C description\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.51 € in
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
+ }
1583
1610
}
0 commit comments