1 " |
1 " |
2 COPYRIGHT (c) 1993 by Claus Gittinger |
2 COPYRIGHT (c) 1993 by Claus Gittinger |
3 All Rights Reserved |
3 All Rights Reserved |
4 |
4 |
5 This software is furnished under a license and may be used |
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 |
6 only in accordance with the terms of that license and with the |
7 inclusion of the above copyright notice. This software may not |
7 inclusion of the above copyright notice. This software may not |
8 be provided or otherwise made available to, or used by, any |
8 be provided or otherwise made available to, or used by, any |
17 category:'Collections-Text' |
17 category:'Collections-Text' |
18 ! |
18 ! |
19 |
19 |
20 TwoByteString comment:' |
20 TwoByteString comment:' |
21 COPYRIGHT (c) 1993 by Claus Gittinger |
21 COPYRIGHT (c) 1993 by Claus Gittinger |
22 All Rights Reserved |
22 All Rights Reserved |
23 |
23 |
24 $Header: /cvs/stx/stx/libbasic/TwoByteString.st,v 1.8 1994-08-05 01:07:48 claus Exp $ |
24 $Header: /cvs/stx/stx/libbasic/TwoByteString.st,v 1.9 1995-02-05 23:38:45 claus Exp $ |
25 '! |
25 '! |
26 |
26 |
27 !TwoByteString class methodsFor:'documentation'! |
27 !TwoByteString class methodsFor:'documentation'! |
28 |
28 |
29 copyright |
29 copyright |
30 " |
30 " |
31 COPYRIGHT (c) 1993 by Claus Gittinger |
31 COPYRIGHT (c) 1993 by Claus Gittinger |
32 All Rights Reserved |
32 All Rights Reserved |
33 |
33 |
34 This software is furnished under a license and may be used |
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 |
35 only in accordance with the terms of that license and with the |
36 inclusion of the above copyright notice. This software may not |
36 inclusion of the above copyright notice. This software may not |
37 be provided or otherwise made available to, or used by, any |
37 be provided or otherwise made available to, or used by, any |
57 |
57 |
58 basicNew:anInteger |
58 basicNew:anInteger |
59 "return a new empty string with anInteger characters" |
59 "return a new empty string with anInteger characters" |
60 |
60 |
61 ^ (super basicNew:(anInteger*2)) atAllPut:(Character space) |
61 ^ (super basicNew:(anInteger*2)) atAllPut:(Character space) |
|
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 " |
62 ! ! |
202 ! ! |
63 |
203 |
64 !TwoByteString methodsFor:'queries'! |
204 !TwoByteString methodsFor:'queries'! |
65 |
205 |
66 basicSize |
206 basicSize |