#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Mon, 25 Jun 2018 17:12:22 +0200
changeset 23129 53cee4c20659
parent 23128 bbd3f21e2fef
child 23130 48acb2bbb580
#FEATURE by cg class: Filename added: #makeLegalBasename comment/format in: #makeLegalFilename
Filename.st
--- a/Filename.st	Fri Jun 22 11:54:27 2018 +0200
+++ b/Filename.st	Mon Jun 25 17:12:22 2018 +0200
@@ -2202,6 +2202,38 @@
     "
 !
 
+makeLegalBasename
+    "convert the receiver's name to be a legal basename.
+     This removes/replaces invalid characters and/or compresses
+     the name as required by the OS.
+     It also replaces the directory separator (i.e. '/') by an inderscore.    
+     The implementation may change in the future to be more
+     OS specific."
+
+    "
+     actually, in Unix spaces are allowed - but it makes life
+     so hard; therefore, replace them by underscores ...
+    "
+    nameString := nameString copy 
+                    replaceAllForWhich:[:each| 
+                        each isSeparator 
+                        or:[self class isBadCharacter:each]]
+                    with:$_.
+    "
+     need more - especially on SYS5.3 type systems,
+     we may want to contract the fileName to 14 characters.
+    "
+    ^ self
+
+    "
+     'hello world' asFilename makeLegalBasename
+      ('abc' copyWith:Character return) asFilename makeLegalBasename
+      ('a/b/c' copyWith:Character return) asFilename makeLegalBasename
+    "
+
+    "Created: / 25-06-2018 / 17:11:41 / Claus Gittinger"
+!
+
 makeLegalFilename
     "convert the receiver's name to be a legal filename.
      This removes/replaces invalid characters and/or compresses
@@ -2216,9 +2248,11 @@
     |separator|
 
     separator := self separator.
-    nameString := nameString copy replaceAllForWhich:[:each| each == Character space
-                                                             or:[each ~= separator 
-                                                                 and:[self class isBadCharacter:each]]] with:$_.
+    nameString := nameString copy 
+                    replaceAllForWhich:[:each| 
+                        each == Character space 
+                        or:[each ~= separator and:[self class isBadCharacter:each]]]
+                    with:$_.
     "
      need more - especially on SYS5.3 type systems,
      we may want to contract the fileName to 14 characters.
@@ -2232,6 +2266,7 @@
 
     "Modified: / 20-07-1998 / 13:16:51 / cg"
     "Modified (comment): / 27-07-2017 / 15:53:53 / stefan"
+    "Modified (format): / 25-06-2018 / 17:09:23 / Claus Gittinger"
 !
 
 withEncoding:encodingSymbol