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: $) ] ].!


Reply via email to