Improve #makeUniqueImageName:among:
MODIFY
src/PharoLauncher-Core.package/PhLDirectoryBasedImageRepository.class/instance/makeUniqueImageName.among..st
src/PharoLauncher-Core.package/PhLDirectoryBasedImageRepository.class/instance/makeUniqueImageName.among..st
action
makeUniqueImageName: baseImageName among: existingImageNames
+ "Provide a reasonable default image name using the next incremental count for images with similar basenames"
+ "See #testMakeUniqueImageName for samples"
+
| similarbaseImageNames existingUniquifiers nextUniquifier separator |
separator := '-'.
- similarbaseImageNames := existingImageNames
- select: [ :imageName | imageName = baseImageName or: (imageName beginsWith: baseImageName) ].
- similarbaseImageNames ifEmpty: [ ^ baseImageName ].
+ similarbaseImageNames := existingImageNames select: [ :imageName | imageName beginsWith: baseImageName ].
existingUniquifiers := similarbaseImageNames
collect: [ :imageName | | suffix |
suffix := imageName allButFirst: baseImageName size.
(suffix beginsWith: separator)
- ifTrue: [ (suffix allButFirst: separator size) asInteger ]
- ifFalse: 0].
+ ifTrue: [ (suffix allButFirst: separator size) initialIntegerOrNil ]
+ ifFalse: 0]
+ thenSelect: #notNil.
+ existingUniquifiers ifEmpty: [ ^ baseImageName ].
nextUniquifier := existingUniquifiers max + 1.
^ baseImageName , separator , (nextUniquifier printPaddedWith: $0 to: 2)
\ No newline at end of file

Improve #makeUniqueImageName:among:
https://pharo.fogbugz.com/f/cases/12533