diff options
| author | Teddy Wing | 2021-08-15 01:50:56 +0200 |
|---|---|---|
| committer | Teddy Wing | 2021-08-15 01:50:56 +0200 |
| commit | 12d8440ec63b9d9fdcae337533e78eaaddc054a7 (patch) | |
| tree | f6038c484a1e2cceeb6fd9bcd6a6096ce4a6e6a9 | |
| parent | 366fa08af2817327d4cf17a3a1a73af4d2291893 (diff) | |
| download | readline-incdec-12d8440ec63b9d9fdcae337533e78eaaddc054a7.tar.bz2 | |
incdec: Idea for handling point within subsequent numbers
Previously, we only handled incrementing when point was in the middle of
the number if the number was the first on the line.
This is code from last week or so. Wasn't really analysing it. Don't
remember entirely. Currently, it loops infinitely on the fifth test.
| -rw-r--r-- | incdec.pm | 33 |
1 files changed, 26 insertions, 7 deletions
@@ -9,22 +9,41 @@ sub incdec { $point_position ||= 0; $is_backward ||= 0; + my $original_point_position = $point_position; + # If point is within a number, move it to ensure we match the whole number # rather than only part of its digits. - $line =~ /(\d+)/; - if ($-[0] <= $point_position && $point_position < $+[0]) { - $point_position = $-[0]; + my $line_part = $line; + while (1) { + $line_part =~ /(\d+)/; + if ($-[0] <= $point_position && $point_position < $+[0]) { + $point_position = $-[0]; + + last; + } + + if ($point_position >= $+[0]) { + # repeat loop + next; + } + else { + last; + } + + $line_part = substr $line_part, $point_position; } - my $line_part = substr $line, $point_position; + # my $line_part = substr $line, $point_position; $line_part =~ s/(\d+)/$1+1/e; - my $line_excluded = substr $line, 0, $point_position; + my $line_excluded = substr $line, 0, $original_point_position; + + # $line = $line_excluded . $line_part; - $line = $line_excluded . $line_part; + # return $line; - return $line; + return $line_part; } 1; |
