diff --git a/tren.py b/tren.py index d6df15d..beea8a1 100755 --- a/tren.py +++ b/tren.py @@ -8,7 +8,7 @@ PROGNAME = "tren.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -RCSID = "$Id: tren.py,v 1.159 2010/02/26 00:24:54 tundra Exp $" +RCSID = "$Id: tren.py,v 1.160 2010/02/26 06:40:00 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -489,15 +489,31 @@ todo = [] - # Handle single instance requests + # Handle single instance requests doing bounds checking as we go - if (renrequest[INSTANCEEND] == SINGLEINST) and (renrequest[INSTANCESTART] < len(oldstrings)): - todo.append(oldstrings[renrequest[INSTANCESTART]]) + start = renrequest[INSTANCESTART] + end = renrequest[INSTANCEEND] + + if (end == SINGLEINST): + + # Compute bounds for positive and negative indicies. + # This is necessary because positive indicies are 0-based, + # but negative indicies start at -1. + + bound = len(oldstrings) + + if start < 0: + bound += 1 + + # Now go get that entry + + if abs(start) < bound: + todo.append(oldstrings[start]) # Handle instance range requests else: - todo = oldstrings[renrequest[INSTANCESTART] : renrequest[INSTANCEEND]] + todo = oldstrings[start:end] # Replace selected substring(s).