X Tutup
Skip to content

Commit 2bd416b

Browse files
author
Johan Brichau
committed
Keep the old utf8 text converter implementation for those who want to migrate
1 parent 59fdaf6 commit 2bd416b

File tree

19 files changed

+103
-5
lines changed

19 files changed

+103
-5
lines changed

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

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
private
2+
basicForEncoding: aString
3+
^ self new
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
accessing
2+
codecs
3+
^ GRPlatform current utf8CodecClass == self
4+
ifTrue:[ Array with: self new ]
5+
ifFalse: [ Array new ]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
testing
2+
supportsEncoding: aString
3+
^ GRPlatform current utf8CodecClass == self and: [(#('utf-8' 'UTF-8') includes: aString) or: [ UTF8TextConverter encodingNames includes: aString ] ]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
convenience
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
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
convenience
2+
decoderFor: aStream
3+
^ GRPharoUtf8CodecStream
4+
on: aStream
5+
converter: UTF8TextConverter new
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
conversion
2+
encodedStringClass
3+
^ String
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
convenience
2+
encoderFor: aStream
3+
^ GRPharoUtf8CodecStream
4+
on: aStream
5+
converter: UTF8TextConverter new
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
convenience
2+
invalidUtf8
3+
^ GRInvalidUtf8Error signal: 'Invalid UTF-8 input'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
accessing
2+
name
3+
^ 'utf-8'

0 commit comments

Comments
 (0)
X Tutup