Microdown icon indicating copy to clipboard operation
Microdown copied to clipboard

MicExportCanvas duplicated logic (tx CB2)

Open Ducasse opened this issue 3 years ago • 2 comments

withLinesIn: aString do: aBlock separatedBy: anotherBlock

	"this method shows that the body of code block is weak because it should encapsulate the way it internally represents lines. Now this is exposed in clients."

	| str |
	str := aString readStream.
	[ str atEnd ] whileFalse: [ 
		| line |
		line := str nextLine.
		aBlock value: line.
		str atEnd ifFalse: anotherBlock ]

Ducasse avatar May 17 '22 15:05 Ducasse

lines: aString

	"Output aString and take care of line ending within aString."

	| str |
	str := aString readStream.
	[ str atEnd ] whileFalse: [ 
		| line |
		line := str nextLine.
		str atEnd
			ifTrue: [ self nextPutAll: line ]
			ifFalse: [ self line: line ] ]

Ducasse avatar May 17 '22 15:05 Ducasse

Looks like we could rewrite this as...

lines: aString
  self withLinesIn: aString do: [ self nextPutAll: line ] separatedBy: [ self line: line ]

Ducasse avatar May 17 '22 15:05 Ducasse