[squeak-dev] The Inbox: Collections-ct.850.mcz
Thiede, Christoph
Christoph.Thiede at student.hpi.uni-potsdam.de
Thu Aug 15 21:40:50 UTC 2019
As always, I will be glad about any feedback :)
________________________________
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von commits at source.squeak.org <commits at source.squeak.org>
Gesendet: Donnerstag, 15. August 2019 23:33:53
An: squeak-dev at lists.squeakfoundation.org
Betreff: [squeak-dev] The Inbox: Collections-ct.850.mcz
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/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 ] ]!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190815/3c438a75/attachment.html>
More information about the Squeak-dev
mailing list
|