author | Stefan Vogel <sv@exept.de> |
Tue, 28 Apr 2020 16:22:44 +0200 | |
changeset 25376 | 88a3329875ba |
parent 25203 | a3ba0cf0dd07 |
permissions | -rw-r--r-- |
7946 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3 |
All Rights Reserved |
|
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 |
" |
|
10223
761e2a050b69
twoByteString moved (req'd in VM)
Claus Gittinger <cg@exept.de>
parents:
9648
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
7946 | 13 |
|
17537 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
7946 | 16 |
TwoByteString variableWordSubclass:#Unicode16String |
17 |
instanceVariableNames:'' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Collections-Text' |
|
21 |
! |
|
22 |
||
23 |
!Unicode16String class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
||
37 |
||
38 |
" |
|
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
10223
761e2a050b69
twoByteString moved (req'd in VM)
Claus Gittinger <cg@exept.de>
parents:
9648
diff
changeset
|
43 |
Represents 16-bit (2-byte) Unicode strings. |
7946 | 44 |
" |
45 |
! ! |
|
46 |
||
47 |
!Unicode16String class methodsFor:'initialization'! |
|
48 |
||
49 |
initialize |
|
50 |
"initialize the class - private" |
|
51 |
||
7949 | 52 |
self flags:(Behavior flagWords). |
53 |
||
54 |
Smalltalk at:#UnicodeString put:Unicode16String. |
|
7946 | 55 |
|
56 |
" |
|
57 |
Unicode16String initialize |
|
58 |
" |
|
59 |
||
60 |
"Created: 30.6.1997 / 15:35:52 / cg" |
|
61 |
"Modified: 30.6.1997 / 15:39:21 / cg" |
|
62 |
! ! |
|
63 |
||
21544 | 64 |
|
65 |
||
11323 | 66 |
!Unicode16String class methodsFor:'reading'! |
67 |
||
68 |
readFrom:aStreamOrString onError:exceptionBlock |
|
69 |
"read & return the next String from the (character-)stream aStream; |
|
70 |
skipping all whitespace first; return the value of exceptionBlock, |
|
71 |
if no string can be read. The sequence of characters as read from the |
|
72 |
stream must be one as stored via storeOn: or storeString." |
|
73 |
||
74 |
" |
|
75 |
this method is not to be inherited |
|
76 |
(i.e. not ok for subclasses; Symbol, for example) |
|
77 |
" |
|
78 |
self ~~ Unicode16String ifTrue:[ |
|
79 |
^ super readFrom:aStreamOrString onError:exceptionBlock |
|
80 |
]. |
|
81 |
^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
|
82 |
||
83 |
" |
|
25203 | 84 |
self readFrom:'abcäöü' storeString |
11323 | 85 |
" |
86 |
! ! |
|
87 |
||
88 |
||
7946 | 89 |
!Unicode16String methodsFor:'conversion'! |
90 |
||
8294
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
91 |
asUnicode16String |
8942 | 92 |
"as the receiver already is a unicode-16 string, return it" |
93 |
||
8294
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
94 |
^ self |
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
95 |
! |
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
96 |
|
7946 | 97 |
asUnicodeString |
8942 | 98 |
"as the receiver already is a unicode string, return it" |
99 |
||
7946 | 100 |
^ self |
24213 | 101 |
! |
102 |
||
103 |
utf16Encoded |
|
104 |
"have to encode only if there are characters that are outside the UTF-16 range" |
|
105 |
||
106 |
|sz "{Class:SmallInteger}" codePoint "{Class:SmallInteger}"| |
|
107 |
||
108 |
sz := self size. |
|
109 |
1 to:sz do:[:eachIdx| |
|
110 |
codePoint := self basicAt:eachIdx. |
|
111 |
||
112 |
(codePoint >= 16rD800 and:[codePoint <= 16rDFFF]) ifTrue:[ |
|
113 |
^ super utf16Encoded. |
|
114 |
]. |
|
115 |
]. |
|
116 |
||
117 |
"all my characters are in the UTF-16 range" |
|
118 |
^ self |
|
119 |
||
120 |
" |
|
121 |
((Unicode16String new:1) at:1 put:16rD800; yourself) utf16Encoded |
|
122 |
((Unicode16String new:1) at:1 put:16r2A00; yourself) utf16Encoded |
|
123 |
" |
|
124 |
||
125 |
"Created: / 28-05-2019 / 13:14:32 / Stefan Vogel" |
|
126 |
"Modified (comment): / 28-05-2019 / 14:45:01 / Stefan Vogel" |
|
7946 | 127 |
! ! |
128 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
129 |
!Unicode16String methodsFor:'printing & storing'! |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
130 |
|
14121
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
131 |
displayOn:aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
132 |
"display myself as on aStream. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
133 |
You must use an ISO10646 unicode font to display this string" |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
134 |
|
17537 | 135 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
21544 | 136 |
"/ old ST80 means: draw-yourself on a GC. |
137 |
aGCOrStream isStream ifFalse:[ |
|
138 |
^ super displayOn:aGCOrStream |
|
14121
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
139 |
]. |
21544 | 140 |
|
141 |
aGCOrStream |
|
142 |
nextPut:$'; |
|
143 |
nextPutAllUnicode:self; |
|
144 |
nextPut:$'. |
|
145 |
||
146 |
"Modified: / 22-02-2017 / 16:56:32 / cg" |
|
14121
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
147 |
! |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
148 |
|
11323 | 149 |
printOn:aStream |
150 |
"print the receiver on aStream. |
|
13986
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
151 |
Let aStream decide how to represent this, whether utf8, ucs16, ..." |
11323 | 152 |
|
153 |
aStream nextPutAllUnicode:self |
|
13986
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
154 |
|
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
155 |
"Modified (comment): / 25-01-2012 / 10:28:34 / cg" |
11323 | 156 |
! |
157 |
||
158 |
storeOn:aStream |
|
159 |
"put the storeString of myself on aStream" |
|
160 |
||
18970 | 161 |
self containsNon7BitAscii ifTrue:[ |
162 |
"non-7bit string has been utf8Encoded" |
|
163 |
self utf8Encoded storeOn:aStream. |
|
164 |
aStream nextPutAll:' utf8Decoded'. |
|
165 |
] ifFalse:[ |
|
166 |
self asSingleByteString storeOn:aStream. |
|
167 |
]. |
|
168 |
||
169 |
" |
|
170 |
String streamContents:[:s| |
|
171 |
'hello' asUnicodeString storeOn:s |
|
172 |
]. |
|
173 |
||
174 |
String streamContents:[:s| |
|
25203 | 175 |
'hello -öäüß' asUnicodeString storeOn:s |
18970 | 176 |
]. |
177 |
" |
|
13737 | 178 |
|
179 |
"/ aStream nextPut:$'. |
|
180 |
"/ (self includes:$') ifTrue:[ |
|
181 |
"/ self do:[:thisChar | |
|
182 |
"/ (thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
183 |
"/ aStream nextPutUnicode:thisChar |
|
184 |
"/ ] |
|
185 |
"/ ] ifFalse:[ |
|
186 |
"/ aStream nextPutAllUnicode:self |
|
187 |
"/ ]. |
|
188 |
"/ aStream nextPut:$' |
|
189 |
||
190 |
"Modified: / 28-09-2011 / 16:17:38 / cg" |
|
11323 | 191 |
! |
192 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
193 |
storeString |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
194 |
"return a String for storing myself" |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
195 |
|
18970 | 196 |
self containsNon7BitAscii ifTrue:[ |
197 |
"non-7bit string has been utf8Encoded" |
|
198 |
^ (self utf8Encoded storeString),' utf8Decoded'. |
|
199 |
] ifFalse:[ |
|
200 |
^ self asSingleByteString storeString. |
|
201 |
]. |
|
202 |
||
203 |
" |
|
204 |
'hello' asUnicodeString storeString |
|
25203 | 205 |
'hello -öäüß' storeString |
206 |
'hello -öäüß' asUnicodeString storeString |
|
18970 | 207 |
" |
13737 | 208 |
|
13989
cd15b3b6154a
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
13988
diff
changeset
|
209 |
"Modified: / 25-01-2012 / 11:59:34 / cg" |
14124 | 210 |
! |
211 |
||
212 |
unicodeStoreOn:aStream |
|
213 |
"put the storeString of myself on aStream" |
|
214 |
||
215 |
aStream nextPut:$'. |
|
216 |
(self includes:$') ifTrue:[ |
|
217 |
self do:[:thisChar | |
|
218 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
219 |
aStream nextPutUnicode:thisChar |
|
220 |
] |
|
221 |
] ifFalse:[ |
|
222 |
aStream nextPutAllUnicode:self |
|
223 |
]. |
|
224 |
aStream nextPut:$' |
|
225 |
! |
|
226 |
||
227 |
unicodeStoreString |
|
228 |
"return a UnicodeString for storing myself. |
|
229 |
This method is a kind of kludge. |
|
230 |
Use it when you want to write a storeString to an encoded Stream" |
|
231 |
||
232 |
^ self basicStoreString. |
|
233 |
! ! |
|
234 |
||
235 |
!Unicode16String methodsFor:'testing'! |
|
236 |
||
25203 | 237 |
isLiteral |
238 |
"return true, if the receiver can be used as a literal constant in ST syntax |
|
239 |
(i.e. can be used in constant arrays)" |
|
240 |
||
241 |
^ true |
|
242 |
! |
|
243 |
||
14124 | 244 |
isUnicode16String |
245 |
^ true |
|
246 |
! |
|
247 |
||
248 |
isUnicodeString |
|
19937 | 249 |
"true if this is a 2- or 4-byte unicode string |
250 |
(i.e. not a single byte string). |
|
251 |
Notice, that the name is misleading: |
|
24940 | 252 |
all strings use unicode encoding" |
19937 | 253 |
|
14124 | 254 |
^ true |
24940 | 255 |
|
256 |
"Modified (comment): / 21-11-2019 / 18:25:59 / Stefan Vogel" |
|
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
257 |
! ! |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
258 |
|
21544 | 259 |
|
7946 | 260 |
!Unicode16String class methodsFor:'documentation'! |
261 |
||
262 |
version |
|
18970 | 263 |
^ '$Header$' |
13988
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
264 |
! |
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
265 |
|
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
266 |
version_CVS |
18970 | 267 |
^ '$Header$' |
7946 | 268 |
! ! |
269 |
||
14605 | 270 |
|
7946 | 271 |
Unicode16String initialize! |