Microdown
Microdown copied to clipboard
MicExportCanvas duplicated logic (tx CB2)
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 ]
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 ] ]
Looks like we could rewrite this as...
lines: aString
self withLinesIn: aString do: [ self nextPutAll: line ] separatedBy: [ self line: line ]