1
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
235
|
3 |
All Rights Reserved
|
1
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
256
|
13 |
CharacterArray subclass:#TwoByteString
|
1
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Collections-Text'
|
|
18 |
!
|
|
19 |
|
|
20 |
TwoByteString comment:'
|
|
21 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
235
|
22 |
All Rights Reserved
|
97
|
23 |
|
383
|
24 |
$Header: /cvs/stx/stx/libbasic/TwoByteString.st,v 1.12 1995-08-10 18:36:34 claus Exp $
|
89
|
25 |
'!
|
1
|
26 |
|
89
|
27 |
!TwoByteString class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
235
|
32 |
All Rights Reserved
|
1
|
33 |
|
89
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
383
|
45 |
$Header: /cvs/stx/stx/libbasic/TwoByteString.st,v 1.12 1995-08-10 18:36:34 claus Exp $
|
89
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
TwoByteStrings are like strings, but storing 16bits per character.
|
|
52 |
The integration of them into the system is not completed ....
|
|
53 |
"
|
|
54 |
! !
|
1
|
55 |
|
|
56 |
!TwoByteString class methodsFor:'instance creation'!
|
|
57 |
|
|
58 |
basicNew:anInteger
|
|
59 |
"return a new empty string with anInteger characters"
|
|
60 |
|
63
|
61 |
^ (super basicNew:(anInteger*2)) atAllPut:(Character space)
|
235
|
62 |
!
|
|
63 |
|
|
64 |
fromJISString:aString
|
|
65 |
"return a new string containing the characters of aString,
|
|
66 |
which are taken as JIS encoded."
|
|
67 |
|
|
68 |
|newString sz dstIdx singleBytes start stop n1 n2 n3 b1 b2 val|
|
|
69 |
|
|
70 |
sz := aString size.
|
|
71 |
newString := self new:sz.
|
|
72 |
sz ~~ 0 ifTrue:[
|
|
73 |
dstIdx := 1.
|
|
74 |
start := 1.
|
|
75 |
singleBytes := true.
|
|
76 |
|
|
77 |
[true] whileTrue:[
|
|
78 |
"scan for next escape"
|
|
79 |
stop := aString indexOf:(Character esc) startingAt:start.
|
|
80 |
stop == 0 ifTrue:[
|
|
81 |
stop := sz + 1.
|
|
82 |
] ifFalse:[
|
|
83 |
(stop + 2) > sz ifTrue:[
|
|
84 |
stop := sz + 1.
|
|
85 |
]
|
|
86 |
].
|
|
87 |
singleBytes ifTrue:[
|
|
88 |
newString replaceFrom:dstIdx to:(dstIdx + (stop - start - 1))
|
|
89 |
with:aString startingAt:start.
|
|
90 |
dstIdx := dstIdx + (stop - start).
|
|
91 |
] ifFalse:[
|
|
92 |
start to:(stop - 1) by:2 do:[:i |
|
|
93 |
b1 := (aString at:i) asciiValue.
|
|
94 |
b2 := (aString at:i+1) asciiValue.
|
|
95 |
val := (b1 bitShift:8) bitOr:b2.
|
|
96 |
newString at:dstIdx put:(Character value:val).
|
|
97 |
dstIdx := dstIdx + 1.
|
|
98 |
]
|
|
99 |
].
|
|
100 |
|
|
101 |
stop > sz ifTrue:[
|
|
102 |
^ newString copyFrom:1 to:dstIdx - 1.
|
|
103 |
].
|
|
104 |
start := stop.
|
|
105 |
|
|
106 |
"
|
|
107 |
found an escape (at index stop) - check for ESC $ B
|
|
108 |
"
|
|
109 |
n1 := aString at:start.
|
|
110 |
n2 := aString at:(start + 1).
|
|
111 |
n3 := aString at:(start + 2).
|
|
112 |
|
|
113 |
(n2 == $$ and:[n3 == $B]) ifTrue:[
|
|
114 |
singleBytes := false.
|
|
115 |
] ifFalse:[
|
|
116 |
(n2 == $( and:[n3 == $B]) ifTrue:[
|
|
117 |
singleBytes := true.
|
|
118 |
] ifFalse:[
|
|
119 |
newString at:dstIdx put:n1.
|
|
120 |
newString at:(dstIdx + 1) put:n2.
|
|
121 |
newString at:(dstIdx + 2) put:n3.
|
|
122 |
dstIdx := dstIdx + 3.
|
|
123 |
]
|
|
124 |
].
|
|
125 |
start := start + 3.
|
|
126 |
start > sz ifTrue:[
|
|
127 |
^ newString copyFrom:1 to:dstIdx-1.
|
|
128 |
]
|
|
129 |
]
|
|
130 |
].
|
|
131 |
^ newString
|
|
132 |
|
|
133 |
"
|
|
134 |
TwoByteString fromJISString:'hello'
|
|
135 |
|
|
136 |
|s|
|
|
137 |
s := 'hello' copyWith:Character esc.
|
|
138 |
TwoByteString fromJISString:s
|
|
139 |
|
|
140 |
|s|
|
|
141 |
s := 'hello' copyWith:Character esc.
|
|
142 |
s := s copyWith:$A.
|
|
143 |
TwoByteString fromJISString:s
|
|
144 |
|
|
145 |
|s|
|
|
146 |
s := 'hello' copyWith:Character esc.
|
|
147 |
s := s copyWith:$$.
|
|
148 |
TwoByteString fromJISString:s
|
|
149 |
|
|
150 |
|s|
|
|
151 |
s := 'hello' copyWith:Character esc.
|
|
152 |
s := s copyWith:$$.
|
|
153 |
s := s copyWith:$A.
|
|
154 |
TwoByteString fromJISString:s
|
|
155 |
|
|
156 |
|s|
|
|
157 |
s := 'hello' copyWith:Character esc.
|
|
158 |
s := s copyWith:$$.
|
|
159 |
s := s copyWith:$B.
|
|
160 |
TwoByteString fromJISString:s
|
|
161 |
|
|
162 |
|s|
|
|
163 |
s := 'hello' copyWith:Character esc.
|
|
164 |
s := s copyWith:$$.
|
|
165 |
s := s copyWith:$B.
|
|
166 |
s := s , '$N'.
|
|
167 |
TwoByteString fromJISString:s
|
|
168 |
|
|
169 |
|s|
|
|
170 |
s := 'hello' copyWith:Character esc.
|
|
171 |
s := s copyWith:$$.
|
|
172 |
s := s copyWith:$B.
|
|
173 |
s := s , '$N4A;z'.
|
|
174 |
TwoByteString fromJISString:s
|
|
175 |
|
|
176 |
|s|
|
|
177 |
s := 'hello' copyWith:Character esc.
|
|
178 |
s := s copyWith:$$.
|
|
179 |
s := s copyWith:$B.
|
|
180 |
s := s , '$N'.
|
|
181 |
s := s copyWith:Character esc.
|
|
182 |
s := s copyWith:$(.
|
|
183 |
s := s copyWith:$B.
|
|
184 |
s := s , 'hello'.
|
|
185 |
TwoByteString fromJISString:s
|
|
186 |
|
|
187 |
|s t l|
|
|
188 |
s := 'kterm ' copyWith:Character esc.
|
|
189 |
s := s copyWith:$$.
|
|
190 |
s := s copyWith:$B.
|
|
191 |
s := s , '$N4A;zC<Kv%(%_%e%l!!<%?'.
|
|
192 |
s := s copyWith:Character esc.
|
|
193 |
s := s copyWith:$(.
|
|
194 |
s := s copyWith:$B.
|
|
195 |
s := s , ' kterm'.
|
|
196 |
t := TwoByteString fromJISString:s.
|
|
197 |
l := Label new.
|
|
198 |
l label:t.
|
|
199 |
l font:(Font family:'k14' face:nil style:nil size:nil).
|
|
200 |
l realize
|
|
201 |
"
|
1
|
202 |
! !
|
|
203 |
|
63
|
204 |
!TwoByteString methodsFor:'queries'!
|
|
205 |
|
|
206 |
basicSize
|
|
207 |
"return the size of the receiver.
|
|
208 |
(i.e. the number of characters in this String)"
|
|
209 |
|
|
210 |
^ super basicSize // 2
|
|
211 |
! !
|
|
212 |
|
1
|
213 |
!TwoByteString methodsFor:'accessing'!
|
|
214 |
|
|
215 |
basicAt:index
|
|
216 |
"return the character at position index, an Integer
|
73
|
217 |
- reimplemented here since we return 16-bit characters"
|
1
|
218 |
|
63
|
219 |
|val i|
|
|
220 |
|
|
221 |
i := (index * 2) - 1.
|
73
|
222 |
"always msb first"
|
|
223 |
val := (super basicAt:(i+1)) + ((super basicAt:i) * 256).
|
63
|
224 |
^ Character value:val
|
1
|
225 |
!
|
|
226 |
|
|
227 |
basicAt:index put:aCharacter
|
|
228 |
"store the argument, aCharacter at position index, an Integer
|
73
|
229 |
- reimplemented here since we store 16-bit characters"
|
1
|
230 |
|
63
|
231 |
|val i|
|
|
232 |
val := aCharacter asciiValue.
|
|
233 |
i := (index * 2) - 1.
|
73
|
234 |
"always msb first"
|
|
235 |
super basicAt:(i+1) put:(val bitAnd:16rFF).
|
|
236 |
super basicAt:i put:(val // 256).
|
63
|
237 |
^ aCharacter
|
1
|
238 |
! !
|