--- a/String.st Tue Aug 19 11:16:52 1997 +0200
+++ b/String.st Tue Aug 19 15:51:32 1997 +0200
@@ -111,6 +111,7 @@
__qSTORE(newString, self);
cp = __stringVal(newString);
+
#if defined(memset4) && !defined(NON_ASCII)
instsize = len >> 2;
if (len & 3) instsize++;
@@ -123,8 +124,12 @@
# else
while (len >= 8) {
# ifndef NON_ASCII /* i.e. EBCDIC ;-) */
+# ifdef alpha64
+ ((INT *)cp)[0] = 0x2020202020202020L;
+# else
((int *)cp)[0] = 0x20202020;
((int *)cp)[1] = 0x20202020;
+# endif
# else
cp[0] = cp[1] = cp[2] = cp[3] = ' ';
cp[4] = cp[5] = cp[6] = cp[7] = ' ';
@@ -180,8 +185,12 @@
#else
while (len >= 8) {
# ifndef NON_ASCII /* i.e. EBCDIC ;-) */
+# ifdef alpha64
+ ((INT *)cp)[0] = 0x2020202020202020L;
+# else
((int *)cp)[0] = 0x20202020;
((int *)cp)[1] = 0x20202020;
+# endif
# else
cp[0] = cp[1] = cp[2] = cp[3] = ' ';
cp[4] = cp[5] = cp[6] = cp[7] = ' ';
@@ -1288,8 +1297,6 @@
%{
int l1, l2, sz;
- char *cp1, *cp2;
- REGISTER unsigned char *dstp;
REGISTER OBJ s = aString;
REGISTER OBJ _string = String;
OBJ myClass, argClass, newString;
@@ -1302,34 +1309,20 @@
*/
if (((myClass == _string) || (myClass == Symbol))
&& ((argClass == _string) || (argClass == Symbol))) {
- cp1 = (char *) __stringVal(self);
l1 = __stringSize(self);
- if (myClass != _string) {
- int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
-
- cp1 += n;
- l1 -= n;
- }
-
- cp2 = (char *) __stringVal(s);
l2 = __stringSize(s);
- if (argClass != _string) {
- int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(s))->c_ninstvars));
-
- cp2 += n;
- l2 -= n;
- }
sz = OHDR_SIZE + l1 + l2 + 1;
__qNew(newString, sz);
if (newString != nil) {
+ char *cp1, *cp2;
+ REGISTER unsigned char *dstp;
+
__InstPtr(newString)->o_class = String;
dstp = __stringVal(newString);
- /*
- * refetch in case of a GC
- */
cp1 = (char *) __stringVal(self);
cp2 = (char *) __stringVal(aString);
+
#ifdef FAST_MEMCPY
bcopy(cp1, dstp, l1);
bcopy(cp2, dstp + l1, l2+1);
@@ -1357,6 +1350,7 @@
- generated by compiler when such a construct is detected"
|newString|
+
%{
int len1, len2, len3, sz;
#if !defined(FAST_MEMCPY) && !defined(FAST_STRCPY)
@@ -1408,6 +1402,7 @@
- generated by compiler when such a construct is detected"
|newString|
+
%{
int len1, len2, len3, len4, sz;
#if !defined(FAST_MEMCPY) && !defined(FAST_STRCPY)
@@ -1475,22 +1470,23 @@
REGISTER int count;
int len, index1, sz;
OBJ newString;
+ OBJ myClass;
- if (__isSmallInteger(start)) {
+ myClass = __qClass(self);
+
+ if (__isSmallInteger(start)
+ && ((myClass==String) || (myClass==Symbol))) {
len = __stringSize(self);
index1 = __intVal(start);
if (index1 > 0) {
- if (__qClass(self) != String) {
- int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
-
- index1 += n;
- }
if (index1 <= len) {
count = len - index1 + 1;
+ sz = OHDR_SIZE + count + 1;
+
__PROTECT_CONTEXT__
- sz = OHDR_SIZE + count + 1;
__qNew(newString, sz);
__UNPROTECT_CONTEXT__
+
if (newString != nil) {
__InstPtr(newString)->o_class = String;
dstp = __stringVal(newString);
@@ -1536,22 +1532,21 @@
REGISTER int count;
int len, sz, index1, index2;
OBJ newString;
+ OBJ myClass;
- if (__bothSmallInteger(start, stop)) {
+ myClass = __qClass(self);
+
+ if (__bothSmallInteger(start, stop)
+ && ((myClass==String) || (myClass==Symbol))) {
len = __stringSize(self);
index1 = __intVal(start);
index2 = __intVal(stop);
if ((index1 <= index2) && (index1 > 0)) {
- if (__qClass(self) != String) {
- int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
-
- index1 += n;
- index2 += n;
- }
if (index2 <= len) {
count = index2 - index1 + 1;
sz = OHDR_SIZE + count + 1;
+
__PROTECT_CONTEXT__
__qNew(newString, sz);
__UNPROTECT_CONTEXT__
@@ -1610,36 +1605,36 @@
int sz;
REGISTER unsigned char *dstp;
- int offs;
OBJ cls, newString;
+ OBJ myClass;
- if (__isCharacter(aCharacter)) {
+ myClass = __qClass(self);
+
+ if (__isCharacter(aCharacter)
+ && ((myClass==String) || (myClass==Symbol))) {
sz = __qSize(self) + 1;
- if ((cls = __qClass(self)) != String) {
- offs = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
- sz -= offs;
- } else
- offs = 0;
__PROTECT_CONTEXT__
__qNew(newString, sz);
__UNPROTECT_CONTEXT__
+
if (newString) {
__InstPtr(newString)->o_class = String;
dstp = __stringVal(newString);
+
#ifdef FAST_MEMCPY
sz = sz - OHDR_SIZE - 1 - 1;
- bcopy(__stringVal(self) + offs, dstp, sz);
+ bcopy(__stringVal(self), dstp, sz);
dstp += sz;
#else
# ifdef FAST_STRCPY
- strcpy(dstp, __stringVal(self) + offs);
+ strcpy(dstp, __stringVal(self));
dstp += sz - OHDR_SIZE - 1 - 1;
# else
{
REGISTER unsigned char *srcp;
- srcp = __stringVal(self) + offs;
+ srcp = __stringVal(self);
while ((*dstp = *srcp++) != '\0')
dstp++;
}
@@ -1737,8 +1732,7 @@
#endif
RETURN ( self );
}
-%}
-.
+%}.
^ super atAllPut:aCharacter
"
@@ -1768,8 +1762,7 @@
}
RETURN ( self );
}
-%}
-.
+%}.
^ super replaceAll:oldCharacter by:newCharacter
"
@@ -1829,8 +1822,7 @@
}
}
}
-%}
-.
+%}.
^ super replaceFrom:start to:stop with:aString startingAt:repStart
!
@@ -1856,13 +1848,14 @@
}
RETURN ( self );
}
-%}
-.
+%}.
^ super reverse
!
withoutSeparators
- "return a copy of myself without leading and trailing whitespace.
+ "return a string containing the chars of myself
+ without leading and trailing whitespace.
+ If there is no whitespace, the receiver is returned.
Notice, this is different from String>>withoutSpaces."
|startIndex "{ Class: SmallInteger }"
@@ -1870,6 +1863,7 @@
sz|
startIndex := 0.
+
%{
REGISTER unsigned char *cp0;
REGISTER unsigned char *cp;
@@ -1878,6 +1872,17 @@
/* ignore instances of subclasses ... */
if (__qClass(self) == String) {
cp = cp0 = __stringVal(self);
+
+#ifndef NON_ASCII
+# ifdef alpha64
+ while (*((unsigned INT *)cp) == 0x2020202020202020L) {
+ cp += 8;
+ }
+# endif
+ while (*((unsigned *)cp) == 0x20202020) {
+ cp += 4;
+ }
+#endif
while ((c = *cp)
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */
&& (c <= ' ')
@@ -1892,7 +1897,7 @@
while ((cp >= cp0) && (*cp == ' ')) cp--;
c = *cp;
while ((cp >= cp0) &&
-#ifndef NON_ASCII /* i.e. EBCDIC ;-) */
+#ifndef NON_ASCII
(c <= ' ') &&
#endif
((c == ' ') || (c == '\n') || (c == '\t')
@@ -1911,7 +1916,9 @@
!
withoutSpaces
- "return a copy of myself without leading and trailing spaces.
+ "return a string containing the characters of myself
+ without leading and trailing spaces.
+ If there are no spaces, the receiver is returned.
Notice, this is different from String>>withoutSeparators."
|startIndex "{ Class: SmallInteger }"
@@ -1926,7 +1933,19 @@
/* ignore instances of subclasses ... */
if (__qClass(self) == String) {
cp = cp0 = __stringVal(self);
+
+#ifndef NON_ASCII
+# ifdef alpha64
+ while (*((unsigned INT *)cp) == 0x2020202020202020L) {
+ cp += 8;
+ }
+# endif /* alpha64 */
+ while (*((unsigned *)cp) == 0x20202020) {
+ cp += 4;
+ }
+#endif
while (*cp == ' ') cp++;
+
startIndex = __MKSMALLINT(cp - cp0 + 1);
cp = cp + strlen(cp) - 1;
while ((cp >= cp0) && (*cp == ' ')) cp--;
@@ -2076,14 +2095,14 @@
if ((cls == String) || (cls == Symbol)) {
RETURN ( (__stringSize(self) == 0) ? true : false);
}
-%}
-.
+%}.
^ super isEmpty
!
knownAsSymbol
"return true, if there is a symbol with same characters in the
- system - use to check for existance of a symbol without creating one"
+ system.
+ Can be used to check for existance of a symbol without creating one"
%{ /* NOCONTEXT */
RETURN ( __KNOWNASSYMBOL(__stringVal(self)) );
@@ -2127,8 +2146,8 @@
!String methodsFor:'testing'!
-endsWith:aString
- "return true, if the receiver end with something, aString."
+endsWith:aStringOrChar
+ "return true, if the receiver ends with something, aStringOrChar."
%{ /* NOCONTEXT */
@@ -2137,15 +2156,15 @@
unsigned char c;
if ((__isString(self) || __isSymbol(self))
- && (__isString(aString) || __isSymbol(aString))) {
+ && (__isString(aStringOrChar) || __isSymbol(aStringOrChar))) {
len1 = __qSize(self);
- len2 = __qSize(aString);
+ len2 = __qSize(aStringOrChar);
if (len1 < len2) {
RETURN ( false );
}
src1 = __stringVal(self) + len1 - len2;
- src2 = __stringVal(aString);
+ src2 = __stringVal(aStringOrChar);
while (c = *src2++) {
if (c != *src1++) {
RETURN ( false );
@@ -2154,11 +2173,11 @@
RETURN (true);
}
%}.
- (aString isMemberOf:Character) ifTrue:[
+ (aStringOrChar isMemberOf:Character) ifTrue:[
self size == 0 ifTrue:[^ false].
- ^ (self at:(self size)) == aString
+ ^ (self at:(self size)) == aStringOrChar
].
- ^ super endsWith:aString
+ ^ super endsWith:aStringOrChar
"
'hello world' endsWith:'world'
@@ -2183,14 +2202,21 @@
src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
#ifndef NON_ASCII
+# ifdef alpha64
+ while (*((unsigned INT *)src) == 0x2020202020202020L) {
+ src += 8;
+ }
+# endif /* alpha64 */
while (*((unsigned *)src) == 0x20202020) {
src += 4;
}
-#endif
- while (c = *src++)
+#endif /* ascii */
+
+ while (c = *src++) {
if (c != ' ') {
RETURN ( false );
}
+ }
%}.
^ true
!
@@ -2298,8 +2324,8 @@
'Computer' levenshteinTo:'computer'"
!
-startsWith:aString
- "return true, if the receiver starts with something, aString."
+startsWith:aStringOrChar
+ "return true, if the receiver starts with something, aStringOrChar."
%{ /* NOCONTEXT */
@@ -2308,15 +2334,15 @@
unsigned char c;
if ((__isString(self) || __isSymbol(self))
- && (__isString(aString) || __isSymbol(aString))) {
+ && (__isString(aStringOrChar) || __isSymbol(aStringOrChar))) {
src1 = __stringVal(self);
- src2 = __stringVal(aString);
+ src2 = __stringVal(aStringOrChar);
if (src1[0] != src2[0]) {
RETURN ( false );
}
len1 = __qSize(self);
- len2 = __qSize(aString);
+ len2 = __qSize(aStringOrChar);
if (len1 < len2) {
RETURN ( false );
}
@@ -2330,11 +2356,11 @@
RETURN (true);
}
%}.
- (aString isMemberOf:Character) ifTrue:[
+ (aStringOrChar isMemberOf:Character) ifTrue:[
self size == 0 ifTrue:[^ false].
- ^ (self at:1) == aString
+ ^ (self at:1) == aStringOrChar
].
- ^ super startsWith:aString
+ ^ super startsWith:aStringOrChar
"
'hello world' startsWith:'hello'
@@ -2347,5 +2373,5 @@
!String class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.95 1997-08-14 15:48:33 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.96 1997-08-19 13:51:32 cg Exp $'
! !