author | Claus Gittinger <cg@exept.de> |
Thu, 10 Jul 2014 14:28:32 +0200 | |
changeset 16750 | 394404a33691 |
parent 14557 | 427740fc4329 |
child 17621 | 098adea6b2d4 |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
235 | 3 |
All Rights Reserved |
1 | 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:
8094
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
8094
d05f69bd0097
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
5761
diff
changeset
|
13 |
|
5761 | 14 |
CharacterArray variableWordSubclass:#TwoByteString |
992
f456f8f7d421
JIS decode now in CharacterArray
Claus Gittinger <cg@exept.de>
parents:
631
diff
changeset
|
15 |
instanceVariableNames:'' |
f456f8f7d421
JIS decode now in CharacterArray
Claus Gittinger <cg@exept.de>
parents:
631
diff
changeset
|
16 |
classVariableNames:'' |
f456f8f7d421
JIS decode now in CharacterArray
Claus Gittinger <cg@exept.de>
parents:
631
diff
changeset
|
17 |
poolDictionaries:'' |
f456f8f7d421
JIS decode now in CharacterArray
Claus Gittinger <cg@exept.de>
parents:
631
diff
changeset
|
18 |
category:'Collections-Text' |
1 | 19 |
! |
20 |
||
89 | 21 |
!TwoByteString class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
235 | 26 |
All Rights Reserved |
1 | 27 |
|
89 | 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 |
documentation |
|
38 |
" |
|
39 |
TwoByteStrings are like strings, but storing 16bits per character. |
|
40 |
The integration of them into the system is not completed .... |
|
1290 | 41 |
|
42 |
[author:] |
|
43 |
Claus Gittinger |
|
1309 | 44 |
|
45 |
[see also:] |
|
1382 | 46 |
Text JISEncodedString |
1309 | 47 |
StringCollection |
89 | 48 |
" |
1214 | 49 |
! ! |
50 |
||
51 |
!TwoByteString class methodsFor:'initialization'! |
|
996 | 52 |
|
53 |
initialize |
|
1253 | 54 |
"initialize the class - private" |
55 |
||
996 | 56 |
self flags:(Behavior flagWords) |
57 |
||
58 |
" |
|
59 |
TwoByteString initialize |
|
60 |
" |
|
1214 | 61 |
|
1253 | 62 |
"Modified: 22.4.1996 / 16:14:14 / cg" |
89 | 63 |
! ! |
1 | 64 |
|
65 |
!TwoByteString class methodsFor:'instance creation'! |
|
66 |
||
67 |
basicNew:anInteger |
|
68 |
"return a new empty string with anInteger characters" |
|
69 |
||
1024 | 70 |
^ (super basicNew:anInteger) atAllPut:(Character space) |
71 |
||
72 |
"Modified: 26.2.1996 / 14:38:47 / cg" |
|
1 | 73 |
! ! |
74 |
||
75 |
!TwoByteString methodsFor:'accessing'! |
|
76 |
||
77 |
basicAt:index |
|
78 |
"return the character at position index, an Integer |
|
73 | 79 |
- reimplemented here since we return 16-bit characters" |
1 | 80 |
|
1024 | 81 |
|val| |
63 | 82 |
|
1024 | 83 |
val := super basicAt:index. |
63 | 84 |
^ Character value:val |
1024 | 85 |
|
86 |
"Modified: 26.2.1996 / 17:02:16 / cg" |
|
1 | 87 |
! |
88 |
||
89 |
basicAt:index put:aCharacter |
|
1230 | 90 |
"store the argument, aCharacter at position index, an Integer. |
91 |
Returns aCharacter (sigh). |
|
73 | 92 |
- reimplemented here since we store 16-bit characters" |
1 | 93 |
|
8094
d05f69bd0097
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
5761
diff
changeset
|
94 |
super basicAt:index put:aCharacter codePoint. |
63 | 95 |
^ aCharacter |
608 | 96 |
|
1230 | 97 |
"Modified: 19.4.1996 / 11:16:22 / cg" |
14123 | 98 |
! |
99 |
||
100 |
unsignedShortAt:index |
|
101 |
"return the short at position index, an Integer" |
|
102 |
||
103 |
^ super basicAt:index. |
|
1014 | 104 |
! ! |
105 |
||
16750 | 106 |
!TwoByteString methodsFor:'filling and replacing'! |
107 |
||
108 |
replaceFrom:start to:stop with:aString startingAt:repStart |
|
109 |
"replace the characters starting at index start, anInteger and ending |
|
110 |
at stop, anInteger with characters from aString starting at repStart. |
|
111 |
Return the receiver. |
|
112 |
||
113 |
- reimplemented here for speed" |
|
114 |
||
115 |
%{ /* NOCONTEXT */ |
|
116 |
||
117 |
#ifndef NO_PRIM_STRING |
|
118 |
if (__bothSmallInteger(start, stop)) { |
|
119 |
REGISTER int count; |
|
120 |
int len, index1, index2; |
|
121 |
||
122 |
index1 = __intVal(start); |
|
123 |
index2 = __intVal(stop); |
|
124 |
count = index2 - index1 + 1; |
|
125 |
if (count <= 0) { |
|
126 |
RETURN (self); |
|
127 |
} |
|
128 |
len = __twoByteStringSize(self); |
|
129 |
if ((index2 <= len) && (index1 > 0)) { |
|
130 |
int repLen, repIndex; |
|
131 |
||
132 |
repIndex = __intVal(repStart); |
|
133 |
||
134 |
if (__isStringLike(aString)) { |
|
135 |
repLen = __stringSize(aString); |
|
136 |
if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) { |
|
137 |
REGISTER unsigned char *srcp; |
|
138 |
REGISTER unsigned short *dstp; |
|
139 |
||
140 |
srcp = __stringVal(aString) + repIndex - 1; |
|
141 |
dstp = __twoByteStringVal(self) + index1 - 1; |
|
142 |
while (count-- > 0) { |
|
143 |
*dstp++ = *srcp++; |
|
144 |
} |
|
145 |
RETURN (self); |
|
146 |
} |
|
147 |
} else if (__isTwoByteString(aString) || __isUnicode16String(aString)) { |
|
148 |
repLen = __twoByteStringSize(aString); |
|
149 |
if ((repIndex > 0) && ((repIndex + count - 1) <= repLen)) { |
|
150 |
REGISTER unsigned short *srcp; |
|
151 |
REGISTER unsigned short *dstp; |
|
152 |
||
153 |
srcp = __twoByteStringVal(aString) + repIndex - 1; |
|
154 |
dstp = __twoByteStringVal(self) + index1 - 1; |
|
155 |
if (aString == self) { |
|
156 |
/* take care of overlapping copy */ |
|
157 |
if (srcp < dstp) { |
|
158 |
/* must do a reverse copy */ |
|
159 |
srcp += count; |
|
160 |
dstp += count; |
|
161 |
while (count-- > 0) { |
|
162 |
*--dstp = *--srcp; |
|
163 |
} |
|
164 |
RETURN (self); |
|
165 |
} |
|
166 |
} |
|
167 |
if (count > 5) { |
|
168 |
memcpy(dstp, srcp, count*sizeof(short)); |
|
169 |
} else { |
|
170 |
while (count-- > 0) { |
|
171 |
*dstp++ = *srcp++; |
|
172 |
} |
|
173 |
} |
|
174 |
RETURN (self); |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
#endif |
|
180 |
%}. |
|
181 |
"/ arrive here if any index arg is out o range, or the source is neither a string, |
|
182 |
"/ nor a two-byte string. |
|
183 |
^ super replaceFrom:start to:stop with:aString startingAt:repStart |
|
184 |
||
185 |
" |
|
186 |
'hello world' asUnicode16String replaceFrom:1 to:5 with:'123456' startingAt:2 |
|
187 |
'hello world' asUnicode16String replaceFrom:1 to:5 with:'123456' asUnicode16String startingAt:2 |
|
188 |
'hello world' asUnicode16String replaceFrom:1 to:0 with:'123456' startingAt:2 |
|
189 |
'hello' asUnicode16String replaceFrom:1 to:6 with:'123456' startingAt:2 |
|
190 |
'hello world' asUnicode16String replaceFrom:1 to:1 with:'123456' startingAt:2 |
|
191 |
" |
|
192 |
! ! |
|
193 |
||
608 | 194 |
!TwoByteString methodsFor:'queries'! |
195 |
||
1017 | 196 |
bitsPerCharacter |
1239 | 197 |
"return the number of bits each character has. |
198 |
Here, 16 is returned (storing double byte characters)." |
|
199 |
||
1017 | 200 |
^ 16 |
1239 | 201 |
|
202 |
"Modified: 20.4.1996 / 23:08:38 / cg" |
|
14557 | 203 |
! |
204 |
||
205 |
isWideString |
|
206 |
^ true |
|
608 | 207 |
! ! |
208 |
||
631 | 209 |
!TwoByteString class methodsFor:'documentation'! |
210 |
||
211 |
version |
|
16750 | 212 |
^ '$Header: /cvs/stx/stx/libbasic/TwoByteString.st,v 1.35 2014-07-10 12:28:32 cg Exp $' |
631 | 213 |
! ! |
8094
d05f69bd0097
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
5761
diff
changeset
|
214 |
|
16750 | 215 |
|
996 | 216 |
TwoByteString initialize! |