This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#58 removed paragraph as it was overkill (KISS)
- Loading branch information
1 parent
7f2f5e5
commit c2736ac
Showing
6 changed files
with
136 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::ops::Range; | ||
|
||
use super::span::SpanToken; | ||
|
||
/// Represents a line of text. | ||
#[derive(Debug, Clone)] | ||
pub struct LineToken { | ||
span_ranges: Vec<SpanRange>, | ||
} | ||
|
||
impl LineToken { | ||
pub fn new(mut span_ranges: Vec<SpanRange>) -> Self { | ||
sort_span_ranges(&mut span_ranges); | ||
Self { span_ranges } | ||
} | ||
|
||
pub fn get_range(&self) -> Range<usize> { | ||
let start = self | ||
.span_ranges | ||
.first() | ||
.map(|sr| sr.range.start) | ||
.unwrap_or_default(); | ||
let end = self | ||
.span_ranges | ||
.last() | ||
.map(|sr| sr.range.end) | ||
.unwrap_or_default(); | ||
|
||
return start..end; | ||
} | ||
|
||
pub fn get_span_ranges(&self) -> &Vec<SpanRange> { | ||
&self.span_ranges | ||
} | ||
|
||
pub fn push_span_range(&mut self, span_range: SpanRange) { | ||
self.span_ranges.push(span_range); | ||
sort_span_ranges(&mut self.span_ranges); | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct SpanRange { | ||
index: usize, | ||
range: Range<usize>, | ||
} | ||
|
||
impl SpanRange { | ||
pub fn new(index: usize, range: Range<usize>) -> Self { | ||
Self { index, range } | ||
} | ||
|
||
pub fn from_span(index: usize, span: &SpanToken) -> Self { | ||
Self { | ||
index, | ||
range: span.get_range().clone(), | ||
} | ||
} | ||
} | ||
|
||
pub fn sort_span_ranges(span_ranges: &mut Vec<SpanRange>) { | ||
span_ranges.sort_by(|a, b| { | ||
// First, compare by index | ||
a.index | ||
.cmp(&b.index) | ||
// If indices are equal, compare by the ending point of the range | ||
.then_with(|| a.range.end.cmp(&b.range.end)) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
pub mod layout; | ||
pub mod line; | ||
pub mod shape; | ||
pub mod span; |