#OTHER by mawalch
authormawalch
Thu, 30 Jun 2016 14:27:07 +0200
changeset 5143 0162f8ec658a
parent 5142 aff1f7d34b8a
child 5144 e3c1660ebede
#OTHER by mawalch class: DoWhatIMeanSupport changed: #goodRenameDefaultFor:lastOld:lastNew: endless recursion
DoWhatIMeanSupport.st
--- a/DoWhatIMeanSupport.st	Thu Jun 30 11:01:49 2016 +0200
+++ b/DoWhatIMeanSupport.st	Thu Jun 30 14:27:07 2016 +0200
@@ -829,144 +829,142 @@
     lastOldSize := lastOldName size.
 
     (lastNewName endsWith:lastOldName) ifTrue:[
-	"last rename was
-	    'foo' -> 'Xfoo'
-	 then, a good default for
-	    'bar' would be 'Xbar'
-	"
-	prefix := lastNewName copyTo:(lastNewSize - lastOldSize).
-	^ (prefix , oldName).
+        "last rename was
+            'foo' -> 'Xfoo'
+         then, a good default for
+            'bar' would be 'Xbar'
+        "
+        prefix := lastNewName copyTo:(lastNewSize - lastOldSize).
+        ^ (prefix , oldName).
     ].
     (lastOldName endsWith:lastNewName) ifTrue:[
-	"last rename was
-	    'Xfoo' -> 'foo'
-	 then, a good default for
-	    'Xbar' would be 'bar'
-	"
-	prefix := lastOldName copyTo:(lastOldSize - lastNewSize).
-	(oldName startsWith:prefix) ifTrue:[
-	    ^ (oldName copyFrom:prefix size+1).
-	]
+        "last rename was
+            'Xfoo' -> 'foo'
+         then, a good default for
+            'Xbar' would be 'bar'
+        "
+        prefix := lastOldName copyTo:(lastOldSize - lastNewSize).
+        (oldName startsWith:prefix) ifTrue:[
+            ^ (oldName copyFrom:prefix size+1).
+        ]
     ].
     (lastOldName asLowercase = lastNewName asLowercase) ifTrue:[
-	(lastOldName first ~= lastNewName first) ifTrue:[
-	    (lastOldName first isLowercase = oldName first isLowercase) ifTrue:[
-		"last rename was
-		    'xfoo' -> 'Xfoo'
-		 then, a good default for
-		    'xbar' would be 'Xbar'
-		"
-		lastOldName first isLowercase ifTrue:[
-		    ^ oldName asUppercaseFirst "oldName first asUppercase asString , (oldName copyFrom:2)".
-		] ifFalse:[
-		    ^ oldName asLowercaseFirst "oldName first asLowercase asString , (oldName copyFrom:2)".
-		]
-	    ]
-	].
+        (lastOldName first ~= lastNewName first) ifTrue:[
+            (lastOldName first isLowercase = oldName first isLowercase) ifTrue:[
+                "last rename was
+                    'xfoo' -> 'Xfoo'
+                 then, a good default for
+                    'xbar' would be 'Xbar'
+                "
+                lastOldName first isLowercase ifTrue:[
+                    ^ oldName asUppercaseFirst "oldName first asUppercase asString , (oldName copyFrom:2)".
+                ] ifFalse:[
+                    ^ oldName asLowercaseFirst "oldName first asLowercase asString , (oldName copyFrom:2)".
+                ]
+            ]
+        ].
     ].
     (lastOldName withoutSeparators = lastNewName) ifTrue:[
-	"last rename was
-	    '  foo   ' -> 'foo'
-	 then, a good default for
-	    '  bar   ' would be 'bar'
-	"
-	^ oldName withoutSeparators.
+        "last rename was
+            '  foo   ' -> 'foo'
+         then, a good default for
+            '  bar   ' would be 'bar'
+        "
+        ^ oldName withoutSeparators.
     ].
     (lastNewName startsWith:lastOldName) ifTrue:[
-	"last rename was
-	    'foo' -> 'fooX'
-	 then, a good default for
-	    'bar' would be 'barX'
-	"
-	suffix := lastNewName copyLast:(lastNewSize - lastOldSize).
-	^ (oldName , suffix).
+        "last rename was
+            'foo' -> 'fooX'
+         then, a good default for
+            'bar' would be 'barX'
+        "
+        suffix := lastNewName copyLast:(lastNewSize - lastOldSize).
+        ^ (oldName , suffix).
     ].
     (lastOldName startsWith:lastNewName) ifTrue:[
-	"last rename was
-	    'fooX' -> 'foo'
-	 then, a good default for
-	    'barX' would be 'bar'
-	"
-	suffix := lastOldName copyLast:(lastOldSize - lastNewSize).
-	(oldName endsWith:suffix) ifTrue:[
-	    ^ (oldName copyButLast:suffix size).
-	]
+        "last rename was
+            'fooX' -> 'foo'
+         then, a good default for
+            'barX' would be 'bar'
+        "
+        suffix := lastOldName copyLast:(lastOldSize - lastNewSize).
+        (oldName endsWith:suffix) ifTrue:[
+            ^ (oldName copyButLast:suffix size).
+        ]
     ].
 
     prefix := lastOldName commonPrefixWith:lastNewName.
     suffix := lastOldName commonSuffixWith:lastNewName.
 
     (prefix size > 0) ifTrue:[
-	(suffix size > 0) ifTrue:[
-
-	    prefix := prefix copyTo:(((lastNewName size - suffix size) min:(lastOldName size - suffix size)) min:prefix size).
-
-	    "last rename was
-		'fooR' -> 'fooXR'
-	     then, a good default for
-		'barR' would be 'barXR'
-	    "
-	    left := lastOldName copyTo:prefix size.
-	    right := lastOldName copyLast:suffix size.
-	    lastNewSize > lastOldSize ifTrue:[
-		inserted := (lastNewName copyFrom:(left size + 1)) copyButLast:(right size).
-		inserted size > 0 ifTrue:[
-		    (oldName startsWith:prefix) ifTrue:[
-			^ oldName copyWithAll:inserted insertedAfterIndex:prefix size
-		    ].
-		].
-	    ].
-	    (oldName string endsWith:suffix string) ifTrue:[
-		deleted := (lastOldName string copyFrom:(prefix size + 1)) copyButLast:(suffix size).
-		(oldName size-suffix size-deleted size + 1) >= 1 ifTrue:[
-		    ((oldName copyFrom:oldName size-suffix size-deleted size + 1) copyTo:deleted size) = deleted ifTrue:[
-			"last rename was
-			    'fooXR' -> 'fooR'
-			 then, a good default for
-			    'barXS' would be 'barS'
-			"
-			^ (oldName copyTo:oldName size-suffix size-deleted size) , suffix
-		    ]
-		]
-	    ]
-	].
-
-	(oldName endsWith:(lastOldName copyFrom:prefix size+1)) ifTrue:[
-	    "last rename was
-		'fooX' -> 'fooY'
-	     then, a good default for
-		'barX' would be 'barY'
-	    "
-	    left := oldName copyButLast:(lastOldName copyFrom:prefix size+1) size.
-	    right := lastNewName copyFrom:prefix size+1.
-	    ^ left , right
-	]
+        (suffix size > 0) ifTrue:[
+
+            prefix := prefix copyTo:(((lastNewName size - suffix size) min:(lastOldName size - suffix size)) min:prefix size).
+
+            "last rename was
+                'fooR' -> 'fooXR'
+             then, a good default for
+                'barR' would be 'barXR'
+            "
+            left := lastOldName copyTo:prefix size.
+            right := lastOldName copyLast:suffix size.
+            lastNewSize > lastOldSize ifTrue:[
+                inserted := (lastNewName copyFrom:(left size + 1)) copyButLast:(right size).
+                inserted size > 0 ifTrue:[
+                    (oldName startsWith:prefix) ifTrue:[
+                        ^ oldName copyWithAll:inserted insertedAfterIndex:prefix size
+                    ].
+                ].
+            ].
+            (oldName string endsWith:suffix string) ifTrue:[
+                deleted := (lastOldName string copyFrom:(prefix size + 1)) copyButLast:(suffix size).
+                (oldName size-suffix size-deleted size + 1) >= 1 ifTrue:[
+                    ((oldName copyFrom:oldName size-suffix size-deleted size + 1) copyTo:deleted size) = deleted ifTrue:[
+                        "last rename was
+                            'fooXR' -> 'fooR'
+                         then, a good default for
+                            'barXS' would be 'barS'
+                        "
+                        ^ (oldName copyTo:oldName size-suffix size-deleted size) , suffix
+                    ]
+                ]
+            ]
+        ].
+
+        (oldName endsWith:(lastOldName copyFrom:prefix size+1)) ifTrue:[
+            "last rename was
+                'fooX' -> 'fooY'
+             then, a good default for
+                'barX' would be 'barY'
+            "
+            left := oldName copyButLast:(lastOldName copyFrom:prefix size+1) size.
+            right := lastNewName copyFrom:prefix size+1.
+            ^ left , right
+        ]
     ].
 
     suffix size > 0 ifTrue:[
-	|prefix2|
-
-	"last rename was:
-	    'fooSUFF1' -> 'barSUFF1'
-	 then, a good default for
-	    'fooSUFF2' -> 'barSUFF2'
-	"
-	prefix := lastOldName copyTo:(lastOldName size - suffix size).  "/ the foo
-	(oldName startsWith:prefix) ifTrue:[
-	    prefix2 := lastNewName copyTo:(lastNewName size - suffix size). "/ the bar
-	    ^ prefix2,(oldName copyFrom:(prefix size+1)).
-	].
+        |prefix2|
+
+        "last rename was:
+            'fooSUFF1' -> 'barSUFF1'
+         then, a good default for
+            'fooSUFF2' -> 'barSUFF2'
+        "
+        prefix := lastOldName copyTo:(lastOldName size - suffix size).  "/ the foo
+        (oldName startsWith:prefix) ifTrue:[
+            prefix2 := lastNewName copyTo:(lastNewName size - suffix size). "/ the bar
+            ^ prefix2,(oldName copyFrom:(prefix size+1)).
+        ].
     ].
 
     "/ was there something stripped at the end?
     suffix := oldName commonSuffixWith:lastOldName.
