Added more bounds checking for individual replacement instance values.
1 parent 872e238 commit 89631de7844370e6c6706ee3fbc8fb91f9fe34aa
@tundra tundra authored on 26 Feb 2010
Showing 1 changed file
View
42
tren.py
 
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
 
# But only process the instances the user asked for
 
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).
# Substitute from R->L in original string