diff --git a/tren.py b/tren.py index c9f1d80..105c65e 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.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 @@ -446,18 +446,35 @@ 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 + # Build a list of indexes to every occurence of the old string, + # taking case sensitivity into account - i = newname.find(old) - while i >= 0: - - oldstrings.append(i) + # 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: