X Tutup
Skip to content

Commit 4e314bc

Browse files
author
Johan Brichau
committed
Use ZnUTF8Encoder in Pharo9
1 parent 66c03f6 commit 4e314bc

File tree

21 files changed

+63
-68
lines changed

21 files changed

+63
-68
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
public
22
nextInt: anInteger
3+
34
"Answer a random integer in the interval [1, anInteger]"
45

5-
^ mutex critical: [ generator nextInt: anInteger ]
6+
^ mutex critical: [ generator nextInteger: anInteger ]
Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,3 @@
1-
decoding
2-
decode: aString
3-
"Convert the given string from UTF-8 using the fast path if converting to Latin-1"
4-
| outStream byte1 byte2 byte3 byte4 unicode stream |
5-
stream := aString readStream.
6-
outStream := WriteStream on: (String new: aString size).
7-
[ stream atEnd not ] whileTrue: [
8-
byte1 := stream next asInteger.
9-
unicode := byte1.
10-
(byte1 bitAnd: 16rE0) = 192 ifTrue: [ "two bytes"
11-
byte2 := stream next asInteger.
12-
(byte2 bitAnd: 16rC0) = 16r80 ifFalse: [ self invalidUtf8 ].
13-
unicode := ((byte1 bitAnd: 31) bitShift: 6) + (byte2 bitAnd: 63) ].
14-
(byte1 bitAnd: 16rF0) = 224 ifTrue: [ "three bytes"
15-
byte2 := stream next asInteger.
16-
(byte2 bitAnd: 16rC0) = 16r80 ifFalse: [ self invalidUtf8 ].
17-
byte3 := stream next asInteger.
18-
(byte3 bitAnd: 16rC0) = 16r80 ifFalse: [ self invalidUtf8 ].
19-
unicode := ((byte1 bitAnd: 15) bitShift: 12) + ((byte2 bitAnd: 63) bitShift: 6)
20-
+ (byte3 bitAnd: 63) ].
21-
(byte1 bitAnd: 16rF8) = 240 ifTrue: [ "four bytes"
22-
byte2 := stream next asInteger.
23-
(byte2 bitAnd: 16rC0) = 16r80 ifFalse: [ self invalidUtf8 ].
24-
byte3 := stream next asInteger.
25-
(byte3 bitAnd: 16rC0) = 16r80 ifFalse: [ self invalidUtf8 ].
26-
byte4 := stream next asInteger.
27-
(byte4 bitAnd: 16rC0) = 16r80 ifFalse: [ self invalidUtf8 ].
28-
unicode := ((byte1 bitAnd: 16r7) bitShift: 18) +
29-
((byte2 bitAnd: 63) bitShift: 12) +
30-
((byte3 bitAnd: 63) bitShift: 6) +
31-
(byte4 bitAnd: 63) ].
32-
unicode ifNil: [ self invalidUtf8 ].
33-
unicode = 16rFEFF "ignore BOM" ifFalse: [
34-
outStream nextPut: (Character codePoint: unicode) ].
35-
unicode := nil ].
36-
^ outStream contents
1+
convenience
2+
decode: aByteArray
3+
^ aByteArray utf8Decoded
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
conversion
22
decoderFor: aStream
3-
^ GRPharoUtf8CodecStream
3+
^ GRPharoConverterCodecStream
44
on: aStream
5-
converter: UTF8TextConverter new
5+
converter: ZnCharacterEncoder utf8
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
convenience
2+
encode: aString
3+
| writeStream |
4+
writeStream := self encoderFor: (ByteArray new: aString size) writeStream.
5+
writeStream nextPutAll: aString.
6+
^ writeStream contents
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
conversion
22
encoderFor: aStream
3-
^ GRPharoUtf8CodecStream
3+
^ GRPharoConverterCodecStream
44
on: aStream
5-
converter: UTF8TextConverter new
5+
converter: ZnUTF8Encoder new

repository/Grease-Pharo90-Core.package/GRZnUtf8CodecStream.class/README.md

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
streaming
2+
nextPutAll: aString
3+
"Convert the given string from UTF-8 using the fast path if converting to Latin-1"
4+
1 to: aString size by: 1 do: [ :index |
5+
converter nextPut: (aString at: index) toStream: stream ]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"commentStamp" : "",
3+
"super" : "GRPharoConverterCodecStream",
4+
"category" : "Grease-Pharo90-Core",
5+
"classinstvars" : [ ],
6+
"pools" : [ ],
7+
"classvars" : [
8+
"Latin1ToUtf8Encodings",
9+
"Latin1ToUtf8Map"
10+
],
11+
"instvars" : [ ],
12+
"name" : "GRZnUtf8CodecStream",
13+
"type" : "normal"
14+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
running
22
setUp
33
| codecStream |
4-
codecStream := ((GRCodec forEncoding: 'utf-8') encoderFor: (WriteStream on: String new)).
4+
codecStream := ((GRCodec forEncoding: 'utf-8') encoderFor: (WriteStream on: ByteArray new)).
55
countingStream := GRCountingStream on: codecStream

repository/Grease-Tests-Core.package/GRCountingStreamTest.class/instance/testNextPut.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ testNextPut
33
countingStream nextPut: (Character codePoint: 16rE4).
44
self assert: countingStream size = 2.
55
self assert: countingStream count = 1.
6-
self assert: countingStream contents = (String with: (Character codePoint: 16rC3) with: (Character codePoint: 16rA4))
6+
self assert: countingStream contents = (String with: (Character codePoint: 16rC3) with: (Character codePoint: 16rA4)) asByteArray

0 commit comments

Comments
 (0)
X Tutup