aboutsummaryrefslogtreecommitdiffstats
path: root/incdec.pm
blob: f9397b541fbfe15839b9b3418dd28423076a7bfb (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use strict;
use warnings;

package incdec;

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

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

	my $original_point_position = $point_position;

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

			last;
		}

		if ($point_position >= $+[0]) {
			# repeat loop
			next;
		}
		else {
			last;
		}

		$line_part = substr $line_part, $point_position;
	}

	# my $line_part = substr $line, $point_position;

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

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

	# $line = $line_excluded . $line_part;

	# return $line;

	return $line_part;
}

1;