A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.852.mcz ==================== Summary ==================== Name: Collections-ct.852 Author: ct Time: 3 September 2019, 2:10:41.062948 pm UUID: c4cd824f-ff9a-1041-97b4-df402b62e7b1 Ancestors: Collections-ct.851 Do not support Unicode numbers in format strings (see discussion about ancestor) =============== Diff against Collections-ct.851 =============== Item was changed: ----- Method: String>>format: (in category 'formatting') ----- format: arguments "format the receiver with arguments simplest example: 'foo {1} bar' format: {Date today}. complete example: '\{ \} \\ foo {1} bar {2}' format: {12. 'string'}. " ^self class new: self size * 11 // 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) caseOf: { [$\] -> [ output nextPut: (self at: (nextIndex := nextIndex + 1)) ]. [${] -> [ "Parse the index - a positive integer in base 10." | character collectionIndex | collectionIndex := 0. + [ (character := self at: (nextIndex := nextIndex + 1)) between: $0 and: $9 ] whileTrue: [ - [ (character := self at: (nextIndex := nextIndex + 1)) isDigit ] whileTrue: [ collectionIndex := collectionIndex * 10 + character digitValue ]. character = $} ifFalse: [ self error: '$} expected' ]. output nextPutAll: (arguments at: collectionIndex) asString ] }. lastIndex := nextIndex + 1 ]. lastIndex <= self size ifTrue: [ output next: self size - lastIndex + 1 putAll: self startingAt: lastIndex ] ]! Item was changed: ----- Method: Text>>format: (in category 'formatting') ----- format: arguments "format the receiver with arguments, respecting the format both of receiver and collection elements" ^self class new: self size * 11 // 10 streamContents: [ :output | | nextIndex | nextIndex := 1. [ nextIndex <= self size ] whileTrue: [ (self at: nextIndex) caseOf: { [$\] -> [ nextIndex := nextIndex + 1. output withAttributes: (runs at: nextIndex) do: [ output nextPut: (self at: nextIndex) ] ]. [${] -> [ "Parse the index - a positive integer in base 10." | character collectionIndex attributes | collectionIndex := 0. attributes := Set new. + [ (character := string at: (nextIndex := nextIndex + 1)) between: $0 and: $9 ] whileTrue: [ - [ (character := string at: (nextIndex := nextIndex + 1)) isDigit ] whileTrue: [ collectionIndex := collectionIndex * 10 + character digitValue. attributes addAll: (runs at: nextIndex) ]. character = $} ifFalse: [ self error: '$} expected' ]. output withAttributes: attributes do: [ output nextPutAll: (arguments at: collectionIndex) asStringOrText ] ] } otherwise: [ output withAttributes: (runs at: nextIndex) do: [ output nextPut: (self at: nextIndex) ] ]. nextIndex := nextIndex + 1 ] ]! |
Free forum by Nabble | Edit this page |