App-Sandy
view release on metacpan or search on metacpan
lib/App/Sandy/PieceTable.pm view on Meta::CPAN
my ($end1, $end2) = ($start1 + $len1 - 1, $start2 + $len2 - 1);
return $start1 <= $end2 && $start2 <= $end1;
}
sub _split_piece {
my ($self, $pos) = @_;
# Catch orig index where pos is inside
my $index = $self->_piece_at($pos);
# Get piece which will be updated
my $old_piece = $self->_get_piece($index);
# Split at the beggining of a piece,
# or this piece has length 1
if ($pos == $old_piece->{start}) {
return $index;
}
# Calculate piece end
my $old_end = $old_piece->{start} + $old_piece->{len} - 1;
lib/App/Sandy/PieceTable.pm view on Meta::CPAN
# Calculate the corrected length according to the split
my $new_len = $pos - $old_piece->{start};
# Update piece
$old_piece->{len} = $new_len;
# Create the second part of the split after the break position
my $piece = $self->_piece_new($old_piece->{ref}, $old_piece->{is_orig},
$pos, $old_end - $pos + 1, $pos);
# Insert second part after updated piece
$self->_splice_piece(++$index, 0, $piece);
# return corrected index that resolves to
# the position between the breaked piece
return $index;
}
sub _is_pos_inside_range {
my ($self, $pos, $start, $len) = @_;
my $end = $start + $len - 1;
( run in 0.247 second using v1.01-cache-2.11-cpan-05444aca049 )