aboutsummaryrefslogtreecommitdiffstats
path: root/incdec.pm
diff options
context:
space:
mode:
authorTeddy Wing2021-08-19 21:57:59 +0200
committerTeddy Wing2021-08-19 21:57:59 +0200
commit016240388e39c58b2d0bba118e4c1a1a52011cee (patch)
tree5a1d66648259ace1179df0dae0ee97c123c4be18 /incdec.pm
parent463490a1857274ebf5b488c38e1a280a4d9b7669 (diff)
downloadreadline-incdec-016240388e39c58b2d0bba118e4c1a1a52011cee.tar.bz2
incdec: Add increment step argument
A new subrouting argument that defines by how much the number should be incremented, or decremented if a negative step value is given. Add a few new tests to verify the decrementing behaviour. The final test where point is in the middle of the number fails.
Diffstat (limited to 'incdec.pm')
-rw-r--r--incdec.pm4
1 files changed, 2 insertions, 2 deletions
diff --git a/incdec.pm b/incdec.pm
index f13209b..b810bf4 100644
--- a/incdec.pm
+++ b/incdec.pm
@@ -4,7 +4,7 @@ use warnings;
package incdec;
sub incdec {
- my ($line, $point_position, $is_backward) = @_;
+ my ($line, $increment_by, $point_position, $is_backward) = @_;
$point_position ||= 0;
$is_backward ||= 0;
@@ -38,7 +38,7 @@ sub incdec {
}
pos($line) = $start_position;
- $line =~ s/\G([^\d]*)(\d+)/$1 . ($2 + 1)/e;
+ $line =~ s/\G([^\d]*)(\d+)/$1 . ($2 + $increment_by)/e;
return $line;
}