[FIX] some FileURL fixes (was Re: While I'm at it...(Re: [BUG]? FileDirectory>>directoryContentsFor:))

Ned Konz ned at bike-nomad.com
Sun Mar 18 17:08:12 UTC 2001


On Sunday 18 March 2001 08:30, Lex Spoon wrote:

> If you inspect the two URL's, however, you will see that the isAbsolute
> instance variable is stored correctly.  Hrm, it looks like #toText is
> also goofed up -- it prints *two* slashes in the first case!  Yarg!!

I fixed some FileURL bugs a while ago; the CS is attached. However, it 
doesn't fix pathForFile.

It does fix toText, though.

The problem with pathForFile is that you have to know the base.

And some operating systems (Windows/CE, for instance) don't have the concept 
of a "current directory", so you can't use that, in general.

-- 
Ned Konz
currently: Stanwood, WA
email:     ned at bike-nomad.com
homepage:  http://bike-nomad.com
-------------- next part --------------
'From Squeak2.9alpha of 5 January 2001 [latest update: #3324] on 5 February 2001 at 3:40:06 pm'!

!FileDirectory methodsFor: 'file name utilities' stamp: 'nk 2/2/2001 15:18'!
url
	"Convert my path into a file:// type url.  Use slash instead of the local delimiter (:), and convert odd characters to %20 notation."

	"If slash (/) is not the file system delimiter, encode slashes before converting."
	| list |
	list _ self pathParts.
	^ String streamContents: [:strm |
		strm nextPutAll: 'file:'.
		list do: [:each | strm nextPut: $/; nextPutAll: each encodeForHTTP].
		strm nextPut: $/]! !


!FileStream methodsFor: 'file accessing' stamp: 'nk 2/2/2001 15:19'!
url
	"Convert my path into a file:// type url.  Use slash instead of the local delimiter (:), and convert odd characters to %32 notation."

	"If / is not the file system delimiter, encode / before converting."
	| list |
	list _ self directory pathParts.
	^ String streamContents: [:strm |
		strm nextPutAll: 'file:'.
		list do: [:each | strm nextPut: $/; nextPutAll: each encodeForHTTP].
		strm nextPut: $/; nextPutAll: self localName encodeForHTTP]! !


!FileUrl methodsFor: 'printing' stamp: 'nk 2/2/2001 16:26'!
toText
	| s |
	s _ WriteStream on: String new.
	s nextPutAll: self schemeName.
	s nextPut: $:.
	s nextPutAll: self pathString.
	fragment ifNotNil: [ s nextPut: $#.  s nextPutAll: fragment encodeForHTTP ].
	^s contents! !

!FileUrl methodsFor: 'access' stamp: 'nk 2/2/2001 16:38'!
pathDirString
	"Path to directory as url, using slash as delimiter"

	^ String streamContents: [ :s |
		isAbsolute ifTrue: [ s nextPut: $/ ].
		1 to: self path size - 1 do: [ :ii |
			s nextPutAll: (path at: ii); nextPut: $/
			 ] ]! !

!FileUrl methodsFor: 'access' stamp: 'nk 2/2/2001 17:50'!
pathForDirectory
	"Path using local file system's delimiter.  $\ or $:"

	^ String streamContents: [ :s |
		isAbsolute ifTrue: [ s nextPut: $/ ].
		1 to: self path size - 1 do: [ :ii |
			s nextPutAll: (path at: ii); nextPut: FileDirectory default pathNameDelimiter
			 ] ]! !



More information about the Squeak-dev mailing list