'From Squeak3.8gamma of ''24 November 2004'' [latest update: #6493] on 23 December 2004 at 7:25:45 pm'! "Change Set: AcornFDcheckName-75 Date: 23 December 2004 Author: tim@sumeru.stanford.edu Yet another attempt at catching and correcting filenames for RISC OS. This time we keep a class var with a mapping of all the allowable or convertable characters. This at least works ok with spaces and hardspaces"! FileDirectory subclass: #AcornFileDirectory instanceVariableNames: '' classVariableNames: 'LegalCharMap ' poolDictionaries: '' category: 'System-Files'! !AcornFileDirectory methodsFor: 'file name utilities' stamp: 'tpr 12/23/2004 19:21'! checkName: aFileName fixErrors: fixing "Check if the file name contains any invalid characters" | fName hasBadChars correctedName newChar| fName _ super checkName: aFileName fixErrors: fixing. correctedName _ String streamContents:[:s| fName do:[:c| (newChar _ LegalCharMap at: c asciiValue +1) ifNotNil:[s nextPut: newChar]]]. hasBadChars _ fName ~= correctedName. (hasBadChars and:[fixing not]) ifTrue:[^self error:'Invalid file name']. hasBadChars ifFalse:[^ fName]. ^ correctedName! ! !AcornFileDirectory class methodsFor: 'class initialization' stamp: 'tpr 12/23/2004 19:20'! initialize "Set up the legal chars map for filenames. May need extending for unicode etc. Basic rule is that any char legal for use in filenames will have a non-nil entry in this array; except for space, this is the same character. Space is transcoded to a char 160 to be a 'hard space' " "AcornFileDirectory initialize" | aVal | LegalCharMap _ Array new: 256. Character alphabet do:[:c| LegalCharMap at: c asciiValue +1 put: c. LegalCharMap at: (aVal _ c asUppercase) asciiValue +1 put: aVal]. '`!!()-_=+[{]};~,./1234567890' do:[:c| LegalCharMap at: c asciiValue + 1 put: c]. LegalCharMap at: Character space asciiValue +1 put: (Character value:160 "hardspace"). LegalCharMap at: 161 put: (Character value:160 "hardspace")."secondary mapping to keep it in strings"! ! AcornFileDirectory initialize! !AcornFileDirectory class reorganize! ('platform specific' isActiveDirectoryClass isCaseSensitive maxFileNameLength pathNameDelimiter) ('class initialization' initialize) ! FileDirectory subclass: #AcornFileDirectory instanceVariableNames: '' classVariableNames: 'LegalCharMap' poolDictionaries: '' category: 'System-Files'!