@@ -43,15 +43,16 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
43
43
if i != 0 || j != lines. len ( ) { Some ( ( i, j) ) } else { None }
44
44
}
45
45
46
- fn get_horizontal_trim ( lines : & [ & str ] , kind : CommentKind ) -> Option < usize > {
46
+ fn get_horizontal_trim < ' a > ( lines : & ' a [ & str ] , kind : CommentKind ) -> Option < String > {
47
47
let mut i = usize:: MAX ;
48
48
let mut first = true ;
49
49
50
50
// In case we have doc comments like `/**` or `/*!`, we want to remove stars if they are
51
51
// present. However, we first need to strip the empty lines so they don't get in the middle
52
52
// when we try to compute the "horizontal trim".
53
53
let lines = if kind == CommentKind :: Block {
54
- let mut i = 0 ;
54
+ // Whatever happens, we skip the first line.
55
+ let mut i = if lines[ 0 ] . trim_start ( ) . starts_with ( '*' ) { 0 } else { 1 } ;
55
56
let mut j = lines. len ( ) ;
56
57
57
58
while i < j && lines[ i] . trim ( ) . is_empty ( ) {
@@ -84,7 +85,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
84
85
return None ;
85
86
}
86
87
}
87
- Some ( i )
88
+ if lines . is_empty ( ) { None } else { Some ( lines [ 0 ] [ ..i ] . into ( ) ) }
88
89
}
89
90
90
91
let data_s = data. as_str ( ) ;
@@ -102,8 +103,13 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
102
103
changes = true ;
103
104
// remove a "[ \t]*\*" block from each line, if possible
104
105
for line in lines. iter_mut ( ) {
105
- if horizontal + 1 < line. len ( ) {
106
- * line = & line[ horizontal + 1 ..] ;
106
+ if let Some ( tmp) = line. strip_prefix ( & horizontal) {
107
+ * line = tmp;
108
+ if kind == CommentKind :: Block
109
+ && ( * line == "*" || line. starts_with ( "* " ) || line. starts_with ( "**" ) )
110
+ {
111
+ * line = & line[ 1 ..] ;
112
+ }
107
113
}
108
114
}
109
115
}
0 commit comments