diff options
| author | bors <bors@rust-lang.org> | 2013-08-25 04:21:15 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-08-25 04:21:15 -0700 |
| commit | 6a649e6b8b3e42bb8fa8fa806d783ecd9b543784 (patch) | |
| tree | 7846affbd49aaefb860c25633b39dc5502b4bf2d | |
| parent | bed84898fca9443f97fc3db17b0417c179d25803 (diff) | |
| parent | ca0e7b12aa3ec542a75769cc3453464813b20490 (diff) | |
| download | rust-6a649e6b8b3e42bb8fa8fa806d783ecd9b543784.tar.gz rust-6a649e6b8b3e42bb8fa8fa806d783ecd9b543784.zip | |
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.)
| -rw-r--r-- | src/libextra/getopts.rs | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs index 000520fe41e..a21d9dc605f 100644 --- a/src/libextra/getopts.rs +++ b/src/libextra/getopts.rs @@ -689,9 +689,9 @@ pub mod groups { } } - // FIXME: #5516 + // FIXME: #5516 should be graphemes not codepoints // here we just need to indent the start of the description - let rowlen = row.len(); + let rowlen = row.char_len(); if rowlen < 24 { do (24 - rowlen).times { row.push_char(' ') @@ -707,14 +707,14 @@ pub mod groups { desc_normalized_whitespace.push_char(' '); } - // FIXME: #5516 + // FIXME: #5516 should be graphemes not codepoints let mut desc_rows = ~[]; do each_split_within(desc_normalized_whitespace, 54) |substr| { desc_rows.push(substr.to_owned()); true }; - // FIXME: #5516 + // FIXME: #5516 should be graphemes not codepoints // wrapped description row.push_str(desc_rows.connect(desc_sep)); @@ -798,7 +798,7 @@ pub mod groups { cont }; - ss.iter().enumerate().advance(|x| machine(x)); + ss.char_offset_iter().advance(|x| machine(x)); // Let the automaton 'run out' by supplying trailing whitespace while cont && match state { B | C => true, A => false } { @@ -1580,4 +1580,31 @@ Options: debug!("generated: <<%s>>", usage); assert!(usage == expected) } + + #[test] + fn test_groups_usage_description_multibyte_handling() { + let optgroups = ~[ + groups::optflag("k", "k\u2013w\u2013", + "The word kiwi is normally spelled with two i's"), + groups::optflag("a", "apple", + "This \u201Cdescription\u201D has some characters that could \ +confuse the line wrapping; an apple costs 0.51€ in some parts of Europe."), + ]; + + let expected = +~"Usage: fruits + +Options: + -k --k–w– The word kiwi is normally spelled with two i's + -a --apple This “description” has some characters that could + confuse the line wrapping; an apple costs 0.51€ in + some parts of Europe. +"; + + let usage = groups::usage("Usage: fruits", optgroups); + + debug!("expected: <<%s>>", expected); + debug!("generated: <<%s>>", usage); + assert!(usage == expected) + } } |
