Status: FixedWaitingToBePharoed
Owner: stephane.ducasse Labels: Milestone-1.3 Difficulty-Easy New issue 3348 by stephane.ducasse: use #shouldBePrintedAsLiteral instead of #isLiteral when printing or storing characters and arrays http://code.google.com/p/pharo/issues/detail?id=3348 A new version of Collections was added to project The Inbox: http://source.squeak.org/inbox/Collections-ul.411.mcz ==================== Summary ==================== Name: Collections-ul.411 Author: ul Time: 23 November 2010, 1:56:22.424 pm UUID: 42a0b87a-f525-6345-bd2c-e55186e17c9d Ancestors: Collections-ul.410 - use #shouldBePrintedAsLiteral instead of #isLiteral when printing or storing characters and arrays =============== Diff against Collections-ul.410 =============== Item was changed: ----- Method: Array>>printOn: (in category 'printing') ----- printOn: aStream + self shouldBePrintedAsLiteral ifTrue: [^self printAsLiteralFormOn: aStream]. - self isLiteral ifTrue: [^self printAsLiteralFormOn: aStream]. self class = Array ifTrue: [^self printAsBraceFormOn: aStream]. ^super printOn: aStream! Item was added: + ----- Method: Array>>shouldBePrintedAsLiteral (in category 'testing') ----- + shouldBePrintedAsLiteral + + ^self class == Array and: [ self allSatisfy: [ :each | each shouldBePrintedAsLiteral ] ]! Item was changed: ----- Method: Array>>storeOn: (in category 'printing') ----- storeOn: aStream "Use the literal form if possible." + self shouldBePrintedAsLiteral - self isLiteral ifTrue: [aStream nextPut: $#; nextPut: $(. self do: [:element | element storeOn: aStream. aStream space]. aStream nextPut: $)] ifFalse: [super storeOn: aStream]! Item was changed: ----- Method: Array>>storeOnStream: (in category 'filter streaming') ----- storeOnStream:aStream + + self shouldBePrintedAsLiteral + ifTrue: [ super storeOnStream:aStream ] + ifFalse:[ aStream writeCollection:self ] - self isLiteral ifTrue: [super storeOnStream:aStream] ifFalse:[aStream writeCollection:self]. ! Item was changed: + ----- Method: Character>>isLiteral (in category 'testing') ----- - ----- Method: Character>>isLiteral (in category 'printing') ----- isLiteral ^true! Item was added: + ----- Method: Character>>shouldBePrintedAsLiteral (in category 'testing') ----- + shouldBePrintedAsLiteral + + ^value between: 33 and: 255! Item was changed: ----- Method: Character>>storeOn: (in category 'printing') ----- storeOn: aStream "Common character literals are preceded by '$', however special need to be encoded differently: for some this might be done by using one of the shortcut constructor methods for the rest we have to create them by ascii-value." | name | + self shouldBePrintedAsLiteral - (value between: 33 and: 255) ifTrue: [ aStream nextPut: $$; nextPut: self ] ifFalse: [ name := self class constantNameFor: self. name notNil ifTrue: [ aStream nextPutAll: self class name; space; nextPutAll: name ] ifFalse: [ aStream nextPut: $(; nextPutAll: self class name; nextPutAll: ' value: '; print: value; nextPut: $) ] ].! |
Comment #1 on issue 3348 by stephane.ducasse: use #shouldBePrintedAsLiteral instead of #isLiteral when printing or storing characters and arrays http://code.google.com/p/pharo/issues/detail?id=3348 - introduced Object >> #shouldBePrintedAsLiteral as a replacement for #isLiteral during printing and storing =============== Diff against Kernel-dtl.517 =============== Item was added: + ----- Method: Object>>shouldBePrintedAsLiteral (in category 'testing') ----- + shouldBePrintedAsLiteral + + ^self isLiteral! Item was changed: ----- Method: ScaledDecimal>>storeOn: (in category 'printing') ----- storeOn: aStream "SxaledDecimal sometimes have more digits than they print (potentially an infinity). In this case, do not use printOn: because it would loose some extra digits" + self shouldBePrintedAsLiteral - self isLiteral ifTrue: [self printOn: aStream] ifFalse: [aStream nextPut: $(; store: fraction numerator; nextPut: $/; store: fraction denominator; nextPut: $s; store: scale; nextPut: $)]! |
Updates:
Labels: -Milestone-1.3 Comment #2 on issue 3348 by [hidden email]: use #shouldBePrintedAsLiteral instead of #isLiteral when printing or storing characters and arrays http://code.google.com/p/pharo/issues/detail?id=3348 (No comment was entered for this change.) |
Free forum by Nabble | Edit this page |