aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2022-05-25 01:52:05 +0200
committerTeddy Wing2022-05-25 01:52:05 +0200
commitb42dc03982cd87ed10dbbc6d339004805fc39fd7 (patch)
tree68a2a1880694a72f4264f940128b3b0fa5d78409
parent3831218d3271133e176b07e0f19e0b16dd907491 (diff)
downloadreadline-incdec-b42dc03982cd87ed10dbbc6d339004805fc39fd7.tar.bz2
incdec.pm: Fix increment for single-digit zero at the end of the line
This just adds another "or" option to match a zero at the end of the string. Wonder if there's a nicer way to do this.
-rw-r--r--incdec.pm4
1 files changed, 2 insertions, 2 deletions
diff --git a/incdec.pm b/incdec.pm
index 8cc0b32..f35c963 100644
--- a/incdec.pm
+++ b/incdec.pm
@@ -30,7 +30,7 @@ sub incdec {
my $start_position = 0;
my $previous_match_start = 0;
my $i = 0;
- while ($line =~ /(-?([1-9]\d*|0\D))/g) {
+ while ($line =~ /(-?([1-9]\d*|0\D|0$))/g) {
if ($is_backward) {
# Set start position to the current match start. This gives us the
# correct start position when incrementing the last number in a
@@ -64,7 +64,7 @@ sub incdec {
}
pos($line) = $start_position;
- $line =~ s/\G(-?([1-9]\d*|0\D))/$1 + $increment_by/e;
+ $line =~ s/\G(-?([1-9]\d*|0\D|0$))/$1 + $increment_by/e;
return ($line, $start_position);
}