9 other person. No title to or ownership of the software is |
11 other person. No title to or ownership of the software is |
10 hereby transferred. |
12 hereby transferred. |
11 " |
13 " |
12 "{ Package: 'stx:libbasic' }" |
14 "{ Package: 'stx:libbasic' }" |
13 |
15 |
|
16 "{ NameSpace: Smalltalk }" |
|
17 |
14 CharacterArray variableWordSubclass:#TwoByteString |
18 CharacterArray variableWordSubclass:#TwoByteString |
15 instanceVariableNames:'' |
19 instanceVariableNames:'' |
16 classVariableNames:'' |
20 classVariableNames:'' |
17 poolDictionaries:'' |
21 poolDictionaries:'' |
18 category:'Collections-Text' |
22 category:'Collections-Text' |
68 "return a new empty string with anInteger characters" |
72 "return a new empty string with anInteger characters" |
69 |
73 |
70 ^ (super basicNew:anInteger) atAllPut:(Character space) |
74 ^ (super basicNew:anInteger) atAllPut:(Character space) |
71 |
75 |
72 "Modified: 26.2.1996 / 14:38:47 / cg" |
76 "Modified: 26.2.1996 / 14:38:47 / cg" |
|
77 ! |
|
78 |
|
79 uninitializedNew:anInteger |
|
80 "return a new empty string with anInteger characters" |
|
81 |
|
82 ^ super basicNew:anInteger |
|
83 |
|
84 " |
|
85 self uninitializedNew:10 |
|
86 " |
73 ! ! |
87 ! ! |
74 |
88 |
75 !TwoByteString methodsFor:'accessing'! |
89 !TwoByteString methodsFor:'accessing'! |
76 |
90 |
77 basicAt:index |
91 basicAt:index |
99 |
113 |
100 unsignedShortAt:index |
114 unsignedShortAt:index |
101 "return the short at position index, an Integer" |
115 "return the short at position index, an Integer" |
102 |
116 |
103 ^ super basicAt:index. |
117 ^ super basicAt:index. |
|
118 ! ! |
|
119 |
|
120 !TwoByteString methodsFor:'encoding'! |
|
121 |
|
122 utf8Encoded |
|
123 "Return my UTF-8 representation as a new String" |
|
124 |
|
125 self contains8BitCharacters ifTrue:[ |
|
126 ^ self basicUtf8Encoded. |
|
127 ]. |
|
128 |
|
129 ^ self asSingleByteString. |
|
130 |
|
131 |
|
132 " |
|
133 'abcdef' asUnicode16String utf8Encoded |
|
134 'abcdefäöü' asUnicode16String utf8Encoded |
|
135 " |
|
136 ! |
|
137 |
|
138 utf8EncodedOn:aStream |
|
139 "write to aStream in utf8 encoding" |
|
140 |
|
141 self contains8BitCharacters ifTrue:[ |
|
142 aStream nextPutAllUtf8:self. |
|
143 ] ifFalse:[ |
|
144 |sz "{Class: SmallInteger}"| |
|
145 |
|
146 sz := self size. |
|
147 1 to:sz do:[:idx| |
|
148 aStream nextPut:(self basicAt:idx). |
|
149 ]. |
|
150 ]. |
|
151 |
|
152 " |
|
153 |s| |
|
154 s := '' writeStream. |
|
155 'abcdef' asUnicode16String utf8EncodedOn:s. |
|
156 s contents |
|
157 " |
|
158 |
|
159 " |
|
160 |s| |
|
161 s := '' writeStream. |
|
162 'abcdefäöü' asUnicode16String utf8EncodedOn:s. |
|
163 s contents |
|
164 " |
104 ! ! |
165 ! ! |
105 |
166 |
106 !TwoByteString methodsFor:'filling and replacing'! |
167 !TwoByteString methodsFor:'filling and replacing'! |
107 |
168 |
108 replaceFrom:start to:stop with:aString startingAt:repStart |
169 replaceFrom:start to:stop with:aString startingAt:repStart |
200 ^ 16 |
261 ^ 16 |
201 |
262 |
202 "Modified: 20.4.1996 / 23:08:38 / cg" |
263 "Modified: 20.4.1996 / 23:08:38 / cg" |
203 ! |
264 ! |
204 |
265 |
|
266 contains8BitCharacters |
|
267 "return true, if the underlying string contains 8BitCharacters (or widers) |
|
268 (i.e. if it is non-ascii)" |
|
269 |
|
270 %{ /* NOCONTEXT */ |
|
271 |
|
272 REGISTER unsigned short *sp, *last; |
|
273 OBJ cls; |
|
274 |
|
275 sp = __twoByteStringVal(self); |
|
276 last = sp + __twoByteStringSize(self); |
|
277 if ((cls = __qClass(self)) != TwoByteString && cls != Unicode16String) { |
|
278 sp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)) / 2; |
|
279 } |
|
280 #if __POINTER_SIZE__ == 8 |
|
281 /* assume sizeof(long) == 4 |
|
282 * if __POINTER_SIZE__ == 4 |
|
283 */ |
|
284 if (sizeof(long) == 8) { |
|
285 while ((sp+4) <= last) { |
|
286 if (*(unsigned long *)sp & 0xFF80FF80FF80FF80) { |
|
287 RETURN ( true ); |
|
288 } |
|
289 sp += 4; |
|
290 } |
|
291 } |
|
292 #endif |
|
293 if (sizeof(int) == 4) { |
|
294 while ((sp+2) <= last) { |
|
295 if (*(unsigned int *)sp & 0xFF80FF80) { |
|
296 RETURN ( true ); |
|
297 } |
|
298 sp += 2; |
|
299 } |
|
300 } |
|
301 while (sp <= last) { |
|
302 if (*sp & 0xFF80) { |
|
303 RETURN ( true ); |
|
304 } |
|
305 sp++; |
|
306 } |
|
307 RETURN (false); |
|
308 %}. |
|
309 |
|
310 " |
|
311 'hello world' asUnicode16String contains8BitCharacters |
|
312 'hello worldüäö' asUnicode16String contains8BitCharacters |
|
313 'ü' asUnicode16String contains8BitCharacters |
|
314 'aü' asUnicode16String contains8BitCharacters |
|
315 'aaü' asUnicode16String contains8BitCharacters |
|
316 'aaaü' asUnicode16String contains8BitCharacters |
|
317 'aaaaü' asUnicode16String contains8BitCharacters |
|
318 " |
|
319 ! |
|
320 |
205 isWideString |
321 isWideString |
206 ^ true |
322 ^ true |
207 ! ! |
323 ! ! |
208 |
324 |
209 !TwoByteString class methodsFor:'documentation'! |
325 !TwoByteString class methodsFor:'documentation'! |
210 |
326 |
211 version |
327 version |
212 ^ '$Header: /cvs/stx/stx/libbasic/TwoByteString.st,v 1.35 2014-07-10 12:28:32 cg Exp $' |
328 ^ '$Header: /cvs/stx/stx/libbasic/TwoByteString.st,v 1.36 2015-03-14 21:30:22 stefan Exp $' |
213 ! ! |
329 ! ! |
214 |
330 |
215 |
331 |
216 TwoByteString initialize! |
332 TwoByteString initialize! |