author | Claus Gittinger <cg@exept.de> |
Sat, 06 Jun 2015 13:42:28 +0200 | |
changeset 18449 | 48c31fe80359 |
parent 17537 | 6ed63b021903 |
child 18120 | e3a375d5f6a8 |
child 18970 | f4c3afd137e3 |
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 |
||
89 |
asSymbolIfInterned |
|
17182 | 90 |
"If a symbol with the receiver's characters is already known, return it. Otherwise, return nil. |
9232 | 91 |
Because ST/X does not support non-8-bit symbols, this method |
8942 | 92 |
has been redefined to only return a symbol, if the receiver does NOT contain |
93 |
any non-8 bit characters." |
|
94 |
||
7946 | 95 |
|s| |
96 |
||
14075 | 97 |
[ |
7946 | 98 |
s := self asSingleByteString. |
14075 | 99 |
] on:Error do:[:ex| |
100 |
^ nil. |
|
7946 | 101 |
]. |
102 |
^ s asSymbolIfInterned |
|
14075 | 103 |
|
104 |
" |
|
105 |
(Unicode16String with:(Character value:16rFFFF)) asSymbolIfInterned |
|
106 |
'new' asUnicodeString asSymbolIfInterned |
|
107 |
" |
|
7946 | 108 |
! |
109 |
||
8294
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
110 |
asUnicode16String |
8942 | 111 |
"as the receiver already is a unicode-16 string, return it" |
112 |
||
8294
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
113 |
^ self |
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
114 |
! |
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
115 |
|
7946 | 116 |
asUnicodeString |
8942 | 117 |
"as the receiver already is a unicode string, return it" |
118 |
||
7946 | 119 |
^ self |
120 |
! ! |
|
121 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
122 |
!Unicode16String methodsFor:'printing & storing'! |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
123 |
|
14121
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
124 |
displayOn:aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
125 |
"display myself as on aStream. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
126 |
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
|
127 |
|
17537 | 128 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
129 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
|
14558 | 130 |
aGCOrStream isStream ifTrue:[ |
14121
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
131 |
aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
132 |
nextPut:$'; |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
133 |
nextPutAllUnicode:self; |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
134 |
nextPut:$'. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
135 |
^ self |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
136 |
]. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
137 |
^ super displayOn:aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
138 |
! |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
139 |
|
11323 | 140 |
printOn:aStream |
141 |
"print the receiver on aStream. |
|
13986
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
142 |
Let aStream decide how to represent this, whether utf8, ucs16, ..." |
11323 | 143 |
|
144 |
aStream nextPutAllUnicode:self |
|
13986
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
145 |
|
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
146 |
"Modified (comment): / 25-01-2012 / 10:28:34 / cg" |
11323 | 147 |
! |
148 |
||
149 |
storeOn:aStream |
|
150 |
"put the storeString of myself on aStream" |
|
151 |
||
14605 | 152 |
self utf8Encoded storeOn:aStream. |
13737 | 153 |
aStream nextPutAll:' utf8Decoded'. |
154 |
||
155 |
"/ aStream nextPut:$'. |
|
156 |
"/ (self includes:$') ifTrue:[ |
|
157 |
"/ self do:[:thisChar | |
|
158 |
"/ (thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
159 |
"/ aStream nextPutUnicode:thisChar |
|
160 |
"/ ] |
|
161 |
"/ ] ifFalse:[ |
|
162 |
"/ aStream nextPutAllUnicode:self |
|
163 |
"/ ]. |
|
164 |
"/ aStream nextPut:$' |
|
165 |
||
166 |
"Modified: / 28-09-2011 / 16:17:38 / cg" |
|
11323 | 167 |
! |
168 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
169 |
storeString |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
170 |
"return a String for storing myself" |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
171 |
|
13737 | 172 |
"/ ^ self basicStoreString. |
13989
cd15b3b6154a
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
13988
diff
changeset
|
173 |
"/ ^ (self withCEscapes storeString),' withoutCEscapes'. |
cd15b3b6154a
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
13988
diff
changeset
|
174 |
^ (self utf8Encoded storeString),' utf8Decoded'. |
13737 | 175 |
|
13989
cd15b3b6154a
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
13988
diff
changeset
|
176 |
"Modified: / 25-01-2012 / 11:59:34 / cg" |
14124 | 177 |
! |
178 |
||
179 |
unicodeStoreOn:aStream |
|
180 |
"put the storeString of myself on aStream" |
|
181 |
||
182 |
aStream nextPut:$'. |
|
183 |
(self includes:$') ifTrue:[ |
|
184 |
self do:[:thisChar | |
|
185 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
186 |
aStream nextPutUnicode:thisChar |
|
187 |
] |
|
188 |
] ifFalse:[ |
|
189 |
aStream nextPutAllUnicode:self |
|
190 |
]. |
|
191 |
aStream nextPut:$' |
|
192 |
! |
|
193 |
||
194 |
unicodeStoreString |
|
195 |
"return a UnicodeString for storing myself. |
|
196 |
This method is a kind of kludge. |
|
197 |
Use it when you want to write a storeString to an encoded Stream" |
|
198 |
||
199 |
^ self basicStoreString. |
|
200 |
! ! |
|
201 |
||
202 |
!Unicode16String methodsFor:'testing'! |
|
203 |
||
204 |
isUnicode16String |
|
205 |
^ true |
|
206 |
! |
|
207 |
||
208 |
isUnicodeString |
|
209 |
^ true |
|
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
210 |
! ! |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
211 |
|
17537 | 212 |
|
7946 | 213 |
!Unicode16String class methodsFor:'documentation'! |
214 |
||
215 |
version |
|
17537 | 216 |
^ '$Header: /cvs/stx/stx/libbasic/Unicode16String.st,v 1.23 2015-02-20 23:59:30 cg Exp $' |
13988
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
217 |
! |
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
218 |
|
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
219 |
version_CVS |
17537 | 220 |
^ '$Header: /cvs/stx/stx/libbasic/Unicode16String.st,v 1.23 2015-02-20 23:59:30 cg Exp $' |
7946 | 221 |
! ! |
222 |
||
14605 | 223 |
|
7946 | 224 |
Unicode16String initialize! |