author | Claus Gittinger <cg@exept.de> |
Fri, 17 May 2019 13:10:48 +0200 | |
changeset 4944 | f4f8254bfb3b |
parent 3872 | af31f9e3a160 |
child 4769 | 89914ccfcf7d |
child 4965 | cb05c61f9204 |
permissions | -rw-r--r-- |
1404 | 1 |
" |
2 |
COPYRIGHT (c) 2004 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 |
" |
|
1411 | 12 |
"{ Package: 'stx:libbasic2' }" |
1404 | 13 |
|
3663 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1404 | 16 |
FourByteString variableLongSubclass:#Unicode32String |
17 |
instanceVariableNames:'' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Collections-Text' |
|
21 |
! |
|
22 |
||
23 |
!Unicode32String class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 2004 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 |
" |
|
1573 | 43 |
Not yet fully finished - unicode support is still being implemented. |
1404 | 44 |
" |
45 |
! ! |
|
46 |
||
47 |
!Unicode32String class methodsFor:'initialization'! |
|
48 |
||
49 |
initialize |
|
50 |
"initialize the class - private" |
|
51 |
||
52 |
self flags:(Behavior flagLongs) |
|
53 |
||
54 |
" |
|
55 |
Unicode32String initialize |
|
56 |
" |
|
57 |
||
58 |
"Created: 30.6.1997 / 15:35:52 / cg" |
|
59 |
"Modified: 30.6.1997 / 15:39:21 / cg" |
|
60 |
! ! |
|
61 |
||
2052 | 62 |
!Unicode32String class methodsFor:'reading'! |
63 |
||
64 |
readFrom:aStreamOrString onError:exceptionBlock |
|
65 |
"read & return the next String from the (character-)stream aStream; |
|
66 |
skipping all whitespace first; return the value of exceptionBlock, |
|
67 |
if no string can be read. The sequence of characters as read from the |
|
68 |
stream must be one as stored via storeOn: or storeString." |
|
69 |
||
70 |
" |
|
71 |
this method is not to be inherited |
|
72 |
(i.e. not ok for subclasses; Symbol, for example) |
|
73 |
" |
|
74 |
self ~~ Unicode32String ifTrue:[ |
|
75 |
^ super readFrom:aStreamOrString onError:exceptionBlock |
|
76 |
]. |
|
77 |
^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
|
78 |
||
79 |
" |
|
80 |
self readFrom:'abcäöü' storeString |
|
81 |
String readFrom:'abcäöü' storeString |
|
82 |
" |
|
83 |
! ! |
|
84 |
||
85 |
||
1404 | 86 |
!Unicode32String methodsFor:'conversion'! |
87 |
||
1443
e971d86d6259
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
1411
diff
changeset
|
88 |
asUnicode32String |
1573 | 89 |
"as the receiver already is a unicode-32 string, return it" |
90 |
||
1443
e971d86d6259
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
1411
diff
changeset
|
91 |
^ self |
e971d86d6259
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
1411
diff
changeset
|
92 |
! |
e971d86d6259
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
1411
diff
changeset
|
93 |
|
1404 | 94 |
asUnicodeString |
1573 | 95 |
"as the receiver already is a unicode string, return it" |
96 |
||
1404 | 97 |
^ self |
98 |
! |
|
99 |
||
100 |
printOn:aStream |
|
2052 | 101 |
"print the receiver on aStream. |
3065 | 102 |
Let aStream decide how to represent this, whether utf8, ucs16, ..." |
2052 | 103 |
|
104 |
aStream nextPutAllUnicode:self |
|
3065 | 105 |
|
106 |
"Modified (comment): / 27-07-2013 / 15:37:03 / cg" |
|
2052 | 107 |
! ! |
108 |
||
109 |
!Unicode32String methodsFor:'printing & storing'! |
|
110 |
||
111 |
storeOn:aStream |
|
112 |
"put the storeString of myself on aStream" |
|
1573 | 113 |
|
3663 | 114 |
self containsNon7BitAscii ifTrue:[ |
115 |
"non-7bit string has been utf8Encoded" |
|
116 |
self utf8Encoded storeOn:aStream. |
|
117 |
aStream nextPutAll:' utf8Decoded'. |
|
118 |
] ifFalse:[ |
|
119 |
self asSingleByteString storeOn:aStream. |
|
120 |
]. |
|
121 |
||
122 |
" |
|
123 |
String streamContents:[:s| |
|
124 |
'hello' asUnicode32String storeOn:s |
|
125 |
]. |
|
126 |
||
127 |
String streamContents:[:s| |
|
128 |
'hello -öäüß' asUnicode32String storeOn:s |
|
129 |
]. |
|
130 |
" |
|
131 |
||
2664 | 132 |
"/ aStream nextPut:$'. |
133 |
"/ (self includes:$') ifTrue:[ |
|
134 |
"/ self do:[:thisChar | |
|
135 |
"/ (thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
136 |
"/ aStream nextPutUnicode:thisChar |
|
137 |
"/ ] |
|
138 |
"/ ] ifFalse:[ |
|
139 |
"/ aStream nextPutAllUnicode:self |
|
140 |
"/ ]. |
|
141 |
"/ aStream nextPut:$' |
|
142 |
||
143 |
"Modified: / 28-09-2011 / 16:18:43 / cg" |
|
2052 | 144 |
! |
145 |
||
146 |
storeString |
|
147 |
"return a String for storing myself" |
|
148 |
||
3663 | 149 |
self containsNon7BitAscii ifTrue:[ |
150 |
"non-7bit string has been utf8Encoded" |
|
151 |
^ (self utf8Encoded storeString),' utf8Decoded'. |
|
152 |
] ifFalse:[ |
|
153 |
^ self asSingleByteString storeString. |
|
154 |
]. |
|
2664 | 155 |
|
3663 | 156 |
" |
157 |
'hello' asUnicode32String storeString |
|
158 |
'hello -öäüß' storeString |
|
159 |
'hello -öäüß' asUnicode32String storeString |
|
160 |
" |
|
2740 | 161 |
! |
162 |
||
163 |
unicodeStoreOn:aStream |
|
164 |
"put the storeString of myself on aStream" |
|
165 |
||
166 |
aStream nextPut:$'. |
|
167 |
(self includes:$') ifTrue:[ |
|
168 |
self do:[:thisChar | |
|
169 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
170 |
aStream nextPutUnicode:thisChar |
|
171 |
] |
|
172 |
] ifFalse:[ |
|
173 |
aStream nextPutAllUnicode:self |
|
174 |
]. |
|
175 |
aStream nextPut:$' |
|
176 |
! |
|
177 |
||
178 |
unicodeStoreString |
|
179 |
"return a UnicodeString for storing myself. |
|
180 |
This method is a kind of kludge. |
|
181 |
Use it when you want to write a storeString to an encoded Stream" |
|
182 |
||
183 |
^ self basicStoreString. |
|
184 |
! ! |
|
185 |
||
186 |
!Unicode32String methodsFor:'testing'! |
|
187 |
||
188 |
isUnicode32String |
|
3872 | 189 |
"true if this is a 4-byte unicode string" |
190 |
||
2740 | 191 |
^ true |
192 |
! |
|
193 |
||
194 |
isUnicodeString |
|
3871 | 195 |
"true if this is a 2- or 4-byte unicode string |
196 |
(i.e. not a single byte string). |
|
197 |
Notice, that the name is misleading: |
|
198 |
all strings are use unicode encoding" |
|
199 |
||
2740 | 200 |
^ true |
1404 | 201 |
! ! |
202 |
||
203 |
!Unicode32String class methodsFor:'documentation'! |
|
204 |
||
205 |
version |
|
3663 | 206 |
^ '$Header$' |
2709
0d45ae840f12
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
2708
diff
changeset
|
207 |
! |
0d45ae840f12
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
2708
diff
changeset
|
208 |
|
0d45ae840f12
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
2708
diff
changeset
|
209 |
version_CVS |
3663 | 210 |
^ '$Header$' |
1404 | 211 |
! ! |
212 |
||
3065 | 213 |
|
1404 | 214 |
Unicode32String initialize! |