@@ -606,12 +606,20 @@ pub fn run(mut krate: clean::Crate,
606
606
}
607
607
608
608
// A short, single-line view of `s`.
609
- fn concise_str ( s : & str ) -> String {
609
+ fn concise_str ( mut s : & str ) -> String {
610
610
if s. contains ( '\n' ) {
611
- return format ! ( "{}..." , s. lines( ) . next( ) . expect( "Impossible! We just found a newline" ) ) ;
611
+ s = s. lines ( ) . next ( ) . expect ( "Impossible! We just found a newline" ) ;
612
612
}
613
613
if s. len ( ) > 70 {
614
- return format ! ( "{} ... {}" , & s[ ..50 ] , & s[ s. len( ) -20 ..] ) ;
614
+ let mut lo = 50 ;
615
+ let mut hi = s. len ( ) - 20 ;
616
+ while !s. is_char_boundary ( lo) {
617
+ lo -= 1 ;
618
+ }
619
+ while !s. is_char_boundary ( hi) {
620
+ hi += 1 ;
621
+ }
622
+ return format ! ( "{} ... {}" , & s[ ..lo] , & s[ hi..] ) ;
615
623
}
616
624
s. to_owned ( )
617
625
}
@@ -1756,18 +1764,18 @@ fn render_markdown(w: &mut fmt::Formatter,
1756
1764
// We only emit warnings if the user has opted-in to Pulldown rendering.
1757
1765
let output = if render_type == RenderType :: Pulldown {
1758
1766
let pulldown_output = format ! ( "{}" , Markdown ( md_text, RenderType :: Pulldown ) ) ;
1759
- let differences = html_diff:: get_differences ( & pulldown_output, & hoedown_output) ;
1760
- let differences = differences. into_iter ( )
1761
- . filter ( |s| {
1762
- match * s {
1763
- html_diff:: Difference :: NodeText { ref elem_text,
1764
- ref opposite_elem_text,
1765
- .. }
1766
- if match_non_whitespace ( elem_text, opposite_elem_text) => false ,
1767
- _ => true ,
1767
+ let mut differences = html_diff:: get_differences ( & pulldown_output, & hoedown_output) ;
1768
+ differences. retain ( |s| {
1769
+ match * s {
1770
+ html_diff:: Difference :: NodeText { ref elem_text,
1771
+ ref opposite_elem_text,
1772
+ .. }
1773
+ if elem_text. split_whitespace ( ) . eq ( opposite_elem_text. split_whitespace ( ) ) => {
1774
+ false
1768
1775
}
1769
- } )
1770
- . collect :: < Vec < _ > > ( ) ;
1776
+ _ => true ,
1777
+ }
1778
+ } ) ;
1771
1779
1772
1780
if !differences. is_empty ( ) {
1773
1781
scx. markdown_warnings . borrow_mut ( ) . push ( ( span, md_text. to_owned ( ) , differences) ) ;
@@ -1781,40 +1789,6 @@ fn render_markdown(w: &mut fmt::Formatter,
1781
1789
write ! ( w, "<div class='docblock'>{}{}</div>" , prefix, output)
1782
1790
}
1783
1791
1784
- // Returns true iff s1 and s2 match, ignoring whitespace.
1785
- fn match_non_whitespace ( s1 : & str , s2 : & str ) -> bool {
1786
- let s1 = s1. trim ( ) ;
1787
- let s2 = s2. trim ( ) ;
1788
- let mut cs1 = s1. chars ( ) ;
1789
- let mut cs2 = s2. chars ( ) ;
1790
- while let Some ( c1) = cs1. next ( ) {
1791
- if c1. is_whitespace ( ) {
1792
- continue ;
1793
- }
1794
-
1795
- loop {
1796
- if let Some ( c2) = cs2. next ( ) {
1797
- if !c2. is_whitespace ( ) {
1798
- if c1 != c2 {
1799
- return false ;
1800
- }
1801
- break ;
1802
- }
1803
- } else {
1804
- return false ;
1805
- }
1806
- }
1807
- }
1808
-
1809
- while let Some ( c2) = cs2. next ( ) {
1810
- if !c2. is_whitespace ( ) {
1811
- return false ;
1812
- }
1813
- }
1814
-
1815
- true
1816
- }
1817
-
1818
1792
fn document_short ( w : & mut fmt:: Formatter , item : & clean:: Item , link : AssocItemLink ,
1819
1793
cx : & Context , prefix : & str ) -> fmt:: Result {
1820
1794
if let Some ( s) = item. doc_value ( ) {
@@ -3791,35 +3765,3 @@ fn test_name_sorting() {
3791
3765
sorted. sort_by_key ( |& s| name_key ( s) ) ;
3792
3766
assert_eq ! ( names, sorted) ;
3793
3767
}
3794
-
3795
- #[ cfg( test) ]
3796
- #[ test]
3797
- fn test_match_non_whitespace ( ) {
3798
- assert ! ( match_non_whitespace( "" , "" ) ) ;
3799
- assert ! ( match_non_whitespace( " " , "" ) ) ;
3800
- assert ! ( match_non_whitespace( "" , " " ) ) ;
3801
-
3802
- assert ! ( match_non_whitespace( "a" , "a" ) ) ;
3803
- assert ! ( match_non_whitespace( " a " , "a" ) ) ;
3804
- assert ! ( match_non_whitespace( "a" , " a" ) ) ;
3805
- assert ! ( match_non_whitespace( "abc" , "abc" ) ) ;
3806
- assert ! ( match_non_whitespace( "abc" , " abc " ) ) ;
3807
- assert ! ( match_non_whitespace( "abc " , "abc" ) ) ;
3808
- assert ! ( match_non_whitespace( "abc xyz" , "abc xyz" ) ) ;
3809
- assert ! ( match_non_whitespace( "abc xyz" , "abc\n xyz" ) ) ;
3810
- assert ! ( match_non_whitespace( "abc xyz" , "abcxyz" ) ) ;
3811
- assert ! ( match_non_whitespace( "abcxyz" , "abc xyz" ) ) ;
3812
- assert ! ( match_non_whitespace( "abc xyz " , " abc xyz\n " ) ) ;
3813
-
3814
- assert ! ( !match_non_whitespace( "a" , "b" ) ) ;
3815
- assert ! ( !match_non_whitespace( " a " , "c" ) ) ;
3816
- assert ! ( !match_non_whitespace( "a" , " aa" ) ) ;
3817
- assert ! ( !match_non_whitespace( "abc" , "ac" ) ) ;
3818
- assert ! ( !match_non_whitespace( "abc" , " adc " ) ) ;
3819
- assert ! ( !match_non_whitespace( "abc " , "abca" ) ) ;
3820
- assert ! ( !match_non_whitespace( "abc xyz" , "abc xy" ) ) ;
3821
- assert ! ( !match_non_whitespace( "abc xyz" , "bc\n xyz" ) ) ;
3822
- assert ! ( !match_non_whitespace( "abc xyz" , "abc.xyz" ) ) ;
3823
- assert ! ( !match_non_whitespace( "abcxyz" , "abc.xyz" ) ) ;
3824
- assert ! ( !match_non_whitespace( "abc xyz " , " abc xyz w" ) ) ;
3825
- }
0 commit comments