aboutsummaryrefslogtreecommitdiffstats
path: root/incdec.pm
blob: d4b1460c59d20ded40d387444bb450624d6c4dbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use strict;
use warnings;

package incdec;

sub incdec {
	my ($line, $point_position, $is_backward) = @_;

	$point_position ||= 0;
	$is_backward ||= 0;

	# If point is within a number, move it to ensure we match the whole number
	# rather than only part of its digits.
	$line =~ /(\d+)/;
	if ($-[0] <= $point_position && $point_position < $+[0]) {
		$point_position = $-[0];
	}

	my $line_part = substr $line, $point_position;

	$line_part =~ s/(\d+)/$1+1/e;

	my $line_excluded = substr $line, 0, $point_position;

	$line = $line_excluded . $line_part;

	return $line;
}

1;