Issue 3663 in pharo: XMLWriter and MultiByteFileStream

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue 3663 in pharo: XMLWriter and MultiByteFileStream

pharo
Status: Accepted
Owner: [hidden email]
Labels: Milestone-1.3

New issue 3663 by [hidden email]: XMLWriter and MultiByteFileStream
http://code.google.com/p/pharo/issues/detail?id=3663

Name: Collections-ul.422
Author: ul
Time: 31 January 2011, 2:02:00.387 am
UUID: 89c6854c-b6d1-1646-a22b-bbc47ce7522f
Ancestors: Collections-ul.421

Introduced Stream >> #basicNext:putAll:startingAt: which will be used by  
MultiByteFileStream to fix http://bugs.squeak.org/view.php?id=7603 .

=============== Diff against Collections-ul.421 ===============

Item was added:
+ ----- Method: Stream>>basicNext:putAll:startingAt: (in  
category 'accessing') -----
+ basicNext: anInteger putAll: aCollection startingAt: startIndex
+
+       ^self next: anInteger putAll: aCollection startingAt: startIndex
+ !


A fix for http://bugs.squeak.org/view.php?id=7603 . Requires  
Collections-ul.422.

Added TextConverter >> #next:putAll:startingAt:toStream: which is used by  
MultiByteFileStream and MultiByteBinaryOrTextStream to properly implement  
#next:putAll:startingAt:.

=============== Diff against Multilingual-ul.133 ===============

Item was added:
+ ----- Method: MultiByteBinaryOrTextStream>>basicNext:putAll:startingAt:  
(in category 'private basic') -----
+ basicNext: anInteger putAll: aCollection startingAt: startIndex
+
+       ^super next: anInteger putAll: aCollection startingAt: startIndex!

Item was added:
+ ----- Method: MultiByteBinaryOrTextStream>>next:putAll:startingAt: (in  
category 'public') -----
+ next: anInteger putAll: aCollection startingAt: startIndex
+
+       (self isBinary or: [ aCollection class == ByteArray ]) ifTrue: [
+               ^super next: anInteger putAll: aCollection startingAt:  
startIndex ].
+       ^self converter next: anInteger putAll: aCollection startingAt:  
startIndex toStream: self
+ !

Item was added:
+ ----- Method: MultiByteFileStream>>basicNext:putAll:startingAt: (in  
category 'private basic') -----
+ basicNext: anInteger putAll: aCollection startingAt: startIndex
+
+       ^super next: anInteger putAll: aCollection startingAt: startIndex!

Item was added:
+ ----- Method: MultiByteFileStream>>next:putAll:startingAt: (in  
category 'public') -----
+ next: anInteger putAll: aCollection startingAt: startIndex
+
+       (self isBinary or: [ aCollection class == ByteArray ]) ifTrue: [
+               ^super next: anInteger putAll: aCollection startingAt:  
startIndex ].
+       ^converter next: anInteger putAll: aCollection startingAt:  
startIndex toStream: self!

Item was changed:
  ----- Method: MultiByteFileStream>>nextPutAll: (in category 'public') -----
  nextPutAll: aCollection

        (self isBinary or: [aCollection class == ByteArray]) ifTrue: [
                ^ super nextPutAll: aCollection.
        ].
+       ^converter nextPutAll: aCollection toStream: self!
-       converter nextPutAll: aCollection toStream: self.
-       ^aCollection!

Item was added:
+ ----- Method: TextConverter>>next:putAll:startingAt:toStream: (in  
category 'conversion') -----
+ next: anInteger putAll: aString startingAt: startIndex toStream: aStream
+       "Handle fast conversion if ByteString"
+
+       | lastIndex nextIndex |
+       aString class == ByteString ifFalse: [
+               startIndex to: startIndex + anInteger - 1 do: [ :index |
+                       self nextPut: (aString at: index) toStream: aStream  
].
+               ^aString ].
+       aStream isBinary ifTrue: [
+               aStream basicNext: anInteger putAll: aString startingAt:  
startIndex.
+               ^aString ].
+       lastIndex := startIndex.
+       [ (nextIndex := ByteString
+               findFirstInString: aString
+               inSet: latin1Map
+               startingAt: lastIndex) = 0 or: [ nextIndex > anInteger ] ]  
whileFalse: [
+                       aStream
+                               basicNext: nextIndex - lastIndex putAll:  
aString startingAt: lastIndex;
+                               basicNextPutAll: (latin1Encodings at:  
(aString byteAt: nextIndex) + 1).
+                       lastIndex := nextIndex + 1 ].
+       aStream basicNext: anInteger - lastIndex + 1 putAll: aString  
startingAt: lastIndex.
+       ^aString!

