Added code to observe reqested case sensitivity when renaming.
Added code to handle the case when the old replacement string is null.
1 parent d853b6c commit 272235be1628231049be0c457a0e9e3ec11d2d7e
@tundra tundra authored on 4 Feb 2010
Showing 1 changed file
View
58
tren.py
 
PROGNAME = "tren.py"
BASENAME = PROGNAME.split(".py")[0]
PROGENV = BASENAME.upper()
RCSID = "$Id: tren.py,v 1.141 2010/02/04 19:55:27 tundra Exp $"
RCSID = "$Id: tren.py,v 1.142 2010/02/05 03:00:24 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
for renrequest in self.RenRequests:
 
old, new = self.ResolveRenameStrings(renrequest[OLD], renrequest[NEW])
 
# Handle global vs. 1st occurence replacement
 
oldstrings = []
 
# Build a list of indexes to every occurence of the old string
 
i = newname.find(old)
while i >= 0:
 
oldstrings.append(i)
# Build a list of indexes to every occurence of the old string,
# taking case sensitivity into account
 
# Handle the case when old = "".
# This means to *replace the entire* old name with new.
i = newname.find(old, i + len(old))
if not old:
oldstrings = [0,]
newname = ""
 
# Handle case where an old is non-null
else:
name = newname
 
# Collapse case if requested
if not renrequest[CASESENSITIVE]:
 
name = name.lower()
old = old.lower()
 
i = name.find(old)
while i >= 0:
 
oldstrings.append(i)
i = name.find(old, i + len(old))
 
# If we found any maching strings, replace them
 
if oldstrings:
# Only process leftmost occurence if global replace is off