File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -633,6 +633,24 @@ impl SourceMap {
633
633
sp
634
634
}
635
635
636
+ /// Extends the given `Span` to just before the previous occurrence of `c`. Return the same span
637
+ /// if an error occurred while retrieving the code snippet.
638
+ pub fn span_extend_to_prev_char_before (
639
+ & self ,
640
+ sp : Span ,
641
+ c : char ,
642
+ accept_newlines : bool ,
643
+ ) -> Span {
644
+ if let Ok ( prev_source) = self . span_to_prev_source ( sp) {
645
+ let prev_source = prev_source. rsplit ( c) . next ( ) . unwrap_or ( "" ) ;
646
+ if accept_newlines || !prev_source. contains ( '\n' ) {
647
+ return sp. with_lo ( BytePos ( sp. lo ( ) . 0 - prev_source. len ( ) as u32 - 1_u32 ) ) ;
648
+ }
649
+ }
650
+
651
+ sp
652
+ }
653
+
636
654
/// Extends the given `Span` to just after the previous occurrence of `pat` when surrounded by
637
655
/// whitespace. Returns None if the pattern could not be found or if an error occurred while
638
656
/// retrieving the code snippet.
You can’t perform that action at this time.
0 commit comments