@@ -139,7 +139,7 @@ impl<'i> Position<'i> {
139139 panic ! ( "position out of bounds" ) ;
140140 }
141141
142- line_col ( self . input , self . pos )
142+ line_col ( self . input , self . pos , ( 1 , 1 ) )
143143 }
144144
145145 /// Returns the entire line of the input that contains this `Position`.
@@ -452,25 +452,30 @@ impl<'i> Hash for Position<'i> {
452452 }
453453}
454454
455- pub ( crate ) fn line_col ( input : & str , pos : usize ) -> ( usize , usize ) {
455+ /// Returns the line and column of the given `pos` in `input`.
456+ pub ( crate ) fn line_col ( input : & str , pos : usize , start : ( usize , usize ) ) -> ( usize , usize ) {
456457 #[ cfg( feature = "fast-line-col" ) ]
457458 {
458- fast_line_col ( input, pos)
459+ fast_line_col ( input, pos, start )
459460 }
460461 #[ cfg( not( feature = "fast-line-col" ) ) ]
461462 {
462- original_line_col ( input, pos)
463+ original_line_col ( input, pos, start )
463464 }
464465}
465466
466467#[ inline]
467468#[ cfg( not( feature = "fast-line-col" ) ) ]
468- fn original_line_col ( input : & str , mut pos : usize ) -> ( usize , usize ) {
469+ pub ( crate ) fn original_line_col (
470+ input : & str ,
471+ mut pos : usize ,
472+ start : ( usize , usize ) ,
473+ ) -> ( usize , usize ) {
469474 // Position's pos is always a UTF-8 border.
470475 let slice = & input[ ..pos] ;
471476 let mut chars = slice. chars ( ) . peekable ( ) ;
472477
473- let mut line_col = ( 1 , 1 ) ;
478+ let mut line_col = start ;
474479
475480 while pos != 0 {
476481 match chars. next ( ) {
@@ -507,16 +512,16 @@ fn original_line_col(input: &str, mut pos: usize) -> (usize, usize) {
507512
508513#[ inline]
509514#[ cfg( feature = "fast-line-col" ) ]
510- fn fast_line_col ( input : & str , pos : usize ) -> ( usize , usize ) {
515+ fn fast_line_col ( input : & str , pos : usize , start : ( usize , usize ) ) -> ( usize , usize ) {
511516 // Position's pos is always a UTF-8 border.
512517 let slice = & input[ ..pos] ;
513518
514519 let prec_ln = memchr:: memrchr ( b'\n' , slice. as_bytes ( ) ) ;
515520 if let Some ( prec_nl_pos) = prec_ln {
516- let lines = bytecount:: count ( slice[ ..=prec_nl_pos] . as_bytes ( ) , b'\n' ) + 1 ;
521+ let lines = bytecount:: count ( slice[ ..=prec_nl_pos] . as_bytes ( ) , b'\n' ) + start . 0 ;
517522 ( lines, slice[ prec_nl_pos..] . chars ( ) . count ( ) )
518523 } else {
519- ( 1 , slice. chars ( ) . count ( ) + 1 )
524+ ( start . 0 , slice. chars ( ) . count ( ) + start . 1 )
520525 }
521526}
522527
0 commit comments