Item was changed:
  ----- Method: TextConverter>>nextPutAll:toStream: (in  
category 'conversion') -----
  nextPutAll: aString toStream: aStream
        "Handle fast conversion if ByteString"

+       ^self next: aString size putAll: aString startingAt: 1 toStream:  
aStream!
-       | lastIndex nextIndex |
-       aString class == ByteString ifFalse: [
-               aString do: [:char | self nextPut: char toStream: aStream].
-               ^self].
-
-       aStream isBinary ifTrue: [
-               aStream basicNextPutAll: aString.
-               ^self].
-       lastIndex := 1.
-       [nextIndex := ByteString findFirstInString: aString inSet:  
latin1Map startingAt: lastIndex.
-       nextIndex = 0] whileFalse:
-               [aStream next: nextIndex-lastIndex putAll: aString  
startingAt: lastIndex.
-               aStream basicNextPutAll: (latin1Encodings at: (aString  
byteAt: nextIndex)+1).
-               lastIndex := nextIndex + 1].
-       aStream next: aString size-lastIndex+1 putAll: aString startingAt:  
lastIndex.
-       ^self
- !


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3663 in pharo: XMLWriter and MultiByteFileStream

pharo

Comment #1 on issue 3663 by [hidden email]: XMLWriter and  
MultiByteFileStream
http://code.google.com/p/pharo/issues/detail?id=3663

Name: Multilingual-ul.135
Author: ul
Time: 31 January 2011, 2:40:43.278 am
UUID: 8cec33f7-5ea5-1c45-974d-a335275f1192
Ancestors: Multilingual-ul.134

Fixed an indexing mistake.

=============== Diff against Multilingual-ul.133 ===============

Item was added:
+ ----- Method: MultiByteBinaryOrTextStream>>basicNext:putAll:startingAt:  
(in category 'private basic') -----
+ basicNext: anInteger putAll: aCollection startingAt: startIndex
+
+       ^super next: anInteger putAll: aCollection startingAt: startIndex!

Item was added:
+ ----- Method: MultiByteBinaryOrTextStream>>next:putAll:startingAt: (in  
category 'public') -----
+ next: anInteger putAll: aCollection startingAt: startIndex
+
+       (self isBinary or: [ aCollection class == ByteArray ]) ifTrue: [
+               ^super next: anInteger putAll: aCollection startingAt:  
startIndex ].
+       ^self converter next: anInteger putAll: aCollection startingAt:  
startIndex toStream: self
+ !

Item was added:
+ ----- Method: MultiByteFileStream>>basicNext:putAll:startingAt: (in  
category 'private basic') -----
+ basicNext: anInteger putAll: aCollection startingAt: startIndex
+
+       ^super next: anInteger putAll: aCollection startingAt: startIndex!

Item was added:
+ ----- Method: MultiByteFileStream>>next:putAll:startingAt: (in  
category 'public') -----
+ next: anInteger putAll: aCollection startingAt: startIndex
+
+       (self isBinary or: [ aCollection class == ByteArray ]) ifTrue: [
+               ^super next: anInteger putAll: aCollection startingAt:  
startIndex ].
+       ^converter next: anInteger putAll: aCollection startingAt:  
startIndex toStream: self!

Item was changed:
  ----- Method: MultiByteFileStream>>nextPutAll: (in category 'public') -----
  nextPutAll: aCollection

        (self isBinary or: [aCollection class == ByteArray]) ifTrue: [
                ^ super nextPutAll: aCollection.
        ].
+       ^converter nextPutAll: aCollection toStream: self!
-       converter nextPutAll: aCollection toStream: self.
-       ^aCollection!

