Retooled the renaming algorithm in preparation for adding case-insensitivity.
1 parent 0b822b7 commit d853b6cdfa43c0f39f457a96eef09bebac0d7ee0
@tundra tundra authored on 4 Feb 2010
Showing 1 changed file
View
50
tren.py
 
PROGNAME = "tren.py"
BASENAME = PROGNAME.split(".py")[0]
PROGENV = BASENAME.upper()
RCSID = "$Id: tren.py,v 1.140 2010/02/03 23:56:38 tundra Exp $"
RCSID = "$Id: tren.py,v 1.141 2010/02/04 19:55:27 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
old, new = self.ResolveRenameStrings(renrequest[OLD], renrequest[NEW])
 
# Handle global vs. 1st occurence replacement
 
if renrequest[GLOBAL]:
newname = newname.replace(old, new)
 
else:
i = newname.find(old)
if i >= 0:
oldstrings = []
 
# Build a list of indexes to every occurence of the old string
 
i = newname.find(old)
while i >= 0:
 
oldstrings.append(i)
i = newname.find(old, i + len(old))
 
if oldstrings:
# Only process leftmost occurence if global replace is off
 
if not renrequest[GLOBAL]:
oldstrings = [oldstrings[0],]
 
# 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:
newname = newname[:i] + new + newname[i + len(old):]
 
print ColumnPad([target, pathname + newname], padwidth = 50)