'From Pharo0.1 of 16 May 2008 [Latest update: #10300] on 10 May 2009 at 1:01:25 am'!
"Change Set:		FasterLatin1Conversion-Part3
Date:			10 May 2009
Author:			nice

Install fast latin1 conversion Part3

Use #installLineEndConventionInConverter where due.
that is whenever converter or lineEndConvention are changed in MultiByteFileStream"!


!MultiByteFileStream methodsFor: 'accessing' stamp: 'nice 5/10/2009 00:14'!
binary

	super binary.
	lineEndConvention := nil.
	self installLineEndConventionInConverter! !

!MultiByteFileStream methodsFor: 'accessing' stamp: 'nice 5/10/2009 00:17'!
converter

	converter ifNil: [converter := TextConverter defaultSystemConverter.
		self installLineEndConventionInConverter].
	^ converter
! !

!MultiByteFileStream methodsFor: 'accessing' stamp: 'nice 5/10/2009 00:18'!
converter: aConverter

	converter := aConverter.
	self installLineEndConventionInConverter
! !

!MultiByteFileStream methodsFor: 'accessing' stamp: 'nice 5/10/2009 00:14'!
lineEndConvention: aSymbol

	lineEndConvention := aSymbol.
	self installLineEndConventionInConverter! !

!MultiByteFileStream methodsFor: 'crlf private' stamp: 'nice 5/10/2009 00:53'!
detectLineEndConvention
	"Detect the line end convention used in this stream. The result may be either #cr, #lf or #crlf."
	| char numRead state |
	self isBinary ifTrue: [^ self error: 'Line end conventions are not used on binary streams'].
	self wantsLineEndConversion ifFalse: [lineEndConvention := nil.
					self installLineEndConventionInConverter.
					^lineEndConvention].
	self closed ifTrue: [lineEndConvention := LineEndDefault.
					self installLineEndConventionInConverter.
					^lineEndConvention].

	"Default if nothing else found"
	numRead := 0.
	state := converter saveStateOf: self.
	lineEndConvention := nil.
	[super atEnd not and: [numRead < LookAheadCount]]
		whileTrue: 
			[char := self next.
			char = Lf
				ifTrue: 
					[converter restoreStateOf: self with: state.
					lineEndConvention := #lf.
					self installLineEndConventionInConverter.
					^lineEndConvention].
			char = Cr
				ifTrue: 
					[self peek = Lf
						ifTrue: [lineEndConvention := #crlf]
						ifFalse: [lineEndConvention := #cr].
					converter restoreStateOf: self with: state.
					self installLineEndConventionInConverter.
					^ lineEndConvention].
			numRead := numRead + 1].
	converter restoreStateOf: self with: state.
	lineEndConvention := LineEndDefault.
	self installLineEndConventionInConverter.
	^ lineEndConvention! !

!MultiByteFileStream methodsFor: 'open/close' stamp: 'nice 5/10/2009 00:18'!
reset

	super reset.
	converter ifNil: [
		converter := UTF8TextConverter new.
		self installLineEndConventionInConverter
	].
! !

"Postscript:
Leave the line above, and replace the rest of this comment by a useful one.
Executable statements should follow this comment, and should
be separated by periods, with no exclamation points (!!).
Be sure to put any further comments in double-quotes, like this one."

SourceFiles do: [:e | (e isKindOf: MultiByteFileStream) ifTrue: [
		e installLineEndConventionInConverter]]!

