@@ -6,17 +6,19 @@ use std::{fmt, iter, ops};
6
6
/// An offset into text.
7
7
/// Offset is represented as `u32` storing number of utf8-bytes,
8
8
/// but most of the clients should treat it like opaque measure.
9
+ // BREAK: TextSize(u32)
9
10
#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash , Default ) ]
10
11
pub struct TextUnit ( u32 ) ;
11
12
12
13
impl TextUnit {
13
- //TODO: rename to `from_char`: this is not ocaml!
14
+ // BREAK: consider renaming?
14
15
/// `TextUnit` equal to the length of this char.
15
16
#[ inline( always) ]
16
17
pub fn of_char ( c : char ) -> TextUnit {
17
18
TextUnit ( c. len_utf8 ( ) as u32 )
18
19
}
19
20
21
+ // BREAK: consider renaming?
20
22
/// `TextUnit` equal to the length of this string.
21
23
///
22
24
/// # Panics
@@ -233,6 +235,8 @@ impl fmt::Display for TextRange {
233
235
}
234
236
235
237
impl TextRange {
238
+ // BREAK: TextRange::new(from..to)?
239
+ // BREAK: TextRange(from, to)?
236
240
/// The left-inclusive range (`[from..to)`) between to points in the text
237
241
#[ inline( always) ]
238
242
pub fn from_to ( from : TextUnit , to : TextUnit ) -> TextRange {
@@ -249,36 +253,41 @@ impl TextRange {
249
253
TextRange :: from_to ( offset, offset + len)
250
254
}
251
255
252
- // TODO : pass by value
256
+ // BREAK : pass by value
253
257
/// The inclusive start of this range
254
258
#[ inline( always) ]
255
259
pub fn start ( & self ) -> TextUnit {
256
260
self . start
257
261
}
258
262
263
+ // BREAK: pass by value
259
264
/// The exclusive end of this range
260
265
#[ inline( always) ]
261
266
pub fn end ( & self ) -> TextUnit {
262
267
self . end
263
268
}
264
269
270
+ // BREAK: pass by value
265
271
/// The length of this range
266
272
#[ inline( always) ]
267
273
pub fn len ( & self ) -> TextUnit {
268
274
self . end - self . start
269
275
}
270
276
277
+ // BREAK: pass by value
271
278
/// Is this range empty of any content?
272
279
#[ inline( always) ]
273
280
pub fn is_empty ( & self ) -> bool {
274
281
self . start ( ) == self . end ( )
275
282
}
276
283
284
+ // BREAK: pass by value
277
285
#[ inline( always) ]
278
286
pub fn is_subrange ( & self , other : & TextRange ) -> bool {
279
287
other. start ( ) <= self . start ( ) && self . end ( ) <= other. end ( )
280
288
}
281
289
290
+ // BREAK: pass by value
282
291
#[ inline( always) ]
283
292
pub fn intersection ( & self , other : & TextRange ) -> Option < TextRange > {
284
293
let start = self . start . max ( other. start ( ) ) ;
@@ -290,11 +299,13 @@ impl TextRange {
290
299
}
291
300
}
292
301
302
+ // BREAK: pass by value
293
303
#[ inline( always) ]
294
304
pub fn contains ( & self , offset : TextUnit ) -> bool {
295
305
self . start ( ) <= offset && offset < self . end ( )
296
306
}
297
307
308
+ // BREAK: pass by value
298
309
#[ inline( always) ]
299
310
pub fn contains_inclusive ( & self , offset : TextUnit ) -> bool {
300
311
self . start ( ) <= offset && offset <= self . end ( )
0 commit comments