break long packedStrings after every 120 chars.
Skip cr's and tabs when reading back.
--- a/ByteArray.st Fri Sep 24 15:05:25 1999 +0200
+++ b/ByteArray.st Fri Sep 24 20:18:24 1999 +0200
@@ -100,48 +100,56 @@
sz := aString size.
sz == 0 ifTrue:[^ self new].
+ sz := sz - (aString occurrencesOf:Character cr).
+ sz := sz - (aString occurrencesOf:Character tab).
+
stop := sz // 4 * 3.
"the size modulo 3 is encoded in the last character, if its in the
range 97 .. otherwise, its exact."
lastCharacter := aString last.
lastCharacter asciiValue > 96 ifTrue:[
- stop := stop - 3 + lastCharacter asciiValue - 96
+ stop := stop - 3 + lastCharacter asciiValue - 96
].
bytes := self new:stop.
index := 1. dstIndex := 1.
[dstIndex <= stop] whileTrue:[
- "take 4 characters ..."
- sixBits := (aString at:index) asciiValue.
- sixBits := sixBits bitAnd:16r3F.
- n := sixBits.
+ "/ take 4 characters ...
+ "/ cg: allow lineBreak befor eeach group of 4
+ sixBits := (aString at:index) asciiValue.
+ [sixBits < 32] whileTrue:[
+ index := index + 1.
+ sixBits := (aString at:index) asciiValue.
+ ].
+ sixBits := sixBits bitAnd:16r3F.
+ n := sixBits.
- sixBits := (aString at:index+1) asciiValue.
- sixBits := sixBits bitAnd:16r3F.
- n := (n bitShift:6) + sixBits.
+ sixBits := (aString at:index+1) asciiValue.
+ sixBits := sixBits bitAnd:16r3F.
+ n := (n bitShift:6) + sixBits.
- sixBits := (aString at:index+2) asciiValue.
- sixBits := sixBits bitAnd:16r3F.
- n := (n bitShift:6) + sixBits.
+ sixBits := (aString at:index+2) asciiValue.
+ sixBits := sixBits bitAnd:16r3F.
+ n := (n bitShift:6) + sixBits.
- sixBits := (aString at:index+3) asciiValue.
- sixBits := sixBits bitAnd:16r3F.
- n := (n bitShift:6) + sixBits.
+ sixBits := (aString at:index+3) asciiValue.
+ sixBits := sixBits bitAnd:16r3F.
+ n := (n bitShift:6) + sixBits.
- index := index + 4.
+ index := index + 4.
- "/ now have 24 bits in n
+ "/ now have 24 bits in n
- bytes at:dstIndex put:(n bitShift:-16).
+ bytes at:dstIndex put:(n bitShift:-16).
- dstIndex < stop ifTrue:[
- bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF).
- dstIndex+2 <= stop ifTrue:[
- bytes at:dstIndex+2 put:(n bitAnd:16rFF).
- ]
- ].
- dstIndex := dstIndex + 3.
+ dstIndex < stop ifTrue:[
+ bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF).
+ dstIndex+2 <= stop ifTrue:[
+ bytes at:dstIndex+2 put:(n bitAnd:16rFF).
+ ]
+ ].
+ dstIndex := dstIndex + 3.
].
^ bytes
@@ -2040,34 +2048,46 @@
nextIndex "{ Class:SmallInteger}"
stop "{ Class:SmallInteger}"
n "{ Class:SmallInteger}"
- mod "{ Class:SmallInteger}"|
+ mod "{ Class:SmallInteger}"
+ cpl|
outStream := WriteStream on:String new.
+ cpl := 0.
index := 1.
stop := self size.
[index <= stop] whileTrue:[
- "take 3 source bytes"
- n := (self at:index) bitShift:16.
- (index < stop) ifTrue:[
- nextIndex := index + 1.
- n := n bitOr:((self at:nextIndex) bitShift:8).
- (nextIndex < stop) ifTrue:[
- n := n bitOr:(self at:(index + 2)).
- ].
- ].
+ "take 3 source bytes"
+ n := (self at:index) bitShift:16.
+ (index < stop) ifTrue:[
+ nextIndex := index + 1.
+ n := n bitOr:((self at:nextIndex) bitShift:8).
+ (nextIndex < stop) ifTrue:[
+ n := n bitOr:(self at:(index + 2)).
+ ].
+ ].
+
+ "took me a while to find that one out ..."
+ n := n bitXor:16r820820.
- "took me a while to find that one out ..."
- n := n bitXor:16r820820.
+ outStream nextPut:(Character value:(n bitShift:-18) + 32).
+ outStream nextPut:(Character value:((n bitShift:-12) bitAnd:16r3F) + 32).
+ outStream nextPut:(Character value:((n bitShift:-6) bitAnd:16r3F) + 32).
+ outStream nextPut:(Character value:(n bitAnd:16r3F) + 32).
+ index := index + 3.
- outStream nextPut:(Character value:(n bitShift:-18) + 32).
- outStream nextPut:(Character value:((n bitShift:-12) bitAnd:16r3F) + 32).
- outStream nextPut:(Character value:((n bitShift:-6) bitAnd:16r3F) + 32).
- outStream nextPut:(Character value:(n bitAnd:16r3F) + 32).
- index := index + 3.
+ "/ cg:
+ "/ lineBreak after every 120 characters
+ "/ fromPackedString will ignore those
+ cpl := cpl + 4.
+ cpl >= 120 ifTrue:[
+ outStream nextPut:Character cr.
+ outStream nextPut:Character tab.
+ cpl := 0.
+ ].
].
(mod := stop \\ 3) ~~ 0 ifTrue:[
- outStream position:(outStream position - 1).
- outStream nextPut:(Character value:(mod + 96)).
+ outStream position:(outStream position - 1).
+ outStream nextPut:(Character value:(mod + 96)).
].
^ outStream contents
@@ -2362,5 +2382,5 @@
!ByteArray class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.120 1999-09-24 13:04:22 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.121 1999-09-24 18:18:24 cg Exp $'
! !