75 PS: It took a while to figure that one out ... I dont like it ;-)" |
75 PS: It took a while to figure that one out ... I dont like it ;-)" |
76 |
76 |
77 |index "{ Class: SmallInteger }" |
77 |index "{ Class: SmallInteger }" |
78 dstIndex "{ Class: SmallInteger }" |
78 dstIndex "{ Class: SmallInteger }" |
79 stop "{ Class: SmallInteger }" |
79 stop "{ Class: SmallInteger }" |
80 n "{ Class: SmallInteger }" |
80 sixBits "{ Class: SmallInteger }" |
|
81 n "{ Class: SmallInteger }" |
81 sz "{ Class: SmallInteger }" |
82 sz "{ Class: SmallInteger }" |
82 lastCharacter bytes| |
83 lastCharacter bytes| |
83 |
84 |
84 sz := aString size. |
85 sz := aString size. |
85 sz == 0 ifTrue:[^ self new]. |
86 sz == 0 ifTrue:[^ self new]. |
87 "the size modulu 3 is encoded in the last character, if its in the |
88 "the size modulu 3 is encoded in the last character, if its in the |
88 range 97 .. otherwise, its exact." |
89 range 97 .. otherwise, its exact." |
89 |
90 |
90 lastCharacter := aString last. |
91 lastCharacter := aString last. |
91 lastCharacter asciiValue > 96 ifTrue:[ |
92 lastCharacter asciiValue > 96 ifTrue:[ |
92 stop := stop - 3 + lastCharacter asciiValue - 96 |
93 stop := stop - 3 + lastCharacter asciiValue - 96 |
93 ]. |
94 ]. |
94 bytes := self new:stop. |
95 bytes := self new:stop. |
|
96 |
95 index := 1. dstIndex := 1. |
97 index := 1. dstIndex := 1. |
96 [dstIndex <= stop] whileTrue:[ |
98 [dstIndex <= stop] whileTrue:[ |
97 "take 4 characters ..." |
99 "take 4 characters ..." |
98 n := (aString at:index) asciiValue - 32. |
100 sixBits := (aString at:index) asciiValue. |
99 n := (n bitShift:6) + ((aString at:index+1) asciiValue - 32). |
101 sixBits := sixBits bitAnd:16r3F. |
100 n := (n bitShift:6) + ((aString at:index+2) asciiValue - 32). |
102 n := sixBits. |
101 n := (n bitShift:6) + ((aString at:index+3) asciiValue - 32). |
103 |
102 n := n bitXor:16r820820. |
104 sixBits := (aString at:index+1) asciiValue. |
103 index := index + 4. |
105 sixBits := sixBits bitAnd:16r3F. |
104 bytes at:dstIndex put:(n bitShift:-16). |
106 n := (n bitShift:6) + sixBits. |
105 dstIndex < stop ifTrue:[ |
107 |
106 bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF). |
108 sixBits := (aString at:index+2) asciiValue. |
107 dstIndex+2 <= stop ifTrue:[ |
109 sixBits := sixBits bitAnd:16r3F. |
108 bytes at:dstIndex+2 put:(n bitAnd:16rFF). |
110 n := (n bitShift:6) + sixBits. |
109 ] |
111 |
110 ]. |
112 sixBits := (aString at:index+3) asciiValue. |
111 dstIndex := dstIndex + 3. |
113 sixBits := sixBits bitAnd:16r3F. |
|
114 n := (n bitShift:6) + sixBits. |
|
115 |
|
116 index := index + 4. |
|
117 |
|
118 "/ now have 24 bits in n |
|
119 |
|
120 bytes at:dstIndex put:(n bitShift:-16). |
|
121 |
|
122 dstIndex < stop ifTrue:[ |
|
123 bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF). |
|
124 dstIndex+2 <= stop ifTrue:[ |
|
125 bytes at:dstIndex+2 put:(n bitAnd:16rFF). |
|
126 ] |
|
127 ]. |
|
128 dstIndex := dstIndex + 3. |
112 ]. |
129 ]. |
113 ^ bytes |
130 ^ bytes |
114 |
131 |
115 " |
132 " |
116 ByteArray fromPackedString:(#[1 1 1 1] asPackedString) |
133 ByteArray fromPackedString:(#[1 1 1 1] asPackedString) |
118 ByteArray fromPackedString:(#[1 1 1 1 1 1] asPackedString) |
135 ByteArray fromPackedString:(#[1 1 1 1 1 1] asPackedString) |
119 ByteArray fromPackedString:(#[1 1 1 1 1 1 1] asPackedString) |
136 ByteArray fromPackedString:(#[1 1 1 1 1 1 1] asPackedString) |
120 ByteArray fromPackedString:(#[1 1 1 1 1 1 1 1] asPackedString) |
137 ByteArray fromPackedString:(#[1 1 1 1 1 1 1 1] asPackedString) |
121 |
138 |
122 " |
139 " |
|
140 |
|
141 "Modified: 6.3.1997 / 15:28:52 / cg" |
123 ! |
142 ! |
124 |
143 |
125 uninitializedNew:anInteger |
144 uninitializedNew:anInteger |
126 "return a new instance of the receiver with uninitialized |
145 "return a new instance of the receiver with uninitialized |
127 (i.e. undefined) contents. The indexed elements have any random |
146 (i.e. undefined) contents. The indexed elements have any random |