author | Stefan Vogel <sv@exept.de> |
Fri, 03 Apr 2020 18:50:48 +0200 | |
changeset 5471 | 0bee7a5e40e8 |
parent 5433 | 45176601c636 |
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 |
" |
|
5433 | 80 |
self readFrom:'abcäöü' storeString |
81 |
String readFrom:'abcäöü' storeString |
|
2052 | 82 |
" |
83 |
! ! |
|
84 |
||
85 |
||
1404 | 86 |
!Unicode32String methodsFor:'conversion'! |
87 |
||
4965 | 88 |
asUnicode16StringReplaceInvalidWith:replacementCharacter |
89 |
"return the receiver converted to a 'normal' string, |
|
90 |
with invalid characters replaced by replacementCharacter. |
|
91 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
92 |
and replace characters above code-255 with some replacement." |
|
93 |
||
94 |
|newString sz "{ Class:SmallInteger }"| |
|
95 |
||
96 |
sz := self size. |
|
97 |
||
98 |
newString := Unicode16String new:sz. |
|
99 |
1 to:sz do:[:idx | |
|
100 |
|char| |
|
101 |
||
102 |
char := self at:idx. |
|
103 |
char codePoint <= 16rFFFF ifTrue:[ |
|
104 |
newString at:idx put:char |
|
105 |
] ifFalse:[ |
|
106 |
newString at:idx put:replacementCharacter |
|
107 |
]. |
|
108 |
]. |
|
109 |
^ newString |
|
110 |
||
111 |
"Created: / 28-05-2019 / 12:13:57 / Stefan Vogel" |
|
112 |
! |
|
113 |
||
1443
e971d86d6259
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
1411
diff
changeset
|
114 |
asUnicode32String |
1573 | 115 |
"as the receiver already is a unicode-32 string, return it" |
116 |
||
1443
e971d86d6259
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
1411
diff
changeset
|
117 |
^ self |
e971d86d6259
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
1411
diff
changeset
|
118 |
! |
e971d86d6259
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
1411
diff
changeset
|
119 |
|
1404 | 120 |
asUnicodeString |
1573 | 121 |
"as the receiver already is a unicode string, return it" |
122 |
||
1404 | 123 |
^ self |
124 |
! |
|
125 |
||
126 |
printOn:aStream |
|
2052 | 127 |
"print the receiver on aStream. |
3065 | 128 |
Let aStream decide how to represent this, whether utf8, ucs16, ..." |
2052 | 129 |
|
130 |
aStream nextPutAllUnicode:self |
|
3065 | 131 |
|
132 |
"Modified (comment): / 27-07-2013 / 15:37:03 / cg" |
|
2052 | 133 |
! ! |
134 |
||
135 |
!Unicode32String methodsFor:'printing & storing'! |
|
136 |
||
137 |
storeOn:aStream |
|
138 |
"put the storeString of myself on aStream" |
|
1573 | 139 |
|
3663 | 140 |
self containsNon7BitAscii ifTrue:[ |
141 |
"non-7bit string has been utf8Encoded" |
|
142 |
self utf8Encoded storeOn:aStream. |
|
143 |
aStream nextPutAll:' utf8Decoded'. |
|
144 |
] ifFalse:[ |
|
145 |
self asSingleByteString storeOn:aStream. |
|
146 |
]. |
|
147 |
||
148 |
" |
|
149 |
String streamContents:[:s| |
|
150 |
'hello' asUnicode32String storeOn:s |
|
151 |
]. |
|
152 |
||
153 |
String streamContents:[:s| |
|
5433 | 154 |
'hello -öäüß' asUnicode32String storeOn:s |
3663 | 155 |
]. |
156 |
" |
|
157 |
||
2664 | 158 |
"/ aStream nextPut:$'. |
159 |
"/ (self includes:$') ifTrue:[ |
|
160 |
"/ self do:[:thisChar | |
|
161 |
"/ (thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
162 |
"/ aStream nextPutUnicode:thisChar |
|
163 |
"/ ] |
|
164 |
"/ ] ifFalse:[ |
|
165 |
"/ aStream nextPutAllUnicode:self |
|
166 |
"/ ]. |
|
167 |
"/ aStream nextPut:$' |
|
168 |
||
169 |
"Modified: / 28-09-2011 / 16:18:43 / cg" |
|
2052 | 170 |
! |
171 |
||
172 |
storeString |
|
173 |
"return a String for storing myself" |
|
174 |
||
3663 | 175 |
self containsNon7BitAscii ifTrue:[ |
176 |
"non-7bit string has been utf8Encoded" |
|
177 |
^ (self utf8Encoded storeString),' utf8Decoded'. |
|
178 |
] ifFalse:[ |
|
179 |
^ self asSingleByteString storeString. |
|
180 |
]. |
|
2664 | 181 |
|
3663 | 182 |
" |
183 |
'hello' asUnicode32String storeString |
|
5433 | 184 |
'hello -öäüß' storeString |
185 |
'hello -öäüß' asUnicode32String storeString |
|
3663 | 186 |
" |
2740 | 187 |
! |
188 |
||
189 |
unicodeStoreOn:aStream |
|
190 |
"put the storeString of myself on aStream" |
|
191 |
||
192 |
aStream nextPut:$'. |
|
193 |
(self includes:$') ifTrue:[ |
|
194 |
self do:[:thisChar | |
|
195 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
196 |
aStream nextPutUnicode:thisChar |
|
197 |
] |
|
198 |
] ifFalse:[ |
|
199 |
aStream nextPutAllUnicode:self |
|
200 |
]. |
|
201 |
aStream nextPut:$' |
|
202 |
! |
|
203 |
||
204 |
unicodeStoreString |
|
205 |
"return a UnicodeString for storing myself. |
|
206 |
This method is a kind of kludge. |
|
207 |
Use it when you want to write a storeString to an encoded Stream" |
|
208 |
||
209 |
^ self basicStoreString. |
|
210 |
! ! |
|
211 |
||
212 |
!Unicode32String methodsFor:'testing'! |
|
213 |
||
5433 | 214 |
isLiteral |
215 |
"return true, if the receiver can be used as a literal constant in ST syntax |
|
216 |
(i.e. can be used in constant arrays)" |
|
217 |
||
218 |
^ true |
|
219 |
! |
|
220 |
||
2740 | 221 |
isUnicode32String |
3872 | 222 |
"true if this is a 4-byte unicode string" |
223 |
||
2740 | 224 |
^ true |
225 |
! |
|
226 |
||
227 |
isUnicodeString |
|
3871 | 228 |
"true if this is a 2- or 4-byte unicode string |
229 |
(i.e. not a single byte string). |
|
230 |
Notice, that the name is misleading: |
|
5265 | 231 |
all strings use unicode encoding" |
3871 | 232 |
|
2740 | 233 |
^ true |
5265 | 234 |
|
235 |
"Modified (comment): / 21-11-2019 / 18:26:05 / Stefan Vogel" |
|
1404 | 236 |
! ! |
237 |
||
238 |
!Unicode32String class methodsFor:'documentation'! |
|
239 |
||
240 |
version |
|
3663 | 241 |
^ '$Header$' |
2709
0d45ae840f12
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
2708
diff
changeset
|
242 |
! |
0d45ae840f12
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
2708
diff
changeset
|
243 |
|
0d45ae840f12
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
2708
diff
changeset
|
244 |
version_CVS |
3663 | 245 |
^ '$Header$' |
1404 | 246 |
! ! |
247 |
||
3065 | 248 |
|
1404 | 249 |
Unicode32String initialize! |