Andreas Raab uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ar.368.mcz==================== Summary ====================
Name: Collections-ar.368
Author: ar
Time: 15 July 2010, 5:16:28.929 pm
UUID: 1d3445e6-fc60-6e42-9996-a1bde20ec5cb
Ancestors: Collections-eem.367
Fix for withNoLineLongerThan:.
=============== Diff against Collections-eem.367 ===============
Item was changed:
----- Method: String>>withNoLineLongerThan: (in category 'converting') -----
withNoLineLongerThan: aNumber
"Answer a string with the same content as receiver, but rewrapped so that no line has more characters than the given number"
aNumber isNumber not | (aNumber < 1) ifTrue: [self error: 'too narrow'].
^self class
new: self size * (aNumber + 1) // aNumber "provision for supplementary line breaks"
streamContents: [ :stream |
self lineIndicesDo: [ :start :endWithoutDelimiters :end | | lineStart |
lineStart := (self indexOfAnyOf: CSNonSeparators startingAt: start ifAbsent: [endWithoutDelimiters + 1]) min: endWithoutDelimiters.
+ [| lineStop lineEnd spacePosition |
- [| lineEnd spacePosition |
lineEnd := 0.
spacePosition := lineStart.
+ lineStop := (lineStart + aNumber - 1) min: endWithoutDelimiters.
+ [spacePosition <= lineStop] whileTrue:[
+ spacePosition := self indexOfAnyOf: CSSeparators startingAt: spacePosition + 1 ifAbsent: [endWithoutDelimiters+1].
+ spacePosition <= (lineStop+1) ifTrue:[lineEnd := spacePosition].
+ ].
- [spacePosition := self indexOfAnyOf: CSSeparators startingAt: spacePosition + 1 ifAbsent: [lineStart + aNumber + 1].
- spacePosition - lineStart <= (aNumber min: endWithoutDelimiters - lineStart)]
- whileTrue: [lineEnd := spacePosition].
lineEnd = 0
ifTrue: ["no space - split arbitrarily"
lineEnd := lineStart + aNumber - 1 min: endWithoutDelimiters.
stream nextPutAll: (self copyFrom: lineStart to: lineEnd).
lineStart := lineEnd + 1]
ifFalse: ["split before space"
stream nextPutAll: (self copyFrom: lineStart to: lineEnd - 1).
"eliminate conscutive spaces at split"
lineStart := self indexOfAnyOf: CSNonSeparators startingAt: lineEnd + 1 ifAbsent: [endWithoutDelimiters + 1] ].
lineStart <= endWithoutDelimiters ]
whileTrue: [stream cr].
stream nextPutAll: (self copyFrom: endWithoutDelimiters + 1 to: end) ] ]!