Squeak 2.1 for UNIX?

Lex Spoon lex at cc.gatech.edu
Thu Aug 13 23:48:49 UTC 1998


R. A. Harmon writes:
 > At 09:05 AM 8/13/98 -0400, you wrote:
 > [snip]
 > >I run Squeak under Linux, and I've
 > >found that sometimes when I read files with the file browser there are no
 > >carriage returns at the end of each line.  I filein'ed the CrLf fix on the
 > >UIUC ftp site, and after a bit of hacking to get it to work I STILL find
 > >that some files have no carriage returns when read.  Am I missing something
 > >important?
 > [snip]
 > 
 > Squeak seems to use a number of characters to indicate line termination.
 > I've found Cr, CrLf, and Lf.  The predominate convention on DOS/Windows x86
 > is CrLf and (I think) UNIX is Lf.
 > 
 > I briefly considered modifying Squeak to use Cr internally and the native
 > platform externally


You should try CrLfFileStream.  It does exactly this for you, modulo
any err unexpected features.  The only time it doesn't help is for
things downloaded over the network. 

For network data, I've been using methods #withSqueakLineEndings and
#withInternetLineEndings to convert back and forth, and it seems to
work pretty well.


Lex




!String methodsFor: 'internet' stamp: 'ls 7/27/1998 23:16'!
withSqueakLineEndings
	"assume the string is textual, and that CR, LF, and CRLF are all valid line endings.  Replace each occurence with a single CR"
	| cr lf input c |
	cr _ Character cr.
	lf _ Character linefeed.
	^String streamContents: [ :str |
		input _ ReadStream on: self.
		[input atEnd] whileFalse: [
			c _ input next.
			c == cr ifTrue: [
				str cr.
				input peek == lf ifTrue: [ input next ] ]
			ifFalse: [ 
				c == lf ifTrue: [ str cr ] ifFalse: [ str nextPut: c ] ] ] ]! !



!String methodsFor: 'internet' stamp: 'ls 7/27/1998 23:17'!
withInternetLineEndings
	"change line endings from CR's to CRLF's.  This is probably in prepration for sending a string over the Internet"
	| cr lf |
	cr _ Character cr.
	lf _ Character linefeed.
	^self class streamContents: [ :stream |
		self do: [ :c |
			stream nextPut: c.
			c = cr ifTrue:[ stream nextPut: lf ]. ] ].! !





More information about the Squeak-dev mailing list