@@ -157,33 +157,9 @@ impl LineIndex {
157
157
158
158
/// Transforms the `LineCol` with the given `WideEncoding` into a `WideLineCol`.
159
159
pub fn to_wide ( & self , enc : WideEncoding , line_col : LineCol ) -> Option < WideLineCol > {
160
- let col = self . utf8_to_wide_col ( enc, line_col. line , line_col. col . into ( ) ) ;
161
- Some ( WideLineCol { line : line_col. line , col : col as u32 } )
162
- }
163
-
164
- /// Transforms the `WideLineCol` with the given `WideEncoding` into a `LineCol`.
165
- pub fn to_utf8 ( & self , enc : WideEncoding , line_col : WideLineCol ) -> Option < LineCol > {
166
- let col = self . wide_to_utf8_col ( enc, line_col. line , line_col. col ) ;
167
- Some ( LineCol { line : line_col. line , col : col. into ( ) } )
168
- }
169
-
170
- /// Returns an iterator over the ranges for the lines.
171
- pub fn lines ( & self , range : TextRange ) -> impl Iterator < Item = TextRange > + ' _ {
172
- let lo = self . newlines . partition_point ( |& it| it < range. start ( ) ) ;
173
- let hi = self . newlines . partition_point ( |& it| it <= range. end ( ) ) ;
174
- let all = std:: iter:: once ( range. start ( ) )
175
- . chain ( self . newlines [ lo..hi] . iter ( ) . copied ( ) )
176
- . chain ( std:: iter:: once ( range. end ( ) ) ) ;
177
-
178
- all. clone ( )
179
- . zip ( all. skip ( 1 ) )
180
- . map ( |( lo, hi) | TextRange :: new ( lo, hi) )
181
- . filter ( |it| !it. is_empty ( ) )
182
- }
183
-
184
- fn utf8_to_wide_col ( & self , enc : WideEncoding , line : u32 , col : TextSize ) -> usize {
160
+ let col: TextSize = line_col. col . into ( ) ;
185
161
let mut res: usize = col. into ( ) ;
186
- if let Some ( wide_chars) = self . line_wide_chars . get ( & line) {
162
+ if let Some ( wide_chars) = self . line_wide_chars . get ( & line_col . line ) {
187
163
for c in wide_chars. iter ( ) {
188
164
if c. end <= col {
189
165
res -= usize:: from ( c. len ( ) ) - c. wide_len ( enc) ;
@@ -194,11 +170,13 @@ impl LineIndex {
194
170
}
195
171
}
196
172
}
197
- res
173
+ Some ( WideLineCol { line : line_col . line , col : res as u32 } )
198
174
}
199
175
200
- fn wide_to_utf8_col ( & self , enc : WideEncoding , line : u32 , mut col : u32 ) -> TextSize {
201
- if let Some ( wide_chars) = self . line_wide_chars . get ( & line) {
176
+ /// Transforms the `WideLineCol` with the given `WideEncoding` into a `LineCol`.
177
+ pub fn to_utf8 ( & self , enc : WideEncoding , line_col : WideLineCol ) -> Option < LineCol > {
178
+ let mut col = line_col. col ;
179
+ if let Some ( wide_chars) = self . line_wide_chars . get ( & line_col. line ) {
202
180
for c in wide_chars. iter ( ) {
203
181
if col > u32:: from ( c. start ) {
204
182
col += u32:: from ( c. len ( ) ) - c. wide_len ( enc) as u32 ;
@@ -209,7 +187,20 @@ impl LineIndex {
209
187
}
210
188
}
211
189
}
190
+ Some ( LineCol { line : line_col. line , col : col. into ( ) } )
191
+ }
192
+
193
+ /// Returns an iterator over the ranges for the lines.
194
+ pub fn lines ( & self , range : TextRange ) -> impl Iterator < Item = TextRange > + ' _ {
195
+ let lo = self . newlines . partition_point ( |& it| it < range. start ( ) ) ;
196
+ let hi = self . newlines . partition_point ( |& it| it <= range. end ( ) ) ;
197
+ let all = std:: iter:: once ( range. start ( ) )
198
+ . chain ( self . newlines [ lo..hi] . iter ( ) . copied ( ) )
199
+ . chain ( std:: iter:: once ( range. end ( ) ) ) ;
212
200
213
- col. into ( )
201
+ all. clone ( )
202
+ . zip ( all. skip ( 1 ) )
203
+ . map ( |( lo, hi) | TextRange :: new ( lo, hi) )
204
+ . filter ( |it| !it. is_empty ( ) )
214
205
}
215
206
}
0 commit comments