diff options
| author | Teddy Wing | 2021-08-21 21:12:39 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2021-08-21 21:13:59 +0200 | 
| commit | 54218fbf53e7077fdd3740456be434893253b183 (patch) | |
| tree | 861e960eb7b8160cade31f37f7dd2c5559dc1389 /incdec.pm | |
| parent | 9ef2e03beda0e9084a8d871ab433ffdd2b0a70fc (diff) | |
| download | readline-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.pm | 4 | 
1 files changed, 2 insertions, 2 deletions
| @@ -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;  } | 
