author | Stefan Vogel <sv@exept.de> |
Wed, 12 Dec 2012 23:56:32 +0100 | |
changeset 14558 | b168e9f03911 |
parent 14124 | 27e2ee113f53 |
child 14605 | 90d502689de9 |
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 |
|
14 |
TwoByteString variableWordSubclass:#Unicode16String |
|
15 |
instanceVariableNames:'' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Collections-Text' |
|
19 |
! |
|
20 |
||
21 |
!Unicode16String class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
||
35 |
||
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
10223
761e2a050b69
twoByteString moved (req'd in VM)
Claus Gittinger <cg@exept.de>
parents:
9648
diff
changeset
|
41 |
Represents 16-bit (2-byte) Unicode strings. |
7946 | 42 |
" |
43 |
! ! |
|
44 |
||
45 |
!Unicode16String class methodsFor:'initialization'! |
|
46 |
||
47 |
initialize |
|
48 |
"initialize the class - private" |
|
49 |
||
7949 | 50 |
self flags:(Behavior flagWords). |
51 |
||
52 |
Smalltalk at:#UnicodeString put:Unicode16String. |
|
7946 | 53 |
|
54 |
" |
|
55 |
Unicode16String initialize |
|
56 |
" |
|
57 |
||
58 |
"Created: 30.6.1997 / 15:35:52 / cg" |
|
59 |
"Modified: 30.6.1997 / 15:39:21 / cg" |
|
60 |
! ! |
|
61 |
||
14558 | 62 |
|
11323 | 63 |
!Unicode16String class methodsFor:'reading'! |
64 |
||
65 |
readFrom:aStreamOrString onError:exceptionBlock |
|
66 |
"read & return the next String from the (character-)stream aStream; |
|
67 |
skipping all whitespace first; return the value of exceptionBlock, |
|
68 |
if no string can be read. The sequence of characters as read from the |
|
69 |
stream must be one as stored via storeOn: or storeString." |
|
70 |
||
71 |
" |
|
72 |
this method is not to be inherited |
|
73 |
(i.e. not ok for subclasses; Symbol, for example) |
|
74 |
" |
|
75 |
self ~~ Unicode16String ifTrue:[ |
|
76 |
^ super readFrom:aStreamOrString onError:exceptionBlock |
|
77 |
]. |
|
78 |
^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
|
79 |
||
80 |
" |
|
81 |
self readFrom:'abcäöü' storeString |
|
82 |
" |
|
83 |
! ! |
|
84 |
||
85 |
||
7946 | 86 |
!Unicode16String methodsFor:'conversion'! |
87 |
||
88 |
asSymbolIfInterned |
|
9232 | 89 |
"If a symbol with the receivers characters is already known, return it. Otherwise, return nil. |
90 |
Because ST/X does not support non-8-bit symbols, this method |
|
8942 | 91 |
has been redefined to only return a symbol, if the receiver does NOT contain |
92 |
any non-8 bit characters." |
|
93 |
||
7946 | 94 |
|s| |
95 |
||
14075 | 96 |
[ |
7946 | 97 |
s := self asSingleByteString. |
14075 | 98 |
] on:Error do:[:ex| |
99 |
^ nil. |
|
7946 | 100 |
]. |
101 |
^ s asSymbolIfInterned |
|
14075 | 102 |
|
103 |
" |
|
104 |
(Unicode16String with:(Character value:16rFFFF)) asSymbolIfInterned |
|
105 |
'new' asUnicodeString asSymbolIfInterned |
|
106 |
" |
|
7946 | 107 |
! |
108 |
||
8294
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
109 |
asUnicode16String |
8942 | 110 |
"as the receiver already is a unicode-16 string, return it" |
111 |
||
8294
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
112 |
^ self |
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
113 |
! |
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
114 |
|
7946 | 115 |
asUnicodeString |
8942 | 116 |
"as the receiver already is a unicode string, return it" |
117 |
||
7946 | 118 |
^ self |
119 |
! ! |
|
120 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
121 |
!Unicode16String methodsFor:'printing & storing'! |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
122 |
|
14121
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
123 |
displayOn:aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
124 |
"display myself as on aStream. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
125 |
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
|
126 |
|
14558 | 127 |
aGCOrStream isStream ifTrue:[ |
14121
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
128 |
aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
129 |
nextPut:$'; |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
130 |
nextPutAllUnicode:self; |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
131 |
nextPut:$'. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
132 |
^ self |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
133 |
]. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
134 |
^ super displayOn:aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
135 |
! |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
136 |
|
11323 | 137 |
printOn:aStream |
138 |
"print the receiver on aStream. |
|
13986
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
139 |
Let aStream decide how to represent this, whether utf8, ucs16, ..." |
11323 | 140 |
|
141 |
aStream nextPutAllUnicode:self |
|
13986
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
142 |
|
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
143 |
"Modified (comment): / 25-01-2012 / 10:28:34 / cg" |
11323 | 144 |
! |
145 |
||
146 |
storeOn:aStream |
|
147 |
"put the storeString of myself on aStream" |
|
148 |
||
13737 | 149 |
(self utf8Encoded storeOn:aStream). |
150 |
aStream nextPutAll:' utf8Decoded'. |
|
151 |
||
152 |
"/ aStream nextPut:$'. |
|
153 |
"/ (self includes:$') ifTrue:[ |
|
154 |
"/ self do:[:thisChar | |
|
155 |
"/ (thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
156 |
"/ aStream nextPutUnicode:thisChar |
|
157 |
"/ ] |
|
158 |
"/ ] ifFalse:[ |
|
159 |
"/ aStream nextPutAllUnicode:self |
|
160 |
"/ ]. |
|
161 |
"/ aStream nextPut:$' |
|
162 |
||
163 |
"Modified: / 28-09-2011 / 16:17:38 / cg" |
|
11323 | 164 |
! |
165 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
166 |
storeString |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
167 |
"return a String for storing myself" |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
168 |
|
13737 | 169 |
"/ ^ self basicStoreString. |
13989
cd15b3b6154a
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
13988
diff
changeset
|
170 |
"/ ^ (self withCEscapes storeString),' withoutCEscapes'. |
cd15b3b6154a
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
13988
diff
changeset
|
171 |
^ (self utf8Encoded storeString),' utf8Decoded'. |
13737 | 172 |
|
13989
cd15b3b6154a
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
13988
diff
changeset
|
173 |
"Modified: / 25-01-2012 / 11:59:34 / cg" |
14124 | 174 |
! |
175 |
||
176 |
unicodeStoreOn:aStream |
|
177 |
"put the storeString of myself on aStream" |
|
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 |
||
191 |
unicodeStoreString |
|
192 |
"return a UnicodeString for storing myself. |
|
193 |
This method is a kind of kludge. |
|
194 |
Use it when you want to write a storeString to an encoded Stream" |
|
195 |
||
196 |
^ self basicStoreString. |
|
197 |
! ! |
|
198 |
||
199 |
!Unicode16String methodsFor:'testing'! |
|
200 |
||
201 |
isUnicode16String |
|
202 |
^ true |
|
203 |
! |
|
204 |
||
205 |
isUnicodeString |
|
206 |
^ true |
|
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
207 |
! ! |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
208 |
|
14121
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
209 |
|
7946 | 210 |
!Unicode16String class methodsFor:'documentation'! |
211 |
||
212 |
version |
|
14558 | 213 |
^ '$Header: /cvs/stx/stx/libbasic/Unicode16String.st,v 1.20 2012-12-12 22:56:32 stefan Exp $' |
13988
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
214 |
! |
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
215 |
|
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
216 |
version_CVS |
14558 | 217 |
^ '$Header: /cvs/stx/stx/libbasic/Unicode16String.st,v 1.20 2012-12-12 22:56:32 stefan Exp $' |
7946 | 218 |
! ! |
219 |
||
220 |
Unicode16String initialize! |