author | convert-repo |
Wed, 29 May 2019 03:27:48 +0000 | |
changeset 4967 | 9ed9d3c91339 |
parent 4965 | cb05c61f9204 |
child 5265 | 5f6a992925c2 |
permissions | -rw-r--r-- |
4965 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1404 | 3 |
" |
4 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1411 | 14 |
"{ Package: 'stx:libbasic2' }" |
1404 | 15 |
|
3663 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1404 | 18 |
FourByteString variableLongSubclass:#Unicode32String |
19 |
instanceVariableNames:'' |
|
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Collections-Text' |
|
23 |
! |
|
24 |
||
25 |
!Unicode32String class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
||
39 |
||
40 |
" |
|
41 |
! |
|
42 |
||
43 |
documentation |
|
44 |
" |
|
1573 | 45 |
Not yet fully finished - unicode support is still being implemented. |
1404 | 46 |
" |
47 |
! ! |
|
48 |
||
49 |
!Unicode32String class methodsFor:'initialization'! |
|
50 |
||
51 |
initialize |
|
52 |
"initialize the class - private" |
|
53 |
||
54 |
self flags:(Behavior flagLongs) |
|
55 |
||
56 |
" |
|
57 |
Unicode32String initialize |
|
58 |
" |
|
59 |
||
60 |
"Created: 30.6.1997 / 15:35:52 / cg" |
|
61 |
"Modified: 30.6.1997 / 15:39:21 / cg" |
|
62 |
! ! |
|
63 |
||
2052 | 64 |
!Unicode32String 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 ~~ Unicode32String ifTrue:[ |
|
77 |
^ super readFrom:aStreamOrString onError:exceptionBlock |
|
78 |
]. |
|
79 |
^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
|
80 |
||
81 |
" |
|
4965 | 82 |
self readFrom:'abcäöü' storeString |
83 |
String readFrom:'abcäöü' storeString |
|
2052 | 84 |
" |
85 |
! ! |
|
86 |
||
87 |
||
1404 | 88 |
!Unicode32String methodsFor:'conversion'! |
89 |
||
4965 | 90 |
asUnicode16StringReplaceInvalidWith:replacementCharacter |
91 |
"return the receiver converted to a 'normal' string, |
|
92 |
with invalid characters replaced by replacementCharacter. |
|
93 |
Can be used to convert from 16-bit strings to 8-bit strings |
|
94 |
and replace characters above code-255 with some replacement." |
|
95 |
||
96 |
|newString sz "{ Class:SmallInteger }"| |
|
97 |
||
98 |
sz := self size. |
|
99 |
||
100 |
newString := Unicode16String new:sz. |
|
101 |
1 to:sz do:[:idx | |
|
102 |
|char| |
|
103 |
||
104 |
char := self at:idx. |
|
105 |
char codePoint <= 16rFFFF ifTrue:[ |
|
106 |
newString at:idx put:char |
|
107 |
] ifFalse:[ |
|
108 |
newString at:idx put:replacementCharacter |
|
109 |
]. |
|
110 |
]. |
|
111 |
^ newString |
|
112 |
||
113 |
"Created: / 28-05-2019 / 12:13:57 / Stefan Vogel" |
|
114 |
! |
|
115 |
||
1443
e971d86d6259
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
1411
diff
changeset
|
116 |
asUnicode32String |
1573 | 117 |
"as the receiver already is a unicode-32 string, return it" |
118 |
||
1443
e971d86d6259
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
1411
diff
changeset
|
119 |
^ self |
e971d86d6259
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
1411
diff
changeset
|
120 |
! |
e971d86d6259
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
1411
diff
changeset
|
121 |
|
1404 | 122 |
asUnicodeString |
1573 | 123 |
"as the receiver already is a unicode string, return it" |
124 |
||
1404 | 125 |
^ self |
126 |
! |
|
127 |
||
128 |
printOn:aStream |
|
2052 | 129 |
"print the receiver on aStream. |
3065 | 130 |
Let aStream decide how to represent this, whether utf8, ucs16, ..." |
2052 | 131 |
|
132 |
aStream nextPutAllUnicode:self |
|
3065 | 133 |
|
134 |
"Modified (comment): / 27-07-2013 / 15:37:03 / cg" |
|
2052 | 135 |
! ! |
136 |
||
137 |
!Unicode32String methodsFor:'printing & storing'! |
|
138 |
||
139 |
storeOn:aStream |
|
140 |
"put the storeString of myself on aStream" |
|
1573 | 141 |
|
3663 | 142 |
self containsNon7BitAscii ifTrue:[ |
143 |
"non-7bit string has been utf8Encoded" |
|
144 |
self utf8Encoded storeOn:aStream. |
|
145 |
aStream nextPutAll:' utf8Decoded'. |
|
146 |
] ifFalse:[ |
|
147 |
self asSingleByteString storeOn:aStream. |
|
148 |
]. |
|
149 |
||
150 |
" |
|
151 |
String streamContents:[:s| |
|
152 |
'hello' asUnicode32String storeOn:s |
|
153 |
]. |
|
154 |
||
155 |
String streamContents:[:s| |
|
4965 | 156 |
'hello -öäüß' asUnicode32String storeOn:s |
3663 | 157 |
]. |
158 |
" |
|
159 |
||
2664 | 160 |
"/ aStream nextPut:$'. |
161 |
"/ (self includes:$') ifTrue:[ |
|
162 |
"/ self do:[:thisChar | |
|
163 |
"/ (thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
164 |
"/ aStream nextPutUnicode:thisChar |
|
165 |
"/ ] |
|
166 |
"/ ] ifFalse:[ |
|
167 |
"/ aStream nextPutAllUnicode:self |
|
168 |
"/ ]. |
|
169 |
"/ aStream nextPut:$' |
|
170 |
||
171 |
"Modified: / 28-09-2011 / 16:18:43 / cg" |
|
2052 | 172 |
! |
173 |
||
174 |
storeString |
|
175 |
"return a String for storing myself" |
|
176 |
||
3663 | 177 |
self containsNon7BitAscii ifTrue:[ |
178 |
"non-7bit string has been utf8Encoded" |
|
179 |
^ (self utf8Encoded storeString),' utf8Decoded'. |
|
180 |
] ifFalse:[ |
|
181 |
^ self asSingleByteString storeString. |
|
182 |
]. |
|
2664 | 183 |
|
3663 | 184 |
" |
185 |
'hello' asUnicode32String storeString |
|
4965 | 186 |
'hello -öäüß' storeString |
187 |
'hello -öäüß' asUnicode32String storeString |
|
3663 | 188 |
" |
2740 | 189 |
! |
190 |
||
191 |
unicodeStoreOn:aStream |
|
192 |
"put the storeString of myself on aStream" |
|
193 |
||
194 |
aStream nextPut:$'. |
|
195 |
(self includes:$') ifTrue:[ |
|
196 |
self do:[:thisChar | |
|
197 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
198 |
aStream nextPutUnicode:thisChar |
|
199 |
] |
|
200 |
] ifFalse:[ |
|
201 |
aStream nextPutAllUnicode:self |
|
202 |
]. |
|
203 |
aStream nextPut:$' |
|
204 |
! |
|
205 |
||
206 |
unicodeStoreString |
|
207 |
"return a UnicodeString for storing myself. |
|
208 |
This method is a kind of kludge. |
|
209 |
Use it when you want to write a storeString to an encoded Stream" |
|
210 |
||
211 |
^ self basicStoreString. |
|
212 |
! ! |
|
213 |
||
214 |
!Unicode32String methodsFor:'testing'! |
|
215 |
||
216 |
isUnicode32String |
|
3872 | 217 |
"true if this is a 4-byte unicode string" |
218 |
||
2740 | 219 |
^ true |
220 |
! |
|
221 |
||
222 |
isUnicodeString |
|
3871 | 223 |
"true if this is a 2- or 4-byte unicode string |
224 |
(i.e. not a single byte string). |
|
225 |
Notice, that the name is misleading: |
|
226 |
all strings are use unicode encoding" |
|
227 |
||
2740 | 228 |
^ true |
1404 | 229 |
! ! |
230 |
||
231 |
!Unicode32String class methodsFor:'documentation'! |
|
232 |
||
233 |
version |
|
3663 | 234 |
^ '$Header$' |
2709
0d45ae840f12
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
2708
diff
changeset
|
235 |
! |
0d45ae840f12
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
2708
diff
changeset
|
236 |
|
0d45ae840f12
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
2708
diff
changeset
|
237 |
version_CVS |
3663 | 238 |
^ '$Header$' |
1404 | 239 |
! ! |
240 |
||
3065 | 241 |
|
1404 | 242 |
Unicode32String initialize! |