22428
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
8148
|
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 |
"
|
8079
|
14 |
"{ Package: 'stx:libbasic' }"
|
|
15 |
|
|
16 |
"{ NameSpace: CharacterEncoderImplementations }"
|
|
17 |
|
22479
|
18 |
FixedBytesEncoder subclass:#TwoByteEncoder
|
8079
|
19 |
instanceVariableNames:''
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'Collections-Text-Encodings'
|
|
23 |
!
|
|
24 |
|
8148
|
25 |
!TwoByteEncoder 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 |
"
|
21306
|
39 |
!
|
|
40 |
|
|
41 |
documentation
|
|
42 |
"
|
|
43 |
abstract superclass of all two-byte encoders
|
|
44 |
"
|
8148
|
45 |
! !
|
8079
|
46 |
|
|
47 |
!TwoByteEncoder class methodsFor:'queries'!
|
|
48 |
|
21306
|
49 |
isAbstract
|
|
50 |
"Return if this class is an abstract class.
|
|
51 |
True is returned here; false for subclasses.
|
|
52 |
Abstract subclasses must redefine this again."
|
|
53 |
|
|
54 |
^ self == CharacterEncoderImplementations::TwoByteEncoder
|
|
55 |
!
|
|
56 |
|
8079
|
57 |
maxCode
|
|
58 |
^ 16rFFFF
|
22479
|
59 |
! !
|
|
60 |
|
|
61 |
!TwoByteEncoder methodsFor:'encoding & decoding'!
|
|
62 |
|
|
63 |
encodeString:aUnicodeString
|
|
64 |
"given a string in unicode, return a string in my encoding for it"
|
|
65 |
|
|
66 |
|newString myCode stringSize "{ Class: SmallInteger }"|
|
8079
|
67 |
|
22479
|
68 |
stringSize := aUnicodeString size.
|
|
69 |
newString := self newString:stringSize.
|
|
70 |
|
|
71 |
1 to:stringSize do:[:idx |
|
|
72 |
myCode := self encode:((aUnicodeString at:idx) codePoint).
|
|
73 |
newString at:idx put:(Character codePoint:myCode).
|
|
74 |
].
|
|
75 |
^ newString
|
|
76 |
|
|
77 |
"Created: / 17-01-2018 / 16:33:52 / stefan"
|
8079
|
78 |
! !
|
|
79 |
|
11995
|
80 |
!TwoByteEncoder methodsFor:'queries'!
|
|
81 |
|
22428
|
82 |
characterSize:charOrCodePoint
|
21141
|
83 |
"return the number of bytes required to encode codePoint"
|
11995
|
84 |
|
22479
|
85 |
^ 2
|
11995
|
86 |
|
|
87 |
"Created: / 15-06-2005 / 15:12:01 / janfrog"
|
22479
|
88 |
"Modified (format): / 16-01-2018 / 22:32:03 / stefan"
|
|
89 |
!
|
|
90 |
|
|
91 |
newString:size
|
|
92 |
^ TwoByteString new:size.
|
|
93 |
|
|
94 |
"Created: / 17-01-2018 / 16:36:56 / stefan"
|
11995
|
95 |
! !
|
|
96 |
|
12434
|
97 |
!TwoByteEncoder methodsFor:'stream support'!
|
|
98 |
|
22479
|
99 |
encodeCharacter:aUnicodeCharacterOrCodePoint on:aStream
|
|
100 |
"given a character in unicode, encode it onto aStream.
|
|
101 |
Subclasses can redefine this to avoid allocating many new string instances."
|
|
102 |
|
|
103 |
aStream nextPutInt16:(self encode:aUnicodeCharacterOrCodePoint codePoint) MSB:false.
|
12434
|
104 |
|
22479
|
105 |
"
|
|
106 |
CharacterEncoderImplementations::ISO8859_10 new encodeCharacter:260 on:Transcript
|
|
107 |
CharacterEncoderImplementations::ISO8859_10 new encodeCharacter:$Ą on:Transcript
|
|
108 |
"
|
|
109 |
|
|
110 |
"Created: / 17-01-2018 / 16:41:09 / stefan"
|
12434
|
111 |
!
|
|
112 |
|
22479
|
113 |
readNextCharacterFrom:aStream
|
|
114 |
| codePoint |
|
|
115 |
|
|
116 |
codePoint := aStream nextUnsignedInt16MSB:false.
|
|
117 |
^ codePoint isNil
|
|
118 |
ifTrue: [nil]
|
|
119 |
ifFalse: [Character codePoint:codePoint]
|
|
120 |
|
|
121 |
"Modified: / 16-01-2018 / 22:30:36 / stefan"
|
12434
|
122 |
! !
|
|
123 |
|
8079
|
124 |
!TwoByteEncoder class methodsFor:'documentation'!
|
|
125 |
|
|
126 |
version
|
19215
|
127 |
^ '$Header$'
|
12434
|
128 |
!
|
|
129 |
|
|
130 |
version_CVS
|
19215
|
131 |
^ '$Header$'
|
8079
|
132 |
! !
|
19215
|
133 |
|