diff --git a/tren.py b/tren.py index 01f593d..d6df15d 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.158 2010/02/26 00:08:44 tundra Exp $" +RCSID = "$Id: tren.py,v 1.159 2010/02/26 00:24:54 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -485,17 +485,27 @@ if oldstrings: - # Only process leftmost occurence if global replace is off + # But only process the instances the user asked for - if not renrequest[DEFINST]: - oldstrings = [oldstrings[0],] + todo = [] + + # Handle single instance requests + + if (renrequest[INSTANCEEND] == SINGLEINST) and (renrequest[INSTANCESTART] < len(oldstrings)): + todo.append(oldstrings[renrequest[INSTANCESTART]]) + + # Handle instance range requests + + else: + todo = oldstrings[renrequest[INSTANCESTART] : renrequest[INSTANCEEND]] + # Replace selected substring(s). # Substitute from R->L in original string # so as not to mess up the replacement indicies. - oldstrings.reverse() - for i in oldstrings: + todo.reverse() + for i in todo: newname = newname[:i] + new + newname[i + len(old):]