The Trunk: Collections-nice.195.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-nice.195.mcz

commits-2
Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.195.mcz

==================== Summary ====================

Name: Collections-nice.195
Author: nice
Time: 16 November 2009, 9:41:05 am
UUID: 1c276a72-f8f6-42d3-a580-f53d92fefb84
Ancestors: Collections-nice.194

Correct my own #withNoLineLongerThan: error and make the test pass

=============== Diff against Collections-nice.194 ===============

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].
  [| lineEnd spacePosition |
  lineEnd := 0.
  spacePosition := lineStart.
  [spacePosition := self indexOfAnyOf: CSSeparators startingAt: spacePosition + 1 ifAbsent: [lineStart + aNumber + 1].
+ spacePosition - lineStart <= (aNumber min: endWithoutDelimiters - lineStart)]
- spacePosition - lineStart <= aNumber]
  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) ] ]!