Skip to content

Commit

Permalink
feat(span): add to_str_range for TextSpan (#6122)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLucqs authored and orizi committed Aug 13, 2024
1 parent cb47d69 commit aec1559
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/cairo-lang-filesystem/src/span.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::iter::Sum;
use std::ops::{Add, Sub};
use std::ops::{Add, Range, Sub};

use crate::db::FilesGroup;
use crate::ids::FileId;
Expand Down Expand Up @@ -94,6 +94,11 @@ impl TextSpan {
Self { start: self.start, end: self.start }
}

/// Returns self.start..self.end as [`Range<usize>`]
pub fn to_str_range(&self) -> Range<usize> {
self.start.0.0 as usize..self.end.0.0 as usize
}

/// Convert this span to a [`TextPositionSpan`] in the file.
pub fn position_in_file(self, db: &dyn FilesGroup, file: FileId) -> Option<TextPositionSpan> {
let start = self.start.position_in_file(db, file)?;
Expand Down

0 comments on commit aec1559

Please sign in to comment.