@@ -940,9 +940,20 @@ impl<'a> CursorLines<'a> {
940
940
941
941
#[ derive( Copy , Clone , Debug , PartialEq ) ]
942
942
pub ( crate ) enum EndLine {
943
- Eof = 0 ,
944
- Crlf = 1 ,
945
- Lf = 2 ,
943
+ Eof ,
944
+ Lf ,
945
+ Crlf ,
946
+ }
947
+
948
+ impl EndLine {
949
+ /// The number of characters this line ending occupies in bytes.
950
+ pub ( crate ) fn len ( self ) -> usize {
951
+ match self {
952
+ EndLine :: Eof => 0 ,
953
+ EndLine :: Lf => 1 ,
954
+ EndLine :: Crlf => 2 ,
955
+ }
956
+ }
946
957
}
947
958
948
959
impl < ' a > Iterator for CursorLines < ' a > {
@@ -957,12 +968,12 @@ impl<'a> Iterator for CursorLines<'a> {
957
968
. map ( |x| {
958
969
let ret = if 0 < x {
959
970
if self . 0 . as_bytes ( ) [ x - 1 ] == b'\r' {
960
- ( & self . 0 [ ..x - 1 ] , EndLine :: Lf )
971
+ ( & self . 0 [ ..x - 1 ] , EndLine :: Crlf )
961
972
} else {
962
- ( & self . 0 [ ..x] , EndLine :: Crlf )
973
+ ( & self . 0 [ ..x] , EndLine :: Lf )
963
974
}
964
975
} else {
965
- ( "" , EndLine :: Crlf )
976
+ ( "" , EndLine :: Lf )
966
977
} ;
967
978
self . 0 = & self . 0 [ x + 1 ..] ;
968
979
ret
@@ -1138,7 +1149,7 @@ fn format_header<'a>(
1138
1149
..
1139
1150
} = item
1140
1151
{
1141
- if main_range >= range. 0 && main_range <= range. 1 + * end_line as usize {
1152
+ if main_range >= range. 0 && main_range <= range. 1 + end_line. len ( ) {
1142
1153
let char_column = text[ 0 ..( main_range - range. 0 ) . min ( text. len ( ) ) ]
1143
1154
. chars ( )
1144
1155
. count ( ) ;
@@ -1366,7 +1377,7 @@ fn format_body(
1366
1377
for ( idx, ( line, end_line) ) in CursorLines :: new ( snippet. source ) . enumerate ( ) {
1367
1378
let line_length: usize = line. len ( ) ;
1368
1379
let line_range = ( current_index, current_index + line_length) ;
1369
- let end_line_size = end_line as usize ;
1380
+ let end_line_size = end_line. len ( ) ;
1370
1381
body. push ( DisplayLine :: Source {
1371
1382
lineno : Some ( current_line) ,
1372
1383
inline_marks : vec ! [ ] ,
0 commit comments