22461
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
|
3 |
"
|
|
4 |
COPYRIGHT (c) 2004 by eXept Software AG
|
|
5 |
All Rights Reserved
|
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
|
14 |
"{ Package: 'stx:libbasic' }"
|
|
15 |
|
|
16 |
"{ NameSpace: CharacterEncoderImplementations }"
|
|
17 |
|
|
18 |
CharacterEncoder subclass:#FixedBytesEncoder
|
|
19 |
instanceVariableNames:''
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'Collections-Text-Encodings'
|
|
23 |
!
|
|
24 |
|
|
25 |
!FixedBytesEncoder class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 2004 by eXept Software AG
|
|
30 |
All Rights Reserved
|
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
|
41 |
documentation
|
|
42 |
"
|
|
43 |
Common abstract superclass for all encodings which encode to a fixed number of bytes.
|
|
44 |
|
|
45 |
[author:]
|
|
46 |
Stefan Vogel
|
|
47 |
"
|
|
48 |
! !
|
|
49 |
|
|
50 |
!FixedBytesEncoder class methodsFor:'queries'!
|
|
51 |
|
|
52 |
isAbstract
|
|
53 |
"Return if this class is an abstract class.
|
|
54 |
True is returned here; false for subclasses.
|
|
55 |
Abstract subclasses must redefine this again."
|
|
56 |
|
|
57 |
^ self == CharacterEncoderImplementations::FixedBytesEncoder
|
|
58 |
|
|
59 |
"Modified: / 17-01-2018 / 17:06:13 / stefan"
|
|
60 |
!
|
|
61 |
|
|
62 |
maxCode
|
|
63 |
^ self subclassResponsibility
|
|
64 |
|
|
65 |
"Modified: / 17-01-2018 / 16:54:48 / stefan"
|
|
66 |
!
|
|
67 |
|
|
68 |
minCode
|
|
69 |
^ 0
|
|
70 |
! !
|
|
71 |
|
|
72 |
!FixedBytesEncoder methodsFor:'encoding & decoding'!
|
|
73 |
|
|
74 |
decode:anEncoding
|
|
75 |
"given an integer in my encoding, return a unicode codePoint for it"
|
|
76 |
|
|
77 |
self subclassResponsibility
|
|
78 |
!
|
|
79 |
|
|
80 |
decodeString:anEncodedStringOrByteCollection
|
|
81 |
"given a string in my encoding, return a unicode-string for it"
|
|
82 |
|
|
83 |
|newString myCode code bits size "{ Class:SmallInteger }"|
|
|
84 |
|
|
85 |
size := anEncodedStringOrByteCollection size.
|
|
86 |
newString := String new:size.
|
|
87 |
bits := newString bitsPerCharacter.
|
|
88 |
|
|
89 |
1 to:size do:[:idx |
|
|
90 |
code := (anEncodedStringOrByteCollection at:idx) codePoint.
|
|
91 |
myCode := self decode:code.
|
|
92 |
myCode > 16rFF ifTrue:[
|
|
93 |
myCode > 16rFFFF ifTrue:[
|
|
94 |
bits < 32 ifTrue:[
|
|
95 |
newString := Unicode32String fromString:newString.
|
|
96 |
bits := 32.
|
|
97 |
]
|
|
98 |
] ifFalse:[
|
|
99 |
bits < 16 ifTrue:[
|
|
100 |
newString := Unicode16String fromString:newString.
|
|
101 |
bits := 16.
|
|
102 |
]
|
|
103 |
]
|
|
104 |
].
|
|
105 |
newString at:idx put:(Character codePoint:myCode).
|
|
106 |
].
|
|
107 |
^ newString
|
|
108 |
|
|
109 |
"
|
|
110 |
CharacterEncoderImplementations::ISO8859_1 decodeString:'hello'
|
|
111 |
"
|
|
112 |
|
|
113 |
"Created: / 16-01-2018 / 19:54:02 / stefan"
|
|
114 |
"Modified (format): / 17-01-2018 / 16:30:59 / stefan"
|
|
115 |
!
|
|
116 |
|
|
117 |
encode:aCodePoint
|
|
118 |
"given a codePoint in unicode, return a single byte in my encoding for it"
|
|
119 |
|
|
120 |
self subclassResponsibility
|
|
121 |
|
|
122 |
"Modified (comment): / 17-01-2018 / 14:52:28 / stefan"
|
|
123 |
!
|
|
124 |
|
|
125 |
encodeCharacter:aUnicodeCharacterOrCodePoint
|
|
126 |
"encode aUnicodeCharacterOrCodePoint to a (8-bit) String or ByteArray"
|
|
127 |
|
|
128 |
^ (Character codePoint:(self encode:aUnicodeCharacterOrCodePoint codePoint)) asString.
|
|
129 |
|
|
130 |
"
|
|
131 |
CharacterEncoderImplementations::ISO8859_10 new encodeCharacter:260
|
|
132 |
CharacterEncoderImplementations::ISO8859_10 new encodeCharacter:$Ą
|
|
133 |
"
|
|
134 |
|
|
135 |
"Created: / 17-01-2018 / 14:13:03 / stefan"
|
|
136 |
! !
|
|
137 |
|
|
138 |
!FixedBytesEncoder class methodsFor:'documentation'!
|
|
139 |
|
|
140 |
version
|
|
141 |
^ '$Header$'
|
|
142 |
!
|
|
143 |
|
|
144 |
version_CVS
|
|
145 |
^ '$Header$'
|
|
146 |
! !
|
|
147 |
|