aboutsummaryrefslogtreecommitdiffstats
path: root/incdec.pm
diff options
context:
space:
mode:
authorTeddy Wing2021-08-21 21:12:39 +0200
committerTeddy Wing2021-08-21 21:13:59 +0200
commit54218fbf53e7077fdd3740456be434893253b183 (patch)
tree861e960eb7b8160cade31f37f7dd2c5559dc1389 /incdec.pm
parent9ef2e03beda0e9084a8d871ab433ffdd2b0a70fc (diff)
downloadreadline-incdec-54218fbf53e7077fdd3740456be434893253b183.tar.bz2
incdec.pm: Handle negative numbers
Include "-" in the pattern that matches numbers. Wrap the pattern in word boundaries also. This passes the test I added previously to increment a negative number.
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 5168aac..23bb545 100644
--- a/incdec.pm
+++ b/incdec.pm
@@ -13,7 +13,7 @@ sub incdec {
# my @match_ranges;
my $previous_match_start = 0;
# my $previous_match_end = 0;
- while ($line =~ /(\d+)/g) {
+ while ($line =~ /\b(-?\d+)\b/g) {
if ($is_backward) {
# print "p[$point_position] -[$-[0]] +[$+[0]]\n";
# print "p[$point_position] -[$previous_match_start] +[$previous_match_end]\n";
@@ -48,7 +48,7 @@ sub incdec {
}
pos($line) = $start_position;
- $line =~ s/\G([^\d]*)(\d+)/$1 . ($2 + $increment_by)/e;
+ $line =~ s/\G([^-\d]*)(-?\d+)/$1 . ($2 + $increment_by)/e;
return $line;
}