Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

Support the use of a length field for Range #12

Merged
merged 2 commits into from
Apr 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pub struct Range<I: Indexed> {
pub row_end: Row<I>,
pub col_start: Column<I>,
pub col_end: Column<I>,
pub len: Option<u64>,
}

impl<I: Indexed> Range<I> {
Expand All @@ -225,6 +226,22 @@ impl<I: Indexed> Range<I> {
row_end: row_end,
col_start: col_start,
col_end: col_end,
len: None
}
}

pub fn new_with_len(row_start: Row<I>,
row_end: Row<I>,
col_start: Column<I>,
col_end: Column<I>,
len: u64)
-> Range<I> {
Range {
row_start: row_start,
row_end: row_end,
col_start: col_start,
col_end: col_end,
len: Some(len)
}
}

Expand All @@ -236,6 +253,20 @@ impl<I: Indexed> Range<I> {
row_end: end.row,
col_start: start.col,
col_end: end.col,
len: None,
}
}

pub fn from_positions_with_len(start: Position<I>,
end: Position<I>,
len: u64)
-> Range<I> {
Range {
row_start: start.row,
row_end: end.row,
col_start: start.col,
col_end: end.col,
len: Some(len),
}
}

Expand Down Expand Up @@ -269,6 +300,7 @@ impl Range<OneIndexed> {
row_end: self.row_end.zero_indexed(),
col_start: self.col_start.zero_indexed(),
col_end: self.col_end.zero_indexed(),
len: None
}
}
}
Expand All @@ -280,6 +312,7 @@ impl Range<ZeroIndexed> {
row_end: self.row_end.one_indexed(),
col_start: self.col_start.one_indexed(),
col_end: self.col_end.one_indexed(),
len: None,
}
}
}
Expand Down Expand Up @@ -364,6 +397,7 @@ impl<I: Indexed> Span<I> {
row_end: row_end,
col_start: col_start,
col_end: col_end,
len: None,
},
file: file.into(),
}
Expand Down