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