Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.611.mcz ==================== Summary ==================== Name: Collections-ul.611 Author: ul Time: 5 April 2015, 3:02:11.144 pm UUID: 8b7bf86a-b335-47a9-9c3b-c87148584c44 Ancestors: Collections-ul.610 - Stricter and faster implementation of String >> #format:. =============== Diff against Collections-ul.610 =============== Item was removed: - ----- 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 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'}. " + ^self class new: self size * 11 // 10 "+10%" streamContents: [ :output | + | lastIndex nextIndex | + lastIndex := 1. + [ (nextIndex := self indexOfAnyOf: FormatCharacterSet startingAt: lastIndex) = 0 ] whileFalse: [ + nextIndex = lastIndex ifFalse: [ + output next: nextIndex - lastIndex putAll: self startingAt: lastIndex ]. + (self at: nextIndex) == $\ + ifTrue: [ output nextPut: (self at: (nextIndex := nextIndex + 1)) ] + ifFalse: [ "${" + "Parse the index - a positive integer in base 10." + | digitValue collectionIndex | + collectionIndex := 0. + [ (digitValue := self basicAt: (nextIndex := nextIndex + 1)) between: 48 "$0 asciiValue" and: 57 "$9 asciiValue" ] whileTrue: [ + collectionIndex := collectionIndex * 10 + digitValue - 48. "$0 asciiValue" ]. + digitValue = 125 "$} asciiValue" ifFalse: [ self error: '$} expected' ]. + output nextPutAll: (aCollection at: collectionIndex) asString ]. + lastIndex := nextIndex + 1 ]. + lastIndex <= self size ifTrue: [ + output next: self size - lastIndex + 1 putAll: self startingAt: lastIndex ] ]! - ^String new: self size streamContents: [ :result | - | stream currentChar | - stream := self readStream. - [ (currentChar := stream next) == nil ] whileFalse: [ - currentChar == ${ - ifTrue: [ - result nextPutAll: ( - self - evaluateExpression: (stream upTo: $}) withBlanksTrimmed - parameters: aCollection) ] - ifFalse: [ - currentChar == $\ - ifFalse: [ result nextPut: currentChar ] - ifTrue: [ - (currentChar := stream next) ifNotNil: [ - result nextPut: currentChar ] ] ] ] ]! |
What means "stricter"? Can you elaborate on what is not possible anymore but was?
Best, Marcel |
Input that one would normally consider invalid is not accepted anymore.
The following expressions raise an error instead of returning 'x': '{1 }' format: { 'x' }. '{1abc}' format: { 'x' }. '{ 1}' format: { 'x' }. '{ 1.0 }' format: { 'x' }. '{1' format: { 'x' }. '{1 foo' format: { 'x' }. The following expressions raise an error, instead of writing an error message into the return value: 'foo {2} bar {1}' format: { 'x' }. "instead of 'foo [subscript is out of bounds: 2] bar x'" 'foo {0} bar {1}' format: { 'x' }. "instead of 'foo [invalid subscript: 0] bar x'" '{-0}' format: { 'x' }. "instead of '[invalid subscript: -0]'" Levente On Sun, 5 Apr 2015, Marcel Taeumel wrote: > What means "stricter"? Can you elaborate on what is not possible anymore but > was? > > Best, > Marcel > > > > -- > View this message in context: http://forum.world.st/The-Trunk-Collections-ul-611-mcz-tp4817669p4817690.html > Sent from the Squeak - Dev mailing list archive at Nabble.com. > > |
Free forum by Nabble | Edit this page |