-    [suffix size > 0] whileTrue:[
-	tryAgain := self
-		    goodRenameDefaultFor:(oldName copyButLast:suffix size)
-		    lastOld:(lastOldName copyButLast:suffix size)
-		    lastNew:lastNewName.
-	tryAgain notNil ifTrue:[^ tryAgain].
-	suffix := suffix copyFrom:2.
+    (suffix size > 0) ifTrue:[
+        ^ self
+            goodRenameDefaultFor:(oldName copyButLast:suffix size)
+            lastOld:(lastOldName copyButLast:suffix size)
+            lastNew:lastNewName.
     ].
     ^ nil
 
@@ -990,8 +988,8 @@
      self goodRenameDefaultFor:'CoastCore-CSFoo' lastOld:'CoastCore-CSBar' lastNew:'Coast-Core-CSBar'
 
      self goodRenameDefaultFor:'mti.odt2.level1HeadlineStyle'
-		       lastOld:'mti.odt2.level1HeadlineMatchPattern'
-		       lastNew:'Key_odt2_level1HeadlineMatchPattern'
+                       lastOld:'mti.odt2.level1HeadlineMatchPattern'
+                       lastNew:'Key_odt2_level1HeadlineMatchPattern'
     "
 
     "Modified: / 24-07-2011 / 11:06:03 / cg"