[Pkg] The Trunk: Collections-ct.850.mcz
commits at source.squeak.org
commits at source.squeak.org
Mon Aug 19 13:00:59 UTC 2019
Marcel Taeumel uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ct.850.mcz
==================== Summary ====================
Name: Collections-ct.850
Author: ct
Time: 15 August 2019, 11:33:51.432735 pm
UUID: f0af391e-59c7-4b41-815c-0aa3ae8afb6d
Ancestors: Collections-fn.847
Implement formatting on Text
Try out something like:
'Hello {1}!' asText format: {Utilities authorInitials asText allBold}.
=============== Diff against Collections-fn.847 ===============
Item was added:
+ ----- Method: Text class>>new:streamContents: (in category 'instance creation') -----
+ new: newSize streamContents: blockWithArg
+
+ | stream |
+ stream := TextStream on: (self new: newSize).
+ blockWithArg value: stream.
+ ^ stream contents!
Item was added:
+ ----- 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)) 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 ] ]!
More information about the Packages
mailing list