@@ -1763,7 +1763,7 @@ fn render_markdown(w: &mut fmt::Formatter,
1763
1763
html_diff:: Difference :: NodeText { ref elem_text,
1764
1764
ref opposite_elem_text,
1765
1765
.. }
1766
- if elem_text . trim ( ) == opposite_elem_text. trim ( ) => false ,
1766
+ if match_non_whitespace ( elem_text , opposite_elem_text) => false ,
1767
1767
_ => true ,
1768
1768
}
1769
1769
} )
@@ -1781,6 +1781,40 @@ fn render_markdown(w: &mut fmt::Formatter,
1781
1781
write ! ( w, "<div class='docblock'>{}{}</div>" , prefix, output)
1782
1782
}
1783
1783
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
+
1784
1818
fn document_short ( w : & mut fmt:: Formatter , item : & clean:: Item , link : AssocItemLink ,
1785
1819
cx : & Context , prefix : & str ) -> fmt:: Result {
1786
1820
if let Some ( s) = item. doc_value ( ) {
@@ -3695,3 +3729,35 @@ fn test_name_sorting() {
3695
3729
sorted. sort_by_key ( |& s| name_key ( s) ) ;
3696
3730
assert_eq ! ( names, sorted) ;
3697
3731
}
3732
+
3733
+ #[ cfg( test) ]
3734
+ #[ test]
3735
+ fn test_match_non_whitespace ( ) {
3736
+ assert ! ( match_non_whitespace( "" , "" ) ) ;
3737
+ assert ! ( match_non_whitespace( " " , "" ) ) ;
3738
+ assert ! ( match_non_whitespace( "" , " " ) ) ;
3739
+
3740
+ assert ! ( match_non_whitespace( "a" , "a" ) ) ;
3741
+ assert ! ( match_non_whitespace( " a " , "a" ) ) ;
3742
+ assert ! ( match_non_whitespace( "a" , " a" ) ) ;
3743
+ assert ! ( match_non_whitespace( "abc" , "abc" ) ) ;
3744
+ assert ! ( match_non_whitespace( "abc" , " abc " ) ) ;
3745
+ assert ! ( match_non_whitespace( "abc " , "abc" ) ) ;
3746
+ assert ! ( match_non_whitespace( "abc xyz" , "abc xyz" ) ) ;
3747
+ assert ! ( match_non_whitespace( "abc xyz" , "abc\n xyz" ) ) ;
3748
+ assert ! ( match_non_whitespace( "abc xyz" , "abcxyz" ) ) ;
3749
+ assert ! ( match_non_whitespace( "abcxyz" , "abc xyz" ) ) ;
3750
+ assert ! ( match_non_whitespace( "abc xyz " , " abc xyz\n " ) ) ;
3751
+
3752
+ assert ! ( !match_non_whitespace( "a" , "b" ) ) ;
3753
+ assert ! ( !match_non_whitespace( " a " , "c" ) ) ;
3754
+ assert ! ( !match_non_whitespace( "a" , " aa" ) ) ;
3755
+ assert ! ( !match_non_whitespace( "abc" , "ac" ) ) ;
3756
+ assert ! ( !match_non_whitespace( "abc" , " adc " ) ) ;
3757
+ assert ! ( !match_non_whitespace( "abc " , "abca" ) ) ;
3758
+ assert ! ( !match_non_whitespace( "abc xyz" , "abc xy" ) ) ;
3759
+ assert ! ( !match_non_whitespace( "abc xyz" , "bc\n xyz" ) ) ;
3760
+ assert ! ( !match_non_whitespace( "abc xyz" , "abc.xyz" ) ) ;
3761
+ assert ! ( !match_non_whitespace( "abcxyz" , "abc.xyz" ) ) ;
3762
+ assert ! ( !match_non_whitespace( "abc xyz " , " abc xyz w" ) ) ;
3763
+ }
0 commit comments