Item was added:
+ ----- Method: TextConverter>>next:putAll:startingAt:toStream: (in  
category 'conversion') -----
+ next: anInteger putAll: aString startingAt: startIndex toStream: aStream
+       "Handle fast conversion if ByteString"
+
+       | lastIndex nextIndex |
+       aString class == ByteString ifFalse: [
+               startIndex to: startIndex + anInteger - 1 do: [ :index |
+                       self nextPut: (aString at: index) toStream: aStream  
].
+               ^aString ].
+       aStream isBinary ifTrue: [
+               aStream basicNext: anInteger putAll: aString startingAt:  
startIndex.
+               ^aString ].
+       lastIndex := startIndex.
+       [ (nextIndex := ByteString
+               findFirstInString: aString
+               inSet: latin1Map
+               startingAt: lastIndex) = 0 or: [ nextIndex > anInteger ] ]  
whileFalse: [
+                       aStream
+                               basicNext: nextIndex - lastIndex putAll:  
aString startingAt: lastIndex;
+                               basicNextPutAll: (latin1Encodings at:  
(aString byteAt: nextIndex) + 1).
+                       lastIndex := nextIndex + 1 ].
+       aStream basicNext: anInteger - lastIndex + startIndex putAll:  
aString startingAt: lastIndex.
+       ^aString!

Item was changed:
  ----- Method: TextConverter>>nextPutAll:toStream: (in  
category 'conversion') -----
  nextPutAll: aString toStream: aStream
        "Handle fast conversion if ByteString"

+       ^self next: aString size putAll: aString startingAt: 1 toStream:  
aStream!
-       | lastIndex nextIndex |
-       aString class == ByteString ifFalse: [
-               aString do: [:char | self nextPut: char toStream: aStream].
-               ^self].
-
-       aStream isBinary ifTrue: [
-               aStream basicNextPutAll: aString.
-               ^self].
-       lastIndex := 1.
-       [nextIndex := ByteString findFirstInString: aString inSet:  
latin1Map startingAt: lastIndex.
-       nextIndex = 0] whileFalse:
-               [aStream next: nextIndex-lastIndex putAll: aString  
startingAt: lastIndex.
-               aStream basicNextPutAll: (latin1Encodings at: (aString  
byteAt: nextIndex)+1).
-               lastIndex := nextIndex + 1].
-       aStream next: aString size-lastIndex+1 putAll: aString startingAt:  
lastIndex.
-       ^self
- !



Reply | Threaded
Open this post in threaded view
|

Re: Issue 3663 in pharo: XMLWriter and MultiByteFileStream

pharo

Comment #2 on issue 3663 by [hidden email]: XMLWriter and  
MultiByteFileStream
http://code.google.com/p/pharo/issues/detail?id=3663

should take as a version to compare with 135


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3663 in pharo: XMLWriter and MultiByteFileStream

pharo

Comment #3 on issue 3663 by [hidden email]: XMLWriter and  
MultiByteFileStream
http://code.google.com/p/pharo/issues/detail?id=3663

  ----- Method: MultiByteFileStreamTest>>testNextPutAllStartingAt (in  
category 'testing') -----
  testNextPutAllStartingAt

        | result |
        fileName := 'foonextputallstartingat.txt'.
        MultiByteFileStream forceNewFileNamed: fileName do: [ :file |
+               { 'abcde' asWideString. 'abcde' } do: [ :string |
+                       file
+                               next: 1 putAll: string startingAt: 5;
+                               next: 3 putAll: string startingAt: 2;
+                               next: 1 putAll: string startingAt: 1 ] ].
-               file
-                       next: 1 putAll: 'abcde' startingAt: 5;
-                       next: 3 putAll: 'abcde' startingAt: 2;
-                       next: 1 putAll: 'abcde' startingAt: 1 ].
        result := StandardFileStream readOnlyFileNamed: fileName do: [ :file  
|
                file binary; contents ].
+       self assert: #[101 98 99 100 97 101 98 99 100 97] equals: result
-       self assert: #[101 98 99 100 97] equals: result


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3663 in pharo: XMLWriter and MultiByteFileStream

pharo
Updates:
        Labels: -Milestone-1.3

Comment #4 on issue 3663 by [hidden email]: XMLWriter and  
MultiByteFileStream
http://code.google.com/p/pharo/issues/detail?id=3663

(No comment was entered for this change.)