author | Jan Vrany <jan.vrany@labware.com> |
Tue, 01 Jun 2021 20:19:13 +0100 | |
branch | jv |
changeset 25424 | 51bd8a6b196f |
parent 23547 | c69c97cec351 |
permissions | -rw-r--r-- |
23547
c69c97cec351
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
19948
diff
changeset
|
1 |
"{ Encoding: utf8 }" |
c69c97cec351
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
19948
diff
changeset
|
2 |
|
7946 | 3 |
" |
4 |
COPYRIGHT (c) 1997 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 |
" |
|
10223
761e2a050b69
twoByteString moved (req'd in VM)
Claus Gittinger <cg@exept.de>
parents:
9648
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
7946 | 15 |
|
17537 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
7946 | 18 |
TwoByteString variableWordSubclass:#Unicode16String |
19 |
instanceVariableNames:'' |
|
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Collections-Text' |
|
23 |
! |
|
24 |
||
25 |
!Unicode16String class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1997 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 |
" |
|
10223
761e2a050b69
twoByteString moved (req'd in VM)
Claus Gittinger <cg@exept.de>
parents:
9648
diff
changeset
|
45 |
Represents 16-bit (2-byte) Unicode strings. |
7946 | 46 |
" |
47 |
! ! |
|
48 |
||
49 |
!Unicode16String class methodsFor:'initialization'! |
|
50 |
||
51 |
initialize |
|
52 |
"initialize the class - private" |
|
53 |
||
7949 | 54 |
self flags:(Behavior flagWords). |
55 |
||
56 |
Smalltalk at:#UnicodeString put:Unicode16String. |
|
7946 | 57 |
|
58 |
" |
|
59 |
Unicode16String initialize |
|
60 |
" |
|
61 |
||
62 |
"Created: 30.6.1997 / 15:35:52 / cg" |
|
63 |
"Modified: 30.6.1997 / 15:39:21 / cg" |
|
64 |
! ! |
|
65 |
||
11323 | 66 |
!Unicode16String class methodsFor:'reading'! |
67 |
||
68 |
readFrom:aStreamOrString onError:exceptionBlock |
|
69 |
"read & return the next String from the (character-)stream aStream; |
|
70 |
skipping all whitespace first; return the value of exceptionBlock, |
|
71 |
if no string can be read. The sequence of characters as read from the |
|
72 |
stream must be one as stored via storeOn: or storeString." |
|
73 |
||
74 |
" |
|
75 |
this method is not to be inherited |
|
76 |
(i.e. not ok for subclasses; Symbol, for example) |
|
77 |
" |
|
78 |
self ~~ Unicode16String ifTrue:[ |
|
79 |
^ super readFrom:aStreamOrString onError:exceptionBlock |
|
80 |
]. |
|
81 |
^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock |
|
82 |
||
83 |
" |
|
23547
c69c97cec351
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
19948
diff
changeset
|
84 |
self readFrom:'abcäöü' storeString |
11323 | 85 |
" |
86 |
! ! |
|
87 |
||
88 |
||
7946 | 89 |
!Unicode16String methodsFor:'conversion'! |
90 |
||
8294
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
91 |
asUnicode16String |
8942 | 92 |
"as the receiver already is a unicode-16 string, return it" |
93 |
||
8294
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
94 |
^ self |
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
95 |
! |
ba5f4421848f
Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents:
8049
diff
changeset
|
96 |
|
7946 | 97 |
asUnicodeString |
8942 | 98 |
"as the receiver already is a unicode string, return it" |
99 |
||
7946 | 100 |
^ self |
101 |
! ! |
|
102 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
103 |
!Unicode16String methodsFor:'printing & storing'! |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
104 |
|
14121
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
105 |
displayOn:aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
106 |
"display myself as on aStream. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
107 |
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
|
108 |
|
17537 | 109 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
110 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
|
14558 | 111 |
aGCOrStream isStream ifTrue:[ |
14121
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
112 |
aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
113 |
nextPut:$'; |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
114 |
nextPutAllUnicode:self; |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
115 |
nextPut:$'. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
116 |
^ self |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
117 |
]. |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
118 |
^ super displayOn:aGCOrStream |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
119 |
! |
fea92d19d1a4
added: #displayOn: (instead of #displaySting)
Stefan Vogel <sv@exept.de>
parents:
14075
diff
changeset
|
120 |
|
11323 | 121 |
printOn:aStream |
122 |
"print the receiver on aStream. |
|
13986
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
123 |
Let aStream decide how to represent this, whether utf8, ucs16, ..." |
11323 | 124 |
|
125 |
aStream nextPutAllUnicode:self |
|
13986
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
126 |
|
c8b952d6139c
comment/format in: #printOn:
Claus Gittinger <cg@exept.de>
parents:
13737
diff
changeset
|
127 |
"Modified (comment): / 25-01-2012 / 10:28:34 / cg" |
11323 | 128 |
! |
129 |
||
130 |
storeOn:aStream |
|
131 |
"put the storeString of myself on aStream" |
|
132 |
||
18970 | 133 |
self containsNon7BitAscii ifTrue:[ |
134 |
"non-7bit string has been utf8Encoded" |
|
135 |
self utf8Encoded storeOn:aStream. |
|
136 |
aStream nextPutAll:' utf8Decoded'. |
|
137 |
] ifFalse:[ |
|
138 |
self asSingleByteString storeOn:aStream. |
|
139 |
]. |
|
140 |
||
141 |
" |
|
142 |
String streamContents:[:s| |
|
143 |
'hello' asUnicodeString storeOn:s |
|
144 |
]. |
|
145 |
||
146 |
String streamContents:[:s| |
|
23547
c69c97cec351
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
19948
diff
changeset
|
147 |
'hello -öäüß' asUnicodeString storeOn:s |
18970 | 148 |
]. |
149 |
" |
|
13737 | 150 |
|
151 |
"/ aStream nextPut:$'. |
|
152 |
"/ (self includes:$') ifTrue:[ |
|
153 |
"/ self do:[:thisChar | |
|
154 |
"/ (thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
155 |
"/ aStream nextPutUnicode:thisChar |
|
156 |
"/ ] |
|
157 |
"/ ] ifFalse:[ |
|
158 |
"/ aStream nextPutAllUnicode:self |
|
159 |
"/ ]. |
|
160 |
"/ aStream nextPut:$' |
|
161 |
||
162 |
"Modified: / 28-09-2011 / 16:17:38 / cg" |
|
11323 | 163 |
! |
164 |
||
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
165 |
storeString |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
166 |
"return a String for storing myself" |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
167 |
|
18970 | 168 |
self containsNon7BitAscii ifTrue:[ |
169 |
"non-7bit string has been utf8Encoded" |
|
170 |
^ (self utf8Encoded storeString),' utf8Decoded'. |
|
171 |
] ifFalse:[ |
|
172 |
^ self asSingleByteString storeString. |
|
173 |
]. |
|
174 |
||
175 |
" |
|
176 |
'hello' asUnicodeString storeString |
|
23547
c69c97cec351
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
19948
diff
changeset
|
177 |
'hello -öäüß' storeString |
c69c97cec351
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present
Patrik Svestka <patrik.svestka@gmail.com>
parents:
19948
diff
changeset
|
178 |
'hello -öäüß' asUnicodeString storeString |
18970 | 179 |
" |
13737 | 180 |
|
13989
cd15b3b6154a
backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents:
13988
diff
changeset
|
181 |
"Modified: / 25-01-2012 / 11:59:34 / cg" |
14124 | 182 |
! |
183 |
||
184 |
unicodeStoreOn:aStream |
|
185 |
"put the storeString of myself on aStream" |
|
186 |
||
187 |
aStream nextPut:$'. |
|
188 |
(self includes:$') ifTrue:[ |
|
189 |
self do:[:thisChar | |
|
190 |
(thisChar == $') ifTrue:[aStream nextPut:thisChar]. |
|
191 |
aStream nextPutUnicode:thisChar |
|
192 |
] |
|
193 |
] ifFalse:[ |
|
194 |
aStream nextPutAllUnicode:self |
|
195 |
]. |
|
196 |
aStream nextPut:$' |
|
197 |
! |
|
198 |
||
199 |
unicodeStoreString |
|
200 |
"return a UnicodeString for storing myself. |
|
201 |
This method is a kind of kludge. |
|
202 |
Use it when you want to write a storeString to an encoded Stream" |
|
203 |
||
204 |
^ self basicStoreString. |
|
205 |
! ! |
|
206 |
||
207 |
!Unicode16String methodsFor:'testing'! |
|
208 |
||
209 |
isUnicode16String |
|
210 |
^ true |
|
211 |
! |
|
212 |
||
213 |
isUnicodeString |
|
19937 | 214 |
"true if this is a 2- or 4-byte unicode string |
215 |
(i.e. not a single byte string). |
|
216 |
Notice, that the name is misleading: |
|
217 |
all strings are use unicode encoding" |
|
218 |
||
14124 | 219 |
^ true |
8049
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
220 |
! ! |
ccd0e8f26439
printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents:
7982
diff
changeset
|
221 |
|
7946 | 222 |
!Unicode16String class methodsFor:'documentation'! |
223 |
||
224 |
version |
|
18970 | 225 |
^ '$Header$' |
13988
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
226 |
! |
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
227 |
|
81154d310967
use new c-escape string for stroreString
Claus Gittinger <cg@exept.de>
parents:
13986
diff
changeset
|
228 |
version_CVS |
18970 | 229 |
^ '$Header$' |
7946 | 230 |
! ! |
231 |
||
14605 | 232 |
|
7946 | 233 |
Unicode16String initialize! |