Filename.st
changeset 11341 22494c109161
parent 11192 828184f29182
child 11397 872cd41bbe05
--- a/Filename.st	Tue Nov 11 22:30:16 2008 +0100
+++ b/Filename.st	Wed Nov 12 14:10:54 2008 +0100
@@ -4319,14 +4319,15 @@
 
 filenameCompletionIn:aDirectory
     "try to complete the receiver filename.
+
      BAD DESIGN: has side effect on the receiver.
      This method has both a return value and a side effect on the receiver:
        it returns a collection of matching filename objects,
-       and changes the receivers filename-string to the longest common
-       match.
-     If none matches, the returned collection is empty and the recevier is unchanged.
+       and changes the receiver's filename-string to the longest common match.
+     If none matches, the returned collection is empty and the receiver is unchanged.
      If there is only one match, the size of the returned collection is exactly 1,
-     containing the fully expanded filename and the receivers name is changed to it."
+     containing the fully expanded filename and the receiver's name is changed to it.
+     An empty baseName pattern (i.e. giving the name of a directory) will also return an empty matchset."
 
     |dir baseName matching matchLen try allMatching 
      sepString parentString prefix nMatch nm caseless lcBaseName|
@@ -4354,7 +4355,9 @@
                     ] ifFalse:[
                         "/ more than one file
                         longest := longest commonPrefixWith:fileName ignoreCase:caseless.
-                        longest isEmpty ifTrue:[ ^ #() ].
+                        longest isEmpty ifTrue:[ 
+                            ^ #() 
+                        ].
                     ]
                 ]
             ].
@@ -4440,9 +4443,9 @@
      if I had a directory-prefix, change names in collection ...
     "
     prefix notNil ifTrue:[
-        prefix = sepString ifTrue:[
+        (prefix endsWith:sepString) ifTrue:[
             "/ avoid introducing double slashes
-            prefix := ''
+            prefix := prefix copyWithoutLast:(sepString size).
         ].
         matching := matching collect:[:n | prefix , sepString , n].
         nMatch == 1 ifTrue:[
@@ -4466,9 +4469,9 @@
 
     " trivial cases:
 
-     '../' asFilename filenameCompletion    
-     '/' asFilename filenameCompletion      
-     '/usr/' asFilename filenameCompletion   
+     '../' asFilename filenameCompletion     -> empty
+     '/' asFilename filenameCompletion       -> empty
+     '/usr/' asFilename filenameCompletion   -> empty
 
      'mak' asFilename filenameCompletion   
      'Make' asFilename filenameCompletion    
@@ -4476,6 +4479,13 @@
      '/u' asFilename filenameCompletion             
      '../../libpr' asFilename filenameCompletion
      '/etc/mail/auth/xx' asFilename filenameCompletion
+
+     'c:\pr' asFilename filenameCompletion             -> matching names
+     'c:\pr' asFilename filenameCompletion; yourself   -> side effect: name changed to longest match
+     'c:\p' asFilename filenameCompletion 
+     'c:\' asFilename filenameCompletion  -> empty
+     'c:' asFilename filenameCompletion   -> empty
+     '\' asFilename filenameCompletion    -> empty
     "
 
     "Modified: / 22-09-1997 / 18:03:33 / stefan"
@@ -5566,7 +5576,7 @@
 !Filename class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.329 2008-10-01 17:45:15 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.330 2008-11-12 13:10:54 cg Exp $'
 ! !
 
 Filename initialize!