aboutsummaryrefslogtreecommitdiffstats
path: root/incdec.bash
diff options
context:
space:
mode:
authorTeddy Wing2022-05-26 16:55:58 +0200
committerTeddy Wing2022-05-26 16:55:58 +0200
commitbf6544d5be555686c63f3da3fa500a1f8b8d5fe9 (patch)
tree00e338a64ebc408508aa2665846ffbfcf0bdd226 /incdec.bash
parent419f4cdec4c13c62c8c365a24ee5c59b59c66fdd (diff)
parent1cb9ad7286b87c348861dafd112a73901e4d6358 (diff)
downloadreadline-incdec-bf6544d5be555686c63f3da3fa500a1f8b8d5fe9.tar.bz2
Merge branch 'keep-leading-zeros'
Diffstat (limited to 'incdec.bash')
-rw-r--r--incdec.bash8
1 files changed, 5 insertions, 3 deletions
diff --git a/incdec.bash b/incdec.bash
index 338afae..f364c0f 100644
--- a/incdec.bash
+++ b/incdec.bash
@@ -1,4 +1,4 @@
-# Copyright (c) 2021 Teddy Wing
+# Copyright (c) 2021–2022 Teddy Wing
#
# This file is part of Incdec.
#
@@ -30,10 +30,12 @@ sub incdec {
$point_position ||= 0;
$is_backward ||= 0;
+ my $number_regex = '-?([1-9]\d*|0\D|0$)';
+
my $start_position = 0;
my $previous_match_start = 0;
my $i = 0;
- while ($line =~ /(-?\d+)/g) {
+ while ($line =~ /($number_regex)/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
@@ -67,7 +69,7 @@ sub incdec {
}
pos($line) = $start_position;
- $line =~ s/\G(-?\d+)/$1 + $increment_by/e;
+ $line =~ s/\G($number_regex)/$1 + $increment_by/e;
return ($line, $start_position);
}