aboutsummaryrefslogtreecommitdiffstats
path: root/incdec.pm
diff options
context:
space:
mode:
authorTeddy Wing2021-08-15 20:02:42 +0200
committerTeddy Wing2021-08-15 20:02:42 +0200
commite256e34a9ccd735aca45a8e42d284b297e094b8f (patch)
treed11ec132f7b2a79d1a8f94bbd97dfe1145e9fd68 /incdec.pm
parentdf187d692c334fc16653f145f8bb0e6ba0ea268c (diff)
downloadreadline-incdec-e256e34a9ccd735aca45a8e42d284b297e094b8f.tar.bz2
incdec: Add comments describing the middle-of-number handling loop
Diffstat (limited to 'incdec.pm')
-rw-r--r--incdec.pm8
1 files changed, 8 insertions, 0 deletions
diff --git a/incdec.pm b/incdec.pm
index a400f7f..927ba92 100644
--- a/incdec.pm
+++ b/incdec.pm
@@ -17,13 +17,21 @@ sub incdec {
my $line_part = $line;
while ($point_position < length($line_part)) {
$line_part =~ /(\d+)/;
+
+ # If `$point_position` is within the matched number, we can stop.
if ($-[0] <= $point_position && $point_position < $+[0]) {
last;
}
+ # Continue the loop if point is further right than the end of the match.
if ($point_position >= $+[0]) {
+ # Store the line part that we don't increment so we can include it at the end.
$line_start .= substr($line_part, 0, $+[0]);
+
+ # Match starting in the next part of the string next iteration.
$line_part = substr($line_part, $+[0]);
+
+ # Adjust point position according to the new line part.
$point_position -= $+[0];
next;