[squeak-dev] The Trunk: Collections-ar.166.mcz

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Wed Oct 14 17:49:31 UTC 2009


Oh, yes, I hesitated about Matrix >> #shallowCopy, because previous
implementation was just silly...
I again approve the removal of this method, we can afford to break
broken code sometimes...

Nicolas

2009/10/14  <commits at source.squeak.org>:
> Andreas Raab uploaded a new version of Collections to project The Trunk:
> http://source.squeak.org/trunk/Collections-ar.166.mcz
>
> ==================== Summary ====================
>
> Name: Collections-ar.166
> Author: ar
> Time: 13 October 2009, 7:35:06 am
> UUID: 9abba6f5-43ec-b047-bd87-bf240bbac59d
> Ancestors: Collections-ul.163, Collections-ul.164, Collections-ul.165
>
> Merging Collections-ul.164, Collections-ul.165:
>
> - removed Matrix >> #shallowCopy. The contents array is already copied in #postCopy, don't have to do it twice. This may break code which assumes that #shallowCopy copies the contents array which is a really bad assumption.
> - also removed empty category "copying" from Interval
> - faster and simpler String >> #format:, String >> #withBlanksTrimmed
>
> =============== Diff against Collections-ul.163 ===============
>
> Item was changed:
>  ----- Method: String>>evaluateExpression:parameters: (in category 'private') -----
>  evaluateExpression: aString parameters: aCollection
>        "private - evaluate the expression aString with
>        aCollection as the parameters and answer the
>        evaluation result as an string"
>        | index |
> +       index := Integer readFrom: aString readStream base: 10.
> -       index := ('0' , aString) asNumber.
>
>        index isZero
>                ifTrue: [^ '[invalid subscript: {1}]' format: {aString}].
>
>        index > aCollection size
>                ifTrue: [^ '[subscript is out of bounds: {1}]' format: {aString}].
>
>        ^ (aCollection at: index) asString!
>
> Item was changed:
>  ----- Method: String>>format: (in category 'formatting') -----
>  format: aCollection
>        "format the receiver with aCollection
>
>        simplest example:
>        'foo {1} bar' format: {Date today}.
>
>        complete example:
> +       '\{ \} \\ foo {1} bar {2}' format: {12. 'string'}.
> -       '\{ \} \\ foo {1} bar {2}' format: {12. 'string'}.
>        "
> +       ^String new: self size streamContents: [ :result |
> +               | stream currentChar |
> +               stream := self readStream.
> +               [ (currentChar := stream next) == nil ] whileFalse: [
> -       | result stream |
> -       result := String new writeStream.
> -       stream := self readStream.
> -
> -       [stream atEnd]
> -               whileFalse: [| currentChar |
> -                       currentChar := stream next.
>                        currentChar == ${
> +                               ifTrue: [
> +                                       result nextPutAll: (
> +                                               self
> +                                                       evaluateExpression: (stream upTo: $}) withBlanksTrimmed
> +                                                       parameters: aCollection) ]
> -                               ifTrue: [| expression |
> -                                       expression := self getEnclosedExpressionFrom: stream.
> -                                       result
> -                                               nextPutAll: (self evaluateExpression: expression parameters: aCollection)]
>                                ifFalse: [
>                                        currentChar == $\
> +                                               ifFalse: [ result nextPut: currentChar ]
> +                                               ifTrue: [
> +                                                       (currentChar := stream next) ifNotNil: [
> +                                                               result nextPut: currentChar ] ] ] ] ]!
> -                                               ifTrue: [stream atEnd
> -                                                               ifFalse: [result nextPut: stream next]]
> -                                               ifFalse: [result nextPut: currentChar]]].
> -
> -       ^ result contents!
>
> Item was changed:
>  ----- Method: String>>withBlanksTrimmed (in category 'converting') -----
>  withBlanksTrimmed
>        "Return a copy of the receiver from which leading and trailing blanks have been trimmed."
>
> +       | first last |
> +       first := self findFirst: [ :c | c isSeparator not ].
> +       first = 0 ifTrue: [ ^'' ].  "no non-separator character"
> +       last := self findLast: [ :c | c isSeparator not ].
> +       (first = 1 and: [ last = self size ]) ifTrue: [ ^self copy ].
> +       ^self
> -       | first result |
> -       first := self findFirst: [:c | c isSeparator not].
> -       first = 0 ifTrue: [^ ''].  "no non-separator character"
> -       result :=  self
>                copyFrom: first
> +               to: last
> -               to: (self findLast: [:c | c isSeparator not]).
> -       result isOctetString ifTrue: [^ result asOctetString] ifFalse: [^ result].
> -
> -       " ' abc  d   ' withBlanksTrimmed"
>  !
>
> Item was removed:
> - ----- Method: Matrix>>shallowCopy (in category 'copying') -----
> - shallowCopy
> -       ^self class rows: nrows columns: ncols contents: contents shallowCopy!
>
> Item was removed:
> - ----- Method: String>>getEnclosedExpressionFrom: (in category 'private') -----
> - getEnclosedExpressionFrom: aStream
> -       "private - get the expression enclosed between '{' and
> -       '}' and remove all the characters from the stream"
> -       | result currentChar |
> -       result := String new writeStream.
> -
> -       [aStream atEnd
> -               or: [(currentChar := aStream next) == $}]]
> -               whileFalse: [result nextPut: currentChar].
> -
> -       ^ result contents withBlanksTrimmed!
>
>
>



More information about the Squeak-dev mailing list