author | Stefan Vogel <sv@exept.de> |
Fri, 20 Jan 2017 19:59:28 +0100 | |
changeset 21267 | 4c1185a27941 |
parent 19937 | 48031fe6896b |
child 19948 | be658f466bca |
child 21544 | d16e66fc4339 |
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 |
||
11323 | 64 |
!Unicode16String class methodsFor:'reading'! |
65 |
||
66 |
readFrom:aStreamOrString onError:exceptionBlock |
|
67 |
"read & return the next String from the (character-)stream aStream; |
|
68 |
skipping all whitespace first; return the value of exceptionBlock, |
|
69 |
if no string can be read. The sequence of characters as read from the |
|
70 |
stream must be one as stored via storeOn: or storeString." |
|
71 |
||
72 |
" |
|
73 |
this method is not to be inherited |
|
74 |
(i.e. not ok for subclasses; Symbol, for example) |
|
75 |
" |
|
76 |
self ~~ Unicode16String ifTrue:[ |
|
77 |
^ super readFrom:aStreamOrString onError:exceptionBlock |
|
78 |
]. |
|
79 |
^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
|
80 |
||
81 |
" |
|
82 |
self readFrom:'abcäöü' storeString |
|
83 |
" |
|
84 |
! ! |
|
85 |
||
86 |
||
7946 | 87 |
!Unicode16String methodsFor:'conversion'! |
88 |
||
8294
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
89 |
asUnicode16String |
8942 | 90 |
"as the receiver already is a unicode-16 string, return it" |
91 |
||
8294
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
92 |
^ self |
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
93 |
! |
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
94 |
|
7946 | 95 |
asUnicodeString |
8942 | 96 |
"as the receiver already is a unicode string, return it" |
97 |
||
7946 | 98 |
^ self |
99 |
! ! |
|
100 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
101 |
!Unicode16String methodsFor:'printing & storing'! |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
102 |
|
14121
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
103 |
displayOn:aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
104 |
"display myself as on aStream. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
105 |
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
|
106 |
|
17537 | 107 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
108 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
|
14558 | 109 |
aGCOrStream isStream ifTrue:[ |
14121
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
110 |
aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
111 |
nextPut:$'; |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
112 |
nextPutAllUnicode:self; |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
113 |
nextPut:$'. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
114 |
^ self |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
115 |
]. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
116 |
^ super displayOn:aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
117 |
! |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
118 |
|
11323 | 119 |
printOn:aStream |
120 |
"print the receiver on aStream. |
|
13986
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
121 |
Let aStream decide how to represent this, whether utf8, ucs16, ..." |
11323 | 122 |
|
123 |
aStream nextPutAllUnicode:self |
|
13986
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
124 |
|
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
125 |
"Modified (comment): / 25-01-2012 / 10:28:34 / cg" |
11323 | 126 |
! |
127 |
||
128 |
storeOn:aStream |
|
129 |
"put the storeString of myself on aStream" |
|
130 |
||
18970 | 131 |
self containsNon7BitAscii ifTrue:[ |
132 |
"non-7bit string has been utf8Encoded" |
|
133 |
self utf8Encoded storeOn:aStream. |
|
134 |
aStream nextPutAll:' utf8Decoded'. |
|
135 |
] ifFalse:[ |
|
136 |
self asSingleByteString storeOn:aStream. |
|
137 |
]. |
|
138 |
||
139 |
" |
|
140 |
String streamContents:[:s| |
|
141 |
'hello' asUnicodeString storeOn:s |
|
142 |
]. |
|
143 |
||
144 |
String streamContents:[:s| |
|
145 |
'hello -öäüß' asUnicodeString storeOn:s |
|
146 |
]. |
|
147 |
" |
|
13737 | 148 |
|
149 |
"/ aStream nextPut:$'. |
|
150 |
"/ (self includes:$') ifTrue:[ |
|
151 |
"/ self do:[:thisChar | |
|
152 |
"/ (thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
153 |
"/ aStream nextPutUnicode:thisChar |
|
154 |
"/ ] |
|
155 |
"/ ] ifFalse:[ |
|
156 |
"/ aStream nextPutAllUnicode:self |
|
157 |
"/ ]. |
|
158 |
"/ aStream nextPut:$' |
|
159 |
||
160 |
"Modified: / 28-09-2011 / 16:17:38 / cg" |
|
11323 | 161 |
! |
162 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
163 |
storeString |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
164 |
"return a String for storing myself" |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
165 |
|
18970 | 166 |
self containsNon7BitAscii ifTrue:[ |
167 |
"non-7bit string has been utf8Encoded" |
|
168 |
^ (self utf8Encoded storeString),' utf8Decoded'. |
|
169 |
] ifFalse:[ |
|
170 |
^ self asSingleByteString storeString. |
|
171 |
]. |
|
172 |
||
173 |
" |
|
174 |
'hello' asUnicodeString storeString |
|
175 |
'hello -öäüß' storeString |
|
176 |
'hello -öäüß' asUnicodeString storeString |
|
177 |
" |
|
13737 | 178 |
|
13989
cd15b3b6154a
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
13988
diff
changeset
|
179 |
"Modified: / 25-01-2012 / 11:59:34 / cg" |
14124 | 180 |
! |
181 |
||
182 |
unicodeStoreOn:aStream |
|
183 |
"put the storeString of myself on aStream" |
|
184 |
||
185 |
aStream nextPut:$'. |
|
186 |
(self includes:$') ifTrue:[ |
|
187 |
self do:[:thisChar | |
|
188 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
189 |
aStream nextPutUnicode:thisChar |
|
190 |
] |
|
191 |
] ifFalse:[ |
|
192 |
aStream nextPutAllUnicode:self |
|
193 |
]. |
|
194 |
aStream nextPut:$' |
|
195 |
! |
|
196 |
||
197 |
unicodeStoreString |
|
198 |
"return a UnicodeString for storing myself. |
|
199 |
This method is a kind of kludge. |
|
200 |
Use it when you want to write a storeString to an encoded Stream" |
|
201 |
||
202 |
^ self basicStoreString. |
|
203 |
! ! |
|
204 |
||
205 |
!Unicode16String methodsFor:'testing'! |
|
206 |
||
207 |
isUnicode16String |
|
208 |
^ true |
|
209 |
! |
|
210 |
||
211 |
isUnicodeString |
|
19937 | 212 |
"true if this is a 2- or 4-byte unicode string |
213 |
(i.e. not a single byte string). |
|
214 |
Notice, that the name is misleading: |
|
215 |
all strings are use unicode encoding" |
|
216 |
||
14124 | 217 |
^ true |
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
218 |
! ! |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
219 |
|
7946 | 220 |
!Unicode16String class methodsFor:'documentation'! |
221 |
||
222 |
version |
|
18970 | 223 |
^ '$Header$' |
13988
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
224 |
! |
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
225 |
|
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
226 |
version_CVS |
18970 | 227 |
^ '$Header$' |
7946 | 228 |
! ! |
229 |
||
14605 | 230 |
|
7946 | 231 |
Unicode16String initialize! |