--- a/String.st Tue Jun 28 15:09:27 2005 +0200
+++ b/String.st Tue Jul 05 16:07:10 2005 +0200
@@ -48,39 +48,39 @@
!String primitiveFunctions!
%{
-static int
+static int
nextOnKeyboard(char1, char2) {
/* compare two characters if they are next to each other on a (US-) keyboard */
static char *keys[] = { "1234567890-",
- "*qwertyuiop",
- "**asdfghjkl:",
- "***zxcvbnm",
- 0 };
+ "*qwertyuiop",
+ "**asdfghjkl:",
+ "***zxcvbnm",
+ 0 };
char **line1, **line2;
char *col1, *col2;
int diff;
for (line1 = keys; *line1 != 0; line1++) {
- for (col1 = *line1; *col1 != 0 && *col1 != char1; col1++)
- continue;
+ for (col1 = *line1; *col1 != 0 && *col1 != char1; col1++)
+ continue;
}
if (*col1 == 0)
- return(0);
+ return(0);
for (line2 = keys; *line2 != 0; line2++) {
- for (col2 = *line2; *col2 != 0 && *col2 != char2; col2++)
- continue;
+ for (col2 = *line2; *col2 != 0 && *col2 != char2; col2++)
+ continue;
}
if (*col2 == 0)
- return(0);
+ return(0);
diff = col1 - col2;
if (diff > 1 || diff < -1)
- return(0);
+ return(0);
diff = line1 - line2;
if (diff > 1 || diff < -1)
- return(0);
+ return(0);
return(1);
}
@@ -126,11 +126,11 @@
or use instances of encodedString.
[author:]
- Claus Gittinger
+ Claus Gittinger
[see also:]
- Text StringCollection TwoByteString JISEncodedString
- Symbol
+ Text StringCollection TwoByteString JISEncodedString
+ Symbol
"
! !
@@ -152,127 +152,127 @@
int nInstVars, instsize;
if (__isSmallInteger(anInteger)) {
- len = __intVal(anInteger);
- if (len >= 0) {
- instsize = OHDR_SIZE + len + 1;
- if (self == String) {
- if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */
- /*
- * the most common case
- */
- __qCheckedNew(newString, instsize);
- __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
- __qSTORE(newString, self);
-
- cp = __stringVal(newString);
+ len = __intVal(anInteger);
+ if (len >= 0) {
+ instsize = OHDR_SIZE + len + 1;
+ if (self == String) {
+ if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */
+ /*
+ * the most common case
+ */
+ __qCheckedNew(newString, instsize);
+ __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
+ __qSTORE(newString, self);
+
+ cp = __stringVal(newString);
#if defined(memset4) && !defined(NON_ASCII)
- {
- /*
- * no sizeof(int) here please -
- * - memset4 (if defined) fills 4-bytes on ALL machines
- */
- int l4 = len >> 2;
-
- if (len & 3) l4++;
- memset4(cp, 0x20202020, l4);
- cp[len] = '\0';
- }
+ {
+ /*
+ * no sizeof(int) here please -
+ * - memset4 (if defined) fills 4-bytes on ALL machines
+ */
+ int l4 = len >> 2;
+
+ if (len & 3) l4++;
+ memset4(cp, 0x20202020, l4);
+ cp[len] = '\0';
+ }
#else
# ifdef FAST_MEMSET
- memset(cp, ' ', len);
- cp[len] = '\0';
+ memset(cp, ' ', len);
+ cp[len] = '\0';
# else
- while (len >= 8) {
+ while (len >= 8) {
# ifndef NON_ASCII /* i.e. EBCDIC */
# ifdef INT64
- ((INT64 *)cp)[0] = 0x2020202020202020L;
+ ((INT64 *)cp)[0] = 0x2020202020202020L;
# else
- ((int *)cp)[0] = 0x20202020;
- ((int *)cp)[1] = 0x20202020;
+ ((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] = ' ';
+ cp[0] = cp[1] = cp[2] = cp[3] = ' ';
+ cp[4] = cp[5] = cp[6] = cp[7] = ' ';
# endif
- cp += 8;
- len -= 8;
- }
- while (len--)
- *cp++ = ' ';
- *cp = '\0';
+ cp += 8;
+ len -= 8;
+ }
+ while (len--)
+ *cp++ = ' ';
+ *cp = '\0';
# endif /* not FAST_MEMSET */
#endif /* not memset4 */
- RETURN (newString);
- }
- nInstVars = 0;
- } else {
- nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
- instsize += __OBJS2BYTES__(nInstVars);
- }
-
- __PROTECT_CONTEXT__;
- __qNew(newString, instsize); /* OBJECT ALLOCATION */
- __UNPROTECT_CONTEXT__;
-
- if (newString == nil) goto fail;
-
- __InstPtr(newString)->o_class = self;
- __qSTORE(newString, self);
-
- if (nInstVars) {
- /*
- * nil-out instvars
- */
+ RETURN (newString);
+ }
+ nInstVars = 0;
+ } else {
+ nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
+ instsize += __OBJS2BYTES__(nInstVars);
+ }
+
+ __PROTECT_CONTEXT__;
+ __qNew(newString, instsize); /* OBJECT ALLOCATION */
+ __UNPROTECT_CONTEXT__;
+
+ if (newString == nil) goto fail;
+
+ __InstPtr(newString)->o_class = self;
+ __qSTORE(newString, self);
+
+ if (nInstVars) {
+ /*
+ * nil-out instvars
+ */
#if defined(memset4)
- memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
+ memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
#else
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
- /*
- * knowing that nil is 0
- */
- memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
+ /*
+ * knowing that nil is 0
+ */
+ memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
# else
- op = __InstPtr(newString)->i_instvars;
- do {
- *op++ = nil;
- } while (--nInstVars);
+ op = __InstPtr(newString)->i_instvars;
+ do {
+ *op++ = nil;
+ } while (--nInstVars);
# endif
#endif
- cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars);
- } else {
- cp = __stringVal(newString);
- }
-
- /*
- * fill with spaces
- */
+ cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars);
+ } else {
+ cp = __stringVal(newString);
+ }
+
+ /*
+ * fill with spaces
+ */
#ifdef FAST_MEMSET
- memset(cp, ' ', len);
- *(cp + len) = '\0';
+ memset(cp, ' ', len);
+ *(cp + len) = '\0';
#else
- while (len >= 8) {
+ while (len >= 8) {
# ifndef NON_ASCII /* i.e. EBCDIC ;-) */
# ifdef INT64
- ((INT64 *)cp)[0] = 0x2020202020202020L;
+ ((INT64 *)cp)[0] = 0x2020202020202020L;
# else
- ((int *)cp)[0] = 0x20202020;
- ((int *)cp)[1] = 0x20202020;
+ ((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] = ' ';
+ cp[0] = cp[1] = cp[2] = cp[3] = ' ';
+ cp[4] = cp[5] = cp[6] = cp[7] = ' ';
# endif
- cp += 8;
- len -= 8;
- }
- while (len--)
- *cp++ = ' ';
- *cp = '\0';
+ cp += 8;
+ len -= 8;
+ }
+ while (len--)
+ *cp++ = ' ';
+ *cp = '\0';
#endif
- RETURN (newString);
- }
+ RETURN (newString);
+ }
}
fail: ;;
%}.
@@ -281,11 +281,11 @@
use error handling in superclass
"
(anInteger < 0) ifTrue:[
- "
- the argument is negative,
- "
- self error:'bad (negative) argument to new:'.
- ^ nil
+ "
+ the argument is negative,
+ "
+ self error:'bad (negative) argument to new:'.
+ ^ nil
].
^ (super basicNew:anInteger+1) atAllPut:(Character space)
@@ -304,7 +304,7 @@
readFrom:aStreamOrString onError:exceptionBlock
"read & return the next String from the (character-)stream aStream;
skipping all whitespace first; return the value of exceptionBlock,
- if no string can be read. The sequence of characters as read from the
+ if no string can be read. The sequence of characters as read from the
stream must be one as stored via storeOn: or storeString."
|str collected char|
@@ -314,7 +314,7 @@
(i.e. not ok for subclasses; Symbol, for example)
"
self ~~ String ifTrue:[
- ^ super readFrom:aStreamOrString onError:exceptionBlock
+ ^ super readFrom:aStreamOrString onError:exceptionBlock
].
str := aStreamOrString readStream.
@@ -322,31 +322,31 @@
"skip whiteSpace"
str skipSeparators.
(str next == $') ifTrue:[
- collected := WriteStream on:(String new).
- [true] whileTrue:[
- str atEnd ifTrue:[
- "/ mhmh - reached the end without a closing quote
- "/ looks like an error to me ...
- ^ exceptionBlock value
- ].
- char := str next.
- char == $' ifTrue:[
- "/ look for another quote
- str peekOrNil == $' ifFalse:[
- ^ collected contents
- ].
- str next.
- ].
- collected nextPut:char
- ]
+ collected := WriteStream on:(String new).
+ [true] whileTrue:[
+ str atEnd ifTrue:[
+ "/ mhmh - reached the end without a closing quote
+ "/ looks like an error to me ...
+ ^ exceptionBlock value
+ ].
+ char := str next.
+ char == $' ifTrue:[
+ "/ look for another quote
+ str peekOrNil == $' ifFalse:[
+ ^ collected contents
+ ].
+ str next.
+ ].
+ collected nextPut:char
+ ]
].
^ exceptionBlock value
"
- String readFrom:('''hello world''' readStream)
- String readFrom:('''hello '''' world''' readStream)
+ String readFrom:('''hello world''' readStream)
+ String readFrom:('''hello '''' world''' readStream)
String readFrom:('1 ''hello'' ' readStream)
- String readFrom:('1 ''hello'' ' readStream) onError:['foobar']
+ String readFrom:('1 ''hello'' ' readStream) onError:['foobar']
"
"Modified: / 14.4.1998 / 18:46:26 / cg"
@@ -366,64 +366,64 @@
int nInstVars, instsize;
if (__isSmallInteger(anInteger)) {
- len = __intVal(anInteger);
- if (len >= 0) {
- instsize = OHDR_SIZE + len + 1;
- if (self == String) {
- if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */
- /*
- * the most common case
- */
- __qCheckedNew(newString, instsize);
- __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
- __qSTORE(newString, self);
-
- cp = __stringVal(newString);
- cp[len] = '\0';
- RETURN (newString);
- }
- nInstVars = 0;
- } else {
- nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
- instsize += __OBJS2BYTES__(nInstVars);
- }
-
- __PROTECT_CONTEXT__;
- __qNew(newString, instsize); /* OBJECT ALLOCATION */
- __UNPROTECT_CONTEXT__;
-
- if (newString == nil) goto fail;
-
- __InstPtr(newString)->o_class = self;
- __qSTORE(newString, self);
-
- if (nInstVars) {
- /*
- * nil-out instvars
- */
+ len = __intVal(anInteger);
+ if (len >= 0) {
+ instsize = OHDR_SIZE + len + 1;
+ if (self == String) {
+ if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */
+ /*
+ * the most common case
+ */
+ __qCheckedNew(newString, instsize);
+ __InstPtr(newString)->o_class = self; /* no need for PROTECT - there was no GC */
+ __qSTORE(newString, self);
+
+ cp = __stringVal(newString);
+ cp[len] = '\0';
+ RETURN (newString);
+ }
+ nInstVars = 0;
+ } else {
+ nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
+ instsize += __OBJS2BYTES__(nInstVars);
+ }
+
+ __PROTECT_CONTEXT__;
+ __qNew(newString, instsize); /* OBJECT ALLOCATION */
+ __UNPROTECT_CONTEXT__;
+
+ if (newString == nil) goto fail;
+
+ __InstPtr(newString)->o_class = self;
+ __qSTORE(newString, self);
+
+ if (nInstVars) {
+ /*
+ * nil-out instvars
+ */
#if defined(memset4)
- memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
+ memset4(__InstPtr(newString)->i_instvars, nil, nInstVars);
#else
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
- /*
- * knowing that nil is 0
- */
- memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
+ /*
+ * knowing that nil is 0
+ */
+ memset(__InstPtr(newString)->i_instvars, 0, __OBJS2BYTES__(nInstVars));
# else
- op = __InstPtr(newString)->i_instvars;
- do {
- *op++ = nil;
- } while (--nInstVars);
+ op = __InstPtr(newString)->i_instvars;
+ do {
+ *op++ = nil;
+ } while (--nInstVars);
# endif
#endif
- cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars);
- } else {
- cp = __stringVal(newString);
- }
-
- *(cp + len) = '\0';
- RETURN (newString);
- }
+ cp = __stringVal(newString) + __OBJS2BYTES__(nInstVars);
+ } else {
+ cp = __stringVal(newString);
+ }
+
+ *(cp + len) = '\0';
+ RETURN (newString);
+ }
}
fail: ;;
%}.
@@ -432,11 +432,11 @@
use error handling in superclass
"
(anInteger < 0) ifTrue:[
- "
- the argument is negative,
- "
- self error:'bad (negative) argument to new:'.
- ^ nil
+ "
+ the argument is negative,
+ "
+ self error:'bad (negative) argument to new:'.
+ ^ nil
].
^ self basicNew:anInteger
@@ -468,9 +468,9 @@
"return a string consisting of the cr-lf Characters"
CRLF isNil ifTrue:[
- CRLF := String
- with:Character return
- with:Character linefeed
+ CRLF := String
+ with:Character return
+ with:Character linefeed
].
^ CRLF
!
@@ -479,7 +479,7 @@
"return a string consisting of the lf Character"
LF isNil ifTrue:[
- LF := String with:Character linefeed
+ LF := String with:Character linefeed
].
^ LF
! !
@@ -494,13 +494,13 @@
"take care of subclasses ..."
((self == String) or:[self == Symbol]) ifTrue:[
- len := stream nextNumber:4.
- s := String uninitializedNew:len.
- stream nextBytes:len into:s startingAt:1.
- self == Symbol ifTrue:[
- ^ s asSymbol
- ].
- ^ s
+ len := stream nextNumber:4.
+ s := String uninitializedNew:len.
+ stream nextBytes:len into:s startingAt:1.
+ self == Symbol ifTrue:[
+ ^ s asSymbol
+ ].
+ ^ s
].
^ super binaryDefinitionFrom:stream manager:manager
@@ -540,16 +540,16 @@
REGISTER OBJ slf, cls;
if (__isSmallInteger(index)) {
- slf = self;
- cls = __qClass(slf);
- indx = __intVal(index) - 1;
- if (cls != String) {
- if (indx < 0) goto badIndex;
- indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
- }
- if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
- RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
- }
+ slf = self;
+ cls = __qClass(slf);
+ indx = __intVal(index) - 1;
+ if (cls != String) {
+ if (indx < 0) goto badIndex;
+ indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ }
+ if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
+ RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
+ }
}
badIndex: ;
%}.
@@ -571,17 +571,17 @@
slf = self;
if (__isString(slf)) {
- if (__isCharacter(aCharacter)) {
- value = __intVal(_characterVal(aCharacter));
- if (((unsigned)value <= 0xFF)
- && __isSmallInteger(index)) {
- indx = __intVal(index) - 1;
- if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
- __stringVal(slf)[indx] = value;
- RETURN ( aCharacter );
- }
- }
- }
+ if (__isCharacter(aCharacter)) {
+ value = __intVal(_characterVal(aCharacter));
+ if (((unsigned)value <= 0xFF)
+ && __isSmallInteger(index)) {
+ indx = __intVal(index) - 1;
+ if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
+ __stringVal(slf)[indx] = value;
+ RETURN ( aCharacter );
+ }
+ }
+ }
}
%}.
^ self basicAt:index put:aCharacter
@@ -597,24 +597,24 @@
REGISTER OBJ slf, cls;
if (__isSmallInteger(index)) {
- slf = self;
- cls = __qClass(slf);
- indx = __intVal(index) - 1;
- if (cls != String) {
- if (indx < 0) goto badIndex;
- indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
- }
- if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
- RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
- }
+ slf = self;
+ cls = __qClass(slf);
+ indx = __intVal(index) - 1;
+ if (cls != String) {
+ if (indx < 0) goto badIndex;
+ indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ }
+ if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
+ RETURN ( __MKCHARACTER(__stringVal(slf)[indx] & 0xFF) );
+ }
}
badIndex: ;
%}.
index isInteger ifFalse:[
- ^ self indexNotInteger:index
+ ^ self indexNotInteger:index
].
index == super basicSize ifTrue:[
- ^ self subscriptBoundsError:index
+ ^ self subscriptBoundsError:index
].
^ Character value:(super basicAt:index)
!
@@ -633,53 +633,53 @@
slf = self;
if (__isCharacter(aCharacter)) {
- value = __intVal(_characterVal(aCharacter));
- if (((unsigned)value <= 0xFF)
- && __isSmallInteger(index)) {
- cls = __qClass(slf);
- indx = __intVal(index) - 1;
- if (cls != String) {
- if (indx < 0) goto badIndex;
- indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
- }
- if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
- __stringVal(slf)[indx] = value;
- RETURN ( aCharacter );
- }
- }
+ value = __intVal(_characterVal(aCharacter));
+ if (((unsigned)value <= 0xFF)
+ && __isSmallInteger(index)) {
+ cls = __qClass(slf);
+ indx = __intVal(index) - 1;
+ if (cls != String) {
+ if (indx < 0) goto badIndex;
+ indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ }
+ if ((unsigned)indx < (unsigned)(__stringSize(slf))) {
+ __stringVal(slf)[indx] = value;
+ RETURN ( aCharacter );
+ }
+ }
}
badIndex: ;
%}.
(aCharacter isMemberOf:Character) ifFalse:[
- "
- tried to store something which is not a character
- "
- ^ self elementNotCharacter
+ "
+ tried to store something which is not a character
+ "
+ ^ self elementNotCharacter
].
(aCharacter codePoint between:1 and:255) ifFalse:[
- "
- tried to store a multibyte character
- "
- ^ self elementBoundsError:aCharacter
+ "
+ tried to store a multibyte character
+ "
+ ^ self elementBoundsError:aCharacter
].
"
invalid index
"
index isInteger ifFalse:[
- ^ self indexNotInteger:index
+ ^ self indexNotInteger:index
].
index == super basicSize ifTrue:[
- ^ self subscriptBoundsError:index
+ ^ self subscriptBoundsError:index
].
super basicAt:index put:aCharacter codePoint.
- ^ aCharacter
+ ^ aCharacter
! !
!String methodsFor:'binary storage'!
storeBinaryDefinitionOn:stream manager:manager
"append a binary representation of the receiver onto stream.
- Redefined since short Strings can be stored with a special type code
+ Redefined since short Strings can be stored with a special type code
in a more compact way.
This is an internal interface for the binary storage mechanism."
@@ -695,7 +695,7 @@
"/ can use a more compact representation;
"/ but not for subclasses ...
- ((myClass == String)
+ ((myClass == String)
and:[myBasicSize <= 255]) ifTrue:[
"/ special encoding: <codeForString> <len> <bytes> ...
stream nextPut:(manager codeForString); nextPut:myBasicSize.
@@ -725,25 +725,25 @@
OBJ cls;
if (__isCharacter(aCharacter)) {
- cp = __stringVal(self);
- if ((cls = __qClass(self)) != String)
- cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-
- byteValue = __intVal(__characterVal(aCharacter));
- if (byteValue <= 0xFF) {
+ cp = __stringVal(self);
+ if ((cls = __qClass(self)) != String)
+ cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+
+ byteValue = __intVal(__characterVal(aCharacter));
+ if (byteValue <= 0xFF) {
#ifdef FAST_MEMCHR
- cp = (unsigned char *) memchr(cp, byteValue, __stringSize(self));
- if (cp) {
- RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) );
- }
+ cp = (unsigned char *) memchr(cp, byteValue, __stringSize(self));
+ if (cp) {
+ RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) );
+ }
#else
- last = __stringSize(self);
- for (index=1; index <= last; index++) {
- if (*cp++ == byteValue) { RETURN ( __MKSMALLINT(index) ); }
- }
+ last = __stringSize(self);
+ for (index=1; index <= last; index++) {
+ if (*cp++ == byteValue) { RETURN ( __MKSMALLINT(index) ); }
+ }
#endif
- }
- RETURN ( __MKSMALLINT(0));
+ }
+ RETURN ( __MKSMALLINT(0));
}
/* with identity compares, only characters can be in myself */
RETURN ( __MKSMALLINT(0));
@@ -751,8 +751,8 @@
^ self primitiveFailed
"
- 'hello world' identityIndexOf:(Character space)
- 'hello world' identityIndexOf:$d
+ 'hello world' identityIndexOf:(Character space)
+ 'hello world' identityIndexOf:$d
'hello world' identityIndexOf:1
#[0 0 1 0 0] asString identityIndexOf:(Character value:1)
#[0 0 1 0 0] asString identityIndexOf:(Character value:0)
@@ -773,34 +773,34 @@
OBJ cls;
if (__isCharacter(aCharacter)) {
- byteValue = __intVal(__characterVal(aCharacter));
- if (byteValue <= 0xFF) {
- cp = __stringVal(self);
- if ((cls = __qClass(self)) != String)
- cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ byteValue = __intVal(__characterVal(aCharacter));
+ if (byteValue <= 0xFF) {
+ cp = __stringVal(self);
+ if ((cls = __qClass(self)) != String)
+ cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
#ifdef FAST_MEMCHR
- if (memchr(cp, byteValue, __stringSize(self)) != NULL) {
- RETURN ( true );
- }
+ if (memchr(cp, byteValue, __stringSize(self)) != NULL) {
+ RETURN ( true );
+ }
#else
- for (last=cp+__stringSize(self); cp < last; cp++) {
- if (*cp == byteValue) {
- RETURN ( true );
- }
- }
+ for (last=cp+__stringSize(self); cp < last; cp++) {
+ if (*cp == byteValue) {
+ RETURN ( true );
+ }
+ }
#endif
- }
- RETURN (false);
+ }
+ RETURN (false);
}
%}.
^ super includes:aCharacter
"
'hello world' includes:$d
- 'hello world' includes:$o
- 'hello world' includes:$x
- 'hello world' includes:1
- 'hello world' asTwoByteString includes:$o
+ 'hello world' includes:$o
+ 'hello world' includes:$x
+ 'hello world' includes:1
+ 'hello world' asTwoByteString includes:$o
#[0 0 1 0 0] asString includes:(Character value:1)
#[0 0 1 0 0] asString includes:(Character value:0)
#[1 2 3 4 5] asString includes:(Character value:0)
@@ -819,54 +819,54 @@
OBJ cls;
if (__isString(aCollection)) {
- matchP = __stringVal(aCollection);
- cp = __stringVal(self);
- if ((cls = __qClass(self)) != String)
- cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-
- switch (__stringSize(aCollection)) {
- case 3:
- /* three character search */
- if (strchr(cp, matchP[2])) {
- RETURN ( true );
- }
- /* fall into */
- case 2:
- /* two character search */
- if (strchr(cp, matchP[1])) {
- RETURN ( true );
- }
- /* fall into */
- case 1:
- /* single character search */
- if (strchr(cp, matchP[0])) {
- RETURN ( true );
- }
- /* fall into */
- case 0:
- RETURN ( false );
- }
- while (*cp) {
- if (strchr(matchP, *cp)) {
- RETURN ( true );
- }
- cp++;
- }
- RETURN ( false );
+ matchP = __stringVal(aCollection);
+ cp = __stringVal(self);
+ if ((cls = __qClass(self)) != String)
+ cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+
+ switch (__stringSize(aCollection)) {
+ case 3:
+ /* three character search */
+ if (strchr(cp, matchP[2])) {
+ RETURN ( true );
+ }
+ /* fall into */
+ case 2:
+ /* two character search */
+ if (strchr(cp, matchP[1])) {
+ RETURN ( true );
+ }
+ /* fall into */
+ case 1:
+ /* single character search */
+ if (strchr(cp, matchP[0])) {
+ RETURN ( true );
+ }
+ /* fall into */
+ case 0:
+ RETURN ( false );
+ }
+ while (*cp) {
+ if (strchr(matchP, *cp)) {
+ RETURN ( true );
+ }
+ cp++;
+ }
+ RETURN ( false );
}
%}.
^ super includesAny:aCollection
"
- 'hello world' includesAny:'abcd'
- 'hello world' includesAny:'xyz'
- 'hello world' includesAny:'xz'
- 'hello world' includesAny:'od'
- 'hello world' includesAny:'xd'
- 'hello world' includesAny:'dx'
- 'hello world' includesAny:(Array with:$a with:$b with:$d)
- 'hello world' includesAny:(Array with:$x with:$y)
- 'hello world' includesAny:(Array with:1 with:2)
+ 'hello world' includesAny:'abcd'
+ 'hello world' includesAny:'xyz'
+ 'hello world' includesAny:'xz'
+ 'hello world' includesAny:'od'
+ 'hello world' includesAny:'xd'
+ 'hello world' includesAny:'dx'
+ 'hello world' includesAny:(Array with:$a with:$b with:$d)
+ 'hello world' includesAny:(Array with:$x with:$y)
+ 'hello world' includesAny:(Array with:1 with:2)
"
!
@@ -885,34 +885,34 @@
OBJ cls;
if (__isCharacter(aCharacter)) {
- cp = __stringVal(self);
- if ((cls = __qClass(self)) != String)
- cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-
- byteValue = __intVal(__characterVal(aCharacter));
- if (byteValue <= 0xFF) {
+ cp = __stringVal(self);
+ if ((cls = __qClass(self)) != String)
+ cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+
+ byteValue = __intVal(__characterVal(aCharacter));
+ if (byteValue <= 0xFF) {
#ifdef FAST_MEMCHR
- cp = (unsigned char *) memchr(cp, byteValue, __stringSize(self));
- if (cp) {
- RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) );
- }
+ cp = (unsigned char *) memchr(cp, byteValue, __stringSize(self));
+ if (cp) {
+ RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) );
+ }
#else
- last = __stringSize(self);
- for (index=1; index <= last; index++) {
- if (*cp++ == byteValue) { RETURN ( __MKSMALLINT(index) ); }
- }
+ last = __stringSize(self);
+ for (index=1; index <= last; index++) {
+ if (*cp++ == byteValue) { RETURN ( __MKSMALLINT(index) ); }
+ }
#endif
- }
- RETURN ( __MKSMALLINT(0));
+ }
+ RETURN ( __MKSMALLINT(0));
}
%}.
^ super indexOf:aCharacter
"
- 'hello world' indexOf:(Character space)
- 'hello world' indexOf:$A
- 'hello world' indexOf:$d
+ 'hello world' indexOf:(Character space)
+ 'hello world' indexOf:$A
+ 'hello world' indexOf:$d
#[0 0 1 0 0] asString indexOf:(Character value:1)
#[0 0 1 0 0] asString indexOf:(Character value:0)
"
@@ -931,41 +931,41 @@
OBJ cls;
if (__isSmallInteger(start)) {
- if (__isCharacter(aCharacter)) {
- byteValue = __intVal(_characterVal(aCharacter));
- if (byteValue <= 0xFF) {
- index = __intVal(start);
- if (index <= 0)
- index = 1;
- if ((cls = __qClass(self)) != String)
- index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
- len = __stringSize(self);
- if (index <= len) {
- cp = __stringVal(self) + index - 1;
+ if (__isCharacter(aCharacter)) {
+ byteValue = __intVal(_characterVal(aCharacter));
+ if (byteValue <= 0xFF) {
+ index = __intVal(start);
+ if (index <= 0)
+ index = 1;
+ if ((cls = __qClass(self)) != String)
+ index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ len = __stringSize(self);
+ if (index <= len) {
+ cp = __stringVal(self) + index - 1;
#ifdef FAST_MEMCHR
- cp = (unsigned char *) memchr(cp, byteValue, len+1-index);
- if (cp) {
- RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) );
- }
+ cp = (unsigned char *) memchr(cp, byteValue, len+1-index);
+ if (cp) {
+ RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) );
+ }
#else
- for (; index <= len; index++) {
- if (*cp++ == byteValue) { RETURN ( __MKSMALLINT(index) ); }
- }
+ for (; index <= len; index++) {
+ if (*cp++ == byteValue) { RETURN ( __MKSMALLINT(index) ); }
+ }
#endif
- }
- }
- }
- RETURN ( __MKSMALLINT(0) );
+ }
+ }
+ }
+ RETURN ( __MKSMALLINT(0) );
}
%}.
^ super indexOf:aCharacter startingAt:start
"
- 'hello world' indexOf:$0 startingAt:1
- 'hello world' indexOf:$l startingAt:1
- 'hello world' indexOf:$l startingAt:5
- 'hello world' indexOf:$d startingAt:5
+ 'hello world' indexOf:$0 startingAt:1
+ 'hello world' indexOf:$l startingAt:1
+ 'hello world' indexOf:$l startingAt:5
+ 'hello world' indexOf:$d startingAt:5
#[0 0 1 0 0] asString indexOf:(Character value:1) startingAt:1
#[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3
"
@@ -988,75 +988,75 @@
if (__isSmallInteger(start)
&& __isString(aCollectionOfCharacters)) {
- matchP = __stringVal(aCollectionOfCharacters);
- index = __intVal(start);
- if (index <= 0)
- index = 1;
- if ((cls = __qClass(self)) != String)
- index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
- len = __stringSize(self);
- if (index <= len) {
- cp = __stringVal(self) + index - 1;
-
- if (matchP[0] == 0) {
- /* matchSet is empty */
- RETURN ( __MKSMALLINT(0) );
- }
-
- if (matchP[1] == 0) {
- /* only a single character match */
- unsigned char m = matchP[0];
+ matchP = __stringVal(aCollectionOfCharacters);
+ index = __intVal(start);
+ if (index <= 0)
+ index = 1;
+ if ((cls = __qClass(self)) != String)
+ index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ len = __stringSize(self);
+ if (index <= len) {
+ cp = __stringVal(self) + index - 1;
+
+ if (matchP[0] == 0) {
+ /* matchSet is empty */
+ RETURN ( __MKSMALLINT(0) );
+ }
+
+ if (matchP[1] == 0) {
+ /* only a single character match */
+ unsigned char m = matchP[0];
#ifdef FAST_MEMCHR
- cp = (unsigned char *) memchr(cp, m, len-index+1);
- if (cp) {
- RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) );
- }
+ cp = (unsigned char *) memchr(cp, m, len-index+1);
+ if (cp) {
+ RETURN ( __MKSMALLINT(cp - __stringVal(self) + 1) );
+ }
#else
- while (c = *cp++) {
- if (c == m) {
- RETURN ( __MKSMALLINT(index) );
- }
- index++;
- }
+ while (c = *cp++) {
+ if (c == m) {
+ RETURN ( __MKSMALLINT(index) );
+ }
+ index++;
+ }
#endif
- RETURN ( __MKSMALLINT(0) );
- }
-
- if (matchP[2] == 0) {
- /* two character matches */
- unsigned char m1 = matchP[0];
- unsigned char m2 = matchP[1];
-
- while (c = *cp++) {
- if ((c == m1) || (c == m2)) {
- RETURN ( __MKSMALLINT(index) );
- }
- index++;
- }
- RETURN ( __MKSMALLINT(0) );
- }
-
- min = max = matchP[0];
-
- for (ccp = matchP+1; *ccp ; ccp++) {
- unsigned char c = *ccp;
- if (c < min) min = c;
- else if (c > max) max = c;
- }
-
- while (c = *cp++) {
- if ((c >= min) && (c <= max)) {
- for (ccp = matchP; *ccp ; ccp++) {
- if (*ccp == c) {
- RETURN ( __MKSMALLINT(index) );
- }
- }
- }
- index++;
- }
- }
- RETURN ( __MKSMALLINT(0) );
+ RETURN ( __MKSMALLINT(0) );
+ }
+
+ if (matchP[2] == 0) {
+ /* two character matches */
+ unsigned char m1 = matchP[0];
+ unsigned char m2 = matchP[1];
+
+ while (c = *cp++) {
+ if ((c == m1) || (c == m2)) {
+ RETURN ( __MKSMALLINT(index) );
+ }
+ index++;
+ }
+ RETURN ( __MKSMALLINT(0) );
+ }
+
+ min = max = matchP[0];
+
+ for (ccp = matchP+1; *ccp ; ccp++) {
+ unsigned char c = *ccp;
+ if (c < min) min = c;
+ else if (c > max) max = c;
+ }
+
+ while (c = *cp++) {
+ if ((c >= min) && (c <= max)) {
+ for (ccp = matchP; *ccp ; ccp++) {
+ if (*ccp == c) {
+ RETURN ( __MKSMALLINT(index) );
+ }
+ }
+ }
+ index++;
+ }
+ }
+ RETURN ( __MKSMALLINT(0) );
}
%}.
"/
@@ -1065,12 +1065,12 @@
^ super indexOfAny:aCollectionOfCharacters startingAt:start
"
- 'hello world' indexOfAny:'eoa' startingAt:1
- 'hello world' indexOfAny:'eoa' startingAt:6
- 'hello world' indexOfAny:'AOE' startingAt:1
- 'hello world' indexOfAny:'o' startingAt:6
- 'hello world' indexOfAny:'o' startingAt:6
- 'hello world§' indexOfAny:'#§$' startingAt:6
+ 'hello world' indexOfAny:'eoa' startingAt:1
+ 'hello world' indexOfAny:'eoa' startingAt:6
+ 'hello world' indexOfAny:'AOE' startingAt:1
+ 'hello world' indexOfAny:'o' startingAt:6
+ 'hello world' indexOfAny:'o' startingAt:6
+ 'hello world§' indexOfAny:'#§$' startingAt:6
"
!
@@ -1110,10 +1110,10 @@
^ super indexOfControlCharacterStartingAt:start
"
- 'hello world' indexOfControlCharacterStartingAt:1
- 'hello world\foo' withCRs indexOfControlCharacterStartingAt:1
- '1\' withCRs indexOfControlCharacterStartingAt:1
- '1\' withCRs indexOfControlCharacterStartingAt:2
+ 'hello world' indexOfControlCharacterStartingAt:1
+ 'hello world\foo' withCRs indexOfControlCharacterStartingAt:1
+ '1\' withCRs indexOfControlCharacterStartingAt:1
+ '1\' withCRs indexOfControlCharacterStartingAt:2
"
!
@@ -1129,31 +1129,31 @@
index = __intVal(start);
if (index <= 0) {
- index = 1;
+ index = 1;
}
if ((cls = __qClass(self)) != String)
- index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
len = __stringSize(self);
if (index > len) {
- RETURN ( __MKSMALLINT(0) );
+ RETURN ( __MKSMALLINT(0) );
}
cp = __stringVal(self) + index - 1;
while (c = *cp++) {
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */
- if (c > ' ')
+ if (c > ' ')
#endif
- if ((c != ' ') && (c != '\t') && (c != '\n')
- && (c != '\r') && (c != '\f')) {
- RETURN ( __MKSMALLINT(cp - __stringVal(self)) );
- }
+ if ((c != ' ') && (c != '\t') && (c != '\n')
+ && (c != '\r') && (c != '\f')) {
+ RETURN ( __MKSMALLINT(cp - __stringVal(self)) );
+ }
}
RETURN ( __MKSMALLINT(0) );
%}.
^ super indexOfNonSeparatorStartingAt:start
"
- 'hello world' indexOfNonWhiteSpaceStartingAt:3
- 'hello world' indexOfNonWhiteSpaceStartingAt:7
+ 'hello world' indexOfNonWhiteSpaceStartingAt:3
+ 'hello world' indexOfNonWhiteSpaceStartingAt:7
"
!
@@ -1169,31 +1169,31 @@
index = __intVal(start);
if (index <= 0) {
- index = 1;
+ index = 1;
}
if ((cls = __qClass(self)) != String)
- index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ index += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
len = __stringSize(self);
if (index > len) {
- RETURN ( __MKSMALLINT(0) );
+ RETURN ( __MKSMALLINT(0) );
}
cp = __stringVal(self) + index - 1;
while (c = *cp++) {
#ifndef NON_ASCII /* i.e. EBCDIC ;-) */
- if (c <= ' ')
+ if (c <= ' ')
#endif
- if ((c == ' ') || (c == '\t') || (c == '\n')
- || (c == '\r') || (c == '\f')) {
- RETURN ( __MKSMALLINT(cp - __stringVal(self)) );
- }
+ if ((c == ' ') || (c == '\t') || (c == '\n')
+ || (c == '\r') || (c == '\f')) {
+ RETURN ( __MKSMALLINT(cp - __stringVal(self)) );
+ }
}
RETURN ( __MKSMALLINT(0) );
%}.
^ super indexOfSeparatorStartingAt:start
"
- 'hello world' indexOfSeparatorStartingAt:3
- 'hello world' indexOfSeparatorStartingAt:7
+ 'hello world' indexOfSeparatorStartingAt:3
+ 'hello world' indexOfSeparatorStartingAt:7
"
!
@@ -1209,22 +1209,22 @@
OBJ cls;
if (__isCharacter(aCharacter)) {
- limit = __stringSize(self);
- count = 0;
- byteValue = __intVal(_characterVal(aCharacter));
- if (byteValue <= 0xFF) {
- cp = __stringVal(self);
- if ((cls = __qClass(self)) != String) {
- int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
- limit -= n;
- cp += n;
- }
- while (limit > 0) {
- limit--;
- if (*cp++ == byteValue) count++;
- }
- }
- RETURN ( __MKSMALLINT(count) );
+ limit = __stringSize(self);
+ count = 0;
+ byteValue = __intVal(_characterVal(aCharacter));
+ if (byteValue <= 0xFF) {
+ cp = __stringVal(self);
+ if ((cls = __qClass(self)) != String) {
+ int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ limit -= n;
+ cp += n;
+ }
+ while (limit > 0) {
+ limit--;
+ if (*cp++ == byteValue) count++;
+ }
+ }
+ RETURN ( __MKSMALLINT(count) );
}
%}.
^ super occurrencesOf:aCharacter
@@ -1232,9 +1232,9 @@
"
'hello world' occurrencesOf:$a
'hello world' occurrencesOf:$w
- 'hello world' occurrencesOf:$l
- 'hello world' occurrencesOf:$x
- 'hello world' occurrencesOf:1
+ 'hello world' occurrencesOf:$l
+ 'hello world' occurrencesOf:$x
+ 'hello world' occurrencesOf:1
"
! !
@@ -1245,7 +1245,7 @@
receiver is greater than the argument. Otherwise return false.
No national variants are honored; use after: for this.
In contrast to ST-80, case differences are NOT ignored, thus
- 'foo' < 'Foo' will return false.
+ 'foo' < 'Foo' will return false.
This may change."
%{ /* NOCONTEXT */
@@ -1257,47 +1257,47 @@
OBJ myCls;
if (__isNonNilObject(s)) {
- cls = __qClass(s);
- myCls = __qClass(self);
-
- if ((cls == String) || (cls == Symbol) || (cls == myCls)) {
- cp2 = __stringVal(s);
- len2 = __stringSize(s);
- /*
- * care for instances of subclasses ...
- */
- if (cls != String) {
- int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-
- cp2 += n;
- len2 -= n;
- }
-
- cp1 = __stringVal(self);
- len1 = __stringSize(self);
- /*
- * care for instances of subclasses ...
- */
- if (myCls != String) {
- int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars));
-
- cp1 += n;
- len1 -= n;
- }
-
- if (len1 <= len2)
- cmp = strncmp(cp1, cp2, len1);
- else
- cmp = strncmp(cp1, cp2, len2);
-
- if (cmp < 0) {
- RETURN ( true );
- }
- if ((cmp == 0) && (len1 < len2)) {
- RETURN ( true );
- }
- RETURN ( false );
- }
+ cls = __qClass(s);
+ myCls = __qClass(self);
+
+ if ((cls == String) || (cls == Symbol) || (cls == myCls)) {
+ cp2 = __stringVal(s);
+ len2 = __stringSize(s);
+ /*
+ * care for instances of subclasses ...
+ */
+ if (cls != String) {
+ int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+
+ cp2 += n;
+ len2 -= n;
+ }
+
+ cp1 = __stringVal(self);
+ len1 = __stringSize(self);
+ /*
+ * care for instances of subclasses ...
+ */
+ if (myCls != String) {
+ int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars));
+
+ cp1 += n;
+ len1 -= n;
+ }
+
+ if (len1 <= len2)
+ cmp = strncmp(cp1, cp2, len1);
+ else
+ cmp = strncmp(cp1, cp2, len2);
+
+ if (cmp < 0) {
+ RETURN ( true );
+ }
+ if ((cmp == 0) && (len1 < len2)) {
+ RETURN ( true );
+ }
+ RETURN ( false );
+ }
}
%}.
^ super < aString
@@ -1319,95 +1319,95 @@
INT addrDelta;
if (s == self) {
- RETURN ( true );
+ RETURN ( true );
}
if (! __isNonNilObject(s)) {
- RETURN ( false );
+ RETURN ( false );
}
cls = __qClass(s);
myCls = __qClass(self);
if ((cls == myCls) || (cls == String) || (cls == Symbol)) {
- cp2 = __stringVal(s);
- l2 = __stringSize(s);
- /*
- * care for instances of subclasses ...
- */
- if (cls != String) {
- int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-
- cp2 += n;
- l2 -= n;
- }
-
- cp1 = __stringVal(self);
- l1 = __stringSize(self);
- /*
- * care for instances of subclasses ...
- */
- if (myCls != String) {
- int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars));
-
- cp1 += n;
- l1 -= n;
- }
-
- if (l1 != l2) {
- RETURN ( false );
- }
+ cp2 = __stringVal(s);
+ l2 = __stringSize(s);
+ /*
+ * care for instances of subclasses ...
+ */
+ if (cls != String) {
+ int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+
+ cp2 += n;
+ l2 -= n;
+ }
+
+ cp1 = __stringVal(self);
+ l1 = __stringSize(self);
+ /*
+ * care for instances of subclasses ...
+ */
+ if (myCls != String) {
+ int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars));
+
+ cp1 += n;
+ l1 -= n;
+ }
+
+ if (l1 != l2) {
+ RETURN ( false );
+ }
#ifdef FAST_MEMCMP
- RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false );
+ RETURN ( (memcmp(cp1, cp2, l1) == 0) ? true : false );
#else
- addrDelta = cp2 - cp1;
+ addrDelta = cp2 - cp1;
# ifdef UNROLL_LOOPS
- while (l1 >= (sizeof(unsigned INT)*4)) {
- if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
- RETURN (false);
- }
- if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
- RETURN (false);
- }
- if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
- RETURN (false);
- }
- if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
- RETURN (false);
- }
- l1 -= (sizeof(unsigned INT) * 4);
- cp1 += (sizeof(unsigned INT) * 4);
- }
+ while (l1 >= (sizeof(unsigned INT)*4)) {
+ if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
+ RETURN (false);
+ }
+ if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
+ RETURN (false);
+ }
+ if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
+ RETURN (false);
+ }
+ if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
+ RETURN (false);
+ }
+ l1 -= (sizeof(unsigned INT) * 4);
+ cp1 += (sizeof(unsigned INT) * 4);
+ }
# endif /* UNROLL_LOOPS */
- while (l1 >= sizeof(unsigned INT)) {
- if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
- RETURN (false);
- }
- l1 -= sizeof(unsigned INT);
- cp1 += sizeof(unsigned INT);
- }
- if (l1 >= sizeof(unsigned short)) {
- if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
- RETURN (false);
- }
- l1 -= sizeof(unsigned short);
- cp1 += sizeof(unsigned short);
- }
- while (l1) {
- if (*cp1 != *(cp1+addrDelta)) {
- RETURN (false);
- }
- l1--;
- cp1++;
- }
-
- RETURN (true);
+ while (l1 >= sizeof(unsigned INT)) {
+ if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
+ RETURN (false);
+ }
+ l1 -= sizeof(unsigned INT);
+ cp1 += sizeof(unsigned INT);
+ }
+ if (l1 >= sizeof(unsigned short)) {
+ if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
+ RETURN (false);
+ }
+ l1 -= sizeof(unsigned short);
+ cp1 += sizeof(unsigned short);
+ }
+ while (l1) {
+ if (*cp1 != *(cp1+addrDelta)) {
+ RETURN (false);
+ }
+ l1--;
+ cp1++;
+ }
+
+ RETURN (true);
#endif
}
%}.
^ super = aString
"
- 'foo' = 'Foo'
+ 'foo' = 'Foo'
'foo' sameAs: 'Foo'
#[0 0 1 0 0] asString = #[0 0 1 0 0] asString
"
@@ -1415,12 +1415,12 @@
|tEmpty tCmp|
tEmpty := Time millisecondsToRun:[
- 1000000 timesRepeat:[]
+ 1000000 timesRepeat:[]
].
tCmp := Time millisecondsToRun:[
- 1000000 timesRepeat:[ '1234567890' = '1234567890' ]
+ 1000000 timesRepeat:[ '1234567890' = '1234567890' ]
].
- tCmp - tEmpty
+ tCmp - tEmpty
"
!
@@ -1429,7 +1429,7 @@
receiver is greater than the argument. Otherwise return false.
No national variants are honored; use after: for this.
In contrast to ST-80, case differences are NOT ignored, thus
- 'foo' > 'Foo' will return true.
+ 'foo' > 'Foo' will return true.
This may change."
%{ /* NOCONTEXT */
@@ -1489,7 +1489,7 @@
after:aString
"Compare the receiver with the argument and return true if the
- receiver should come after the argument in a sorted list.
+ receiver should come after the argument in a sorted list.
Otherwise return false.
The comparison is language specific, depending on the value of
LC_COLLATE, which is initialized from the environment.
@@ -1504,7 +1504,7 @@
compareCollatingWith:aString
"Compare the receiver with the argument and return 1 if the receiver is
- greater, 0 if equal and -1 if less than the argument in a sorted list.
+ greater, 0 if equal and -1 if less than the argument in a sorted list.
The comparison is language specific, depending on the value of
LC_COLLATE, which is in the shell environment."
@@ -1583,85 +1583,85 @@
INT addrDelta;
if (s == self) {
- RETURN ( false );
+ RETURN ( false );
}
if (! __isNonNilObject(s)) {
- RETURN ( true );
+ RETURN ( true );
}
cls = __qClass(s);
myCls = __qClass(self);
if ((cls == String) || (cls == Symbol) || (cls == myCls)) {
- cp1 = __stringVal(self);
- l1 = __stringSize(self);
- /*
- * care for instances of subclasses ...
- */
- if (myCls != String) {
- int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars));
-
- cp1 += n;
- l1 -= n;
- }
-
- cp2 = __stringVal(s);
- l2 = __stringSize(s);
- /*
- * care for instances of subclasses ...
- */
- if (cls != String) {
- int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-
- cp2 += n;
- l2 -= n;
- }
-
- if (l1 != l2) {
- RETURN ( true );
- }
-
- addrDelta = cp2 - cp1;
+ cp1 = __stringVal(self);
+ l1 = __stringSize(self);
+ /*
+ * care for instances of subclasses ...
+ */
+ if (myCls != String) {
+ int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(myCls)->c_ninstvars));
+
+ cp1 += n;
+ l1 -= n;
+ }
+
+ cp2 = __stringVal(s);
+ l2 = __stringSize(s);
+ /*
+ * care for instances of subclasses ...
+ */
+ if (cls != String) {
+ int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+
+ cp2 += n;
+ l2 -= n;
+ }
+
+ if (l1 != l2) {
+ RETURN ( true );
+ }
+
+ addrDelta = cp2 - cp1;
# ifdef UNROLL_LOOPS
- while (l1 >= (sizeof(unsigned INT)*4)) {
- if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
- RETURN (true);
- }
- if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
- RETURN (true);
- }
- if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
- RETURN (true);
- }
- if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
- RETURN (true);
- }
- l1 -= (sizeof(unsigned INT) * 4);
- cp1 += (sizeof(unsigned INT) * 4);
- }
+ while (l1 >= (sizeof(unsigned INT)*4)) {
+ if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
+ RETURN (true);
+ }
+ if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
+ RETURN (true);
+ }
+ if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
+ RETURN (true);
+ }
+ if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
+ RETURN (true);
+ }
+ l1 -= (sizeof(unsigned INT) * 4);
+ cp1 += (sizeof(unsigned INT) * 4);
+ }
# endif /* UNROLL_LOOPS */
- while (l1 >= sizeof(unsigned INT)) {
- if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
- RETURN (true);
- }
- l1 -= sizeof(unsigned INT);
- cp1 += sizeof(unsigned INT);
- }
- if (l1 >= sizeof(unsigned short)) {
- if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
- RETURN (true);
- }
- l1 -= sizeof(unsigned short);
- cp1 += sizeof(unsigned short);
- }
- while (l1) {
- if (*cp1 != *(cp1+addrDelta)) {
- RETURN (true);
- }
- l1--;
- cp1++;
- }
- RETURN (false);
+ while (l1 >= sizeof(unsigned INT)) {
+ if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
+ RETURN (true);
+ }
+ l1 -= sizeof(unsigned INT);
+ cp1 += sizeof(unsigned INT);
+ }
+ if (l1 >= sizeof(unsigned short)) {
+ if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
+ RETURN (true);
+ }
+ l1 -= sizeof(unsigned short);
+ cp1 += sizeof(unsigned short);
+ }
+ while (l1) {
+ if (*cp1 != *(cp1+addrDelta)) {
+ RETURN (true);
+ }
+ l1--;
+ cp1++;
+ }
+ RETURN (false);
}
%}.
^ super ~= aString
@@ -1724,17 +1724,17 @@
/* care for instances of a subclass with instVars */
cls = __qClass(self);
if (cls != String) {
- cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
}
newSymbol = __MKSYMBOL(cp, (OBJ *)0);
if (newSymbol) {
- RETURN ( newSymbol);
+ RETURN ( newSymbol);
}
%}.
^ ObjectMemory allocationFailureSignal raise.
"
- 'hello' asSymbol
+ 'hello' asSymbol
"
!
@@ -1742,7 +1742,7 @@
"if a symbol with the receivers characters is already known, return it.
Otherwise, return nil. This can be used to query for an existing
symbol and is the same as
- self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil]
+ self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil]
but slightly faster, since the symbol lookup operation is only
performed once."
@@ -1752,9 +1752,9 @@
cls = __qClass(self);
if (cls != String) {
- indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
} else {
- indx = 0;
+ indx = 0;
}
RETURN ( __SYMBOL_OR_NIL(__stringVal(self) + indx));
%}.
@@ -1795,91 +1795,91 @@
if ((__qClass(self) == String)
&& __isSmallInteger(numSpaces)) {
- n = __intVal(numSpaces);
-
- /*
- * for small strings (< 80), do it without a prescan ...
- * the buffer is large enough to even convert a
- * receiver consisting fully of tabs.
- */
- if (__stringSize(self) < 80) {
- idx = 1;
- for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) {
- if (c == '\t') {
- any = 1;
- while (idx % n) {
- idx++;
- *dstP++ = ' ';
- }
- idx++;
- *dstP++ = ' ';
- } else {
- *dstP++ = c;
- idx++;
- if (c == '\n') {
- idx = 1;
- }
- }
- }
- if (! any) RETURN(self);
- *dstP = '\0';
- RETURN (__MKSTRING_L(buffer, (dstP-buffer)));
- }
- /*
- * for large strings, we compute the new size, allocate a new string
- * and expand it.
- *
- * first, scan for size ...
- */
- idx = 1;
- for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) {
- if (c == '\t') {
- any = 1;
- while (idx % n) {
- idx++;
- sz++;
- }
- idx++; sz ++;
- } else {
- sz++; idx++;
- if (c == '\n') {
- idx = 1;
- }
- }
- }
- if (! any) RETURN(self);
-
- /*
- * get the string
- */
- sz = OHDR_SIZE + sz + 1;
- __qNew(newString, sz); /* OBJECT ALLOCATION */
- if (newString != nil) {
- __InstPtr(newString)->o_class = String;
- __qSTORE(newString, String);
-
- /*
- * expand
- */
- idx = 1;
- for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) {
- if (c == '\t') {
- while (idx % n) {
- idx++;
- *dstP++ = ' ';
- }
- idx++;
- *dstP++ = ' ';
- } else {
- *dstP++ = c; idx++;
- if (c == '\n') {
- idx = 1;
- }
- }
- }
- *dstP++ = '\0';
- RETURN (newString);
- }
+ n = __intVal(numSpaces);
+
+ /*
+ * for small strings (< 80), do it without a prescan ...
+ * the buffer is large enough to even convert a
+ * receiver consisting fully of tabs.
+ */
+ if (__stringSize(self) < 80) {
+ idx = 1;
+ for (srcP = __stringVal(self), dstP = buffer; (c = *srcP); srcP++) {
+ if (c == '\t') {
+ any = 1;
+ while (idx % n) {
+ idx++;
+ *dstP++ = ' ';
+ }
+ idx++;
+ *dstP++ = ' ';
+ } else {
+ *dstP++ = c;
+ idx++;
+ if (c == '\n') {
+ idx = 1;
+ }
+ }
+ }
+ if (! any) RETURN(self);
+ *dstP = '\0';
+ RETURN (__MKSTRING_L(buffer, (dstP-buffer)));
+ }
+ /*
+ * for large strings, we compute the new size, allocate a new string
+ * and expand it.
+ *
+ * first, scan for size ...
+ */
+ idx = 1;
+ for (srcP = __stringVal(self), sz = 0; (c = *srcP); srcP++) {
+ if (c == '\t') {
+ any = 1;
+ while (idx % n) {
+ idx++;
+ sz++;
+ }
+ idx++; sz ++;
+ } else {
+ sz++; idx++;
+ if (c == '\n') {
+ idx = 1;
+ }
+ }
+ }
+ if (! any) RETURN(self);
+
+ /*
+ * get the string
+ */
+ sz = OHDR_SIZE + sz + 1;
+ __qNew(newString, sz); /* OBJECT ALLOCATION */
+ if (newString != nil) {
+ __InstPtr(newString)->o_class = String;
+ __qSTORE(newString, String);
+
+ /*
+ * expand
+ */
+ idx = 1;
+ for (srcP = __stringVal(self), dstP = cp0 = __stringVal(newString); (c = *srcP); srcP++) {
+ if (c == '\t') {
+ while (idx % n) {
+ idx++;
+ *dstP++ = ' ';
+ }
+ idx++;
+ *dstP++ = ' ';
+ } else {
+ *dstP++ = c; idx++;
+ if (c == '\n') {
+ idx = 1;
+ }
+ }
+ }
+ *dstP++ = '\0';
+ RETURN (newString);
+ }
}
%}.
^ super withTabsExpanded:numSpaces
@@ -1899,84 +1899,84 @@
OBJ myClass, argClass, newString;
if (__isNonNilObject(s)) {
- myClass = __qClass(self);
- argClass = __qClass(s);
- /*
- * can do it here if both are Strings/Symbols:
- */
- if (((myClass == _string) || (myClass == Symbol))
- && ((argClass == _string) || (argClass == Symbol))) {
- l1 = __stringSize(self);
- l2 = __stringSize(s);
-
- sz = OHDR_SIZE + l1 + l2 + 1;
- __qNew(newString, sz); /* OBJECT ALLOCATION */
- if (newString != nil) {
- char *cp1, *cp2;
- REGISTER unsigned char *dstp;
-
- __InstPtr(newString)->o_class = String;
- __qSTORE(newString, String);
- dstp = __stringVal(newString);
- cp1 = (char *) __stringVal(self);
- cp2 = (char *) __stringVal(aString);
+ myClass = __qClass(self);
+ argClass = __qClass(s);
+ /*
+ * can do it here if both are Strings/Symbols:
+ */
+ if (((myClass == _string) || (myClass == Symbol))
+ && ((argClass == _string) || (argClass == Symbol))) {
+ l1 = __stringSize(self);
+ l2 = __stringSize(s);
+
+ sz = OHDR_SIZE + l1 + l2 + 1;
+ __qNew(newString, sz); /* OBJECT ALLOCATION */
+ if (newString != nil) {
+ char *cp1, *cp2;
+ REGISTER unsigned char *dstp;
+
+ __InstPtr(newString)->o_class = String;
+ __qSTORE(newString, String);
+ dstp = __stringVal(newString);
+ cp1 = (char *) __stringVal(self);
+ cp2 = (char *) __stringVal(aString);
#ifdef bcopy4
- /* knowing that allocation is 4-byte aligned and
- * size rounded up to next 4-byte, the first copy
- * can be done word-wise.
- * that speeds up size-10-string , size-10-string
- * by 10% on a P5/200.
- */
- {
- int nw = l1 >> 2;
-
- if (l1 & 3) nw++;
- bcopy4(cp1, dstp, nw);
- dstp += l1;
- }
+ /* knowing that allocation is 4-byte aligned and
+ * size rounded up to next 4-byte, the first copy
+ * can be done word-wise.
+ * that speeds up size-10-string , size-10-string
+ * by 10% on a P5/200.
+ */
+ {
+ int nw = l1 >> 2;
+
+ if (l1 & 3) nw++;
+ bcopy4(cp1, dstp, nw);
+ dstp += l1;
+ }
#else
# ifdef FAST_MEMCPY
- memcpy(dstp, cp1, l1);
- dstp += l1;
+ memcpy(dstp, cp1, l1);
+ dstp += l1;
# else
- while (l1 >= 4) {
- *(int *)dstp = *(int *)cp1;
- dstp += 4; cp1 += 4;
- l1 -= 4;
- }
- while (l1--) *dstp++ = *cp1++;
+ while (l1 >= 4) {
+ *(int *)dstp = *(int *)cp1;
+ dstp += 4; cp1 += 4;
+ l1 -= 4;
+ }
+ while (l1--) *dstp++ = *cp1++;
# endif
#endif
#ifdef bcopy4
- if (((INT)dstp & 3) == 0) {
- int nw = l2 >> 2;
-
- if (l2 & 3) nw++;
- bcopy4(cp2, dstp, nw);
- *(dstp + l2) = '\0';
- RETURN ( newString );
- }
+ if (((INT)dstp & 3) == 0) {
+ int nw = l2 >> 2;
+
+ if (l2 & 3) nw++;
+ bcopy4(cp2, dstp, nw);
+ *(dstp + l2) = '\0';
+ RETURN ( newString );
+ }
#endif
-
+
#ifdef FAST_MEMCPY
- memcpy(dstp, cp2, l2+1);
- dstp[l2] = '\0';
+ memcpy(dstp, cp2, l2+1);
+ dstp[l2] = '\0';
#else
- while (l2--) *dstp++ = *cp2++;
- *dstp = '\0';
+ while (l2--) *dstp++ = *cp2++;
+ *dstp = '\0';
#endif
- RETURN ( newString );
- }
- }
+ RETURN ( newString );
+ }
+ }
}
%}.
^ super , aString
"
'hello' , 'world'
- #[0 0 0 1] asString, #[0 0 0 2 0] asString
+ #[0 0 0 1] asString, #[0 0 0 2 0] asString
"
!
@@ -1997,31 +1997,31 @@
if ((__isString(self) || __isSymbol(self))
&& (__isString(string1) || __isSymbol(string1))
&& (__isString(string2) || __isSymbol(string2))) {
- len1 = __stringSize(self);
- len2 = __stringSize(string1);
- len3 = __stringSize(string2);
- sz = OHDR_SIZE + len1 + len2 + len3 + 1;
- __qNew(newString, sz); /* OBJECT ALLOCATION */
- if (newString != nil) {
- __InstPtr(newString)->o_class = String;
- __qSTORE(newString, String);
- dstp = __stringVal(newString);
+ len1 = __stringSize(self);
+ len2 = __stringSize(string1);
+ len3 = __stringSize(string2);
+ sz = OHDR_SIZE + len1 + len2 + len3 + 1;
+ __qNew(newString, sz); /* OBJECT ALLOCATION */
+ if (newString != nil) {
+ __InstPtr(newString)->o_class = String;
+ __qSTORE(newString, String);
+ dstp = __stringVal(newString);
#ifdef FAST_MEMCPY
- memcpy(dstp, __stringVal(self), len1);
- memcpy(dstp + len1, __stringVal(string1), len2);
- memcpy(dstp + len1 + len2, __stringVal(string2), len3+1);
- *(dstp + len1 + len2 + len3) = '\0';
+ memcpy(dstp, __stringVal(self), len1);
+ memcpy(dstp + len1, __stringVal(string1), len2);
+ memcpy(dstp + len1 + len2, __stringVal(string2), len3+1);
+ *(dstp + len1 + len2 + len3) = '\0';
#else
- srcp = __stringVal(self);
- while (len1--) *dstp++ = *srcp++;
- srcp = __stringVal(string1);
- while (len2--) *dstp++ = *srcp++;
- srcp = __stringVal(string2);
- while (len3--) *dstp++ = *srcp++;
- *dstp = '\0';
+ srcp = __stringVal(self);
+ while (len1--) *dstp++ = *srcp++;
+ srcp = __stringVal(string1);
+ while (len2--) *dstp++ = *srcp++;
+ srcp = __stringVal(string2);
+ while (len3--) *dstp++ = *srcp++;
+ *dstp = '\0';
#endif
- RETURN ( newString );
- }
+ RETURN ( newString );
+ }
}
%}.
^ super , string1 , string2
@@ -2045,35 +2045,35 @@
&& (__isString(string1) || __isSymbol(string1))
&& (__isString(string2) || __isSymbol(string2))
&& (__isString(string3) || __isSymbol(string3))) {
- len1 = __stringSize(self);
- len2 = __stringSize(string1);
- len3 = __stringSize(string2);
- len4 = __stringSize(string3);
- sz = OHDR_SIZE + len1 + len2 + len3 + len4 + 1;
- __qNew(newString, sz); /* OBJECT ALLOCATION */
- if (newString != nil) {
- __InstPtr(newString)->o_class = String;
- __qSTORE(newString, String);
- dstp = __stringVal(newString);
+ len1 = __stringSize(self);
+ len2 = __stringSize(string1);
+ len3 = __stringSize(string2);
+ len4 = __stringSize(string3);
+ sz = OHDR_SIZE + len1 + len2 + len3 + len4 + 1;
+ __qNew(newString, sz); /* OBJECT ALLOCATION */
+ if (newString != nil) {
+ __InstPtr(newString)->o_class = String;
+ __qSTORE(newString, String);
+ dstp = __stringVal(newString);
#ifdef FAST_MEMCPY
- memcpy(dstp, __stringVal(self), len1);
- memcpy(dstp + len1, __stringVal(string1), len2);
- memcpy(dstp + len1 + len2, __stringVal(string2), len3);
- memcpy(dstp + len1 + len2 + len3, __stringVal(string3), len4+1);
- *(dstp + len1 + len2 + len3 + len4) = '\0';
+ memcpy(dstp, __stringVal(self), len1);
+ memcpy(dstp + len1, __stringVal(string1), len2);
+ memcpy(dstp + len1 + len2, __stringVal(string2), len3);
+ memcpy(dstp + len1 + len2 + len3, __stringVal(string3), len4+1);
+ *(dstp + len1 + len2 + len3 + len4) = '\0';
#else
- srcp = __stringVal(self);
- while (len1--) *dstp++ = *srcp++;
- srcp = __stringVal(string1);
- while (len2--) *dstp++ = *srcp++;
- srcp = __stringVal(string2);
- while (len3--) *dstp++ = *srcp++;
- srcp = __stringVal(string3);
- while (len4--) *dstp++ = *srcp++;
- *dstp = '\0';
+ srcp = __stringVal(self);
+ while (len1--) *dstp++ = *srcp++;
+ srcp = __stringVal(string1);
+ while (len2--) *dstp++ = *srcp++;
+ srcp = __stringVal(string2);
+ while (len3--) *dstp++ = *srcp++;
+ srcp = __stringVal(string3);
+ while (len4--) *dstp++ = *srcp++;
+ *dstp = '\0';
#endif
- RETURN ( newString );
- }
+ RETURN ( newString );
+ }
}
%}.
^ super , string1 , string2 , string3
@@ -2083,14 +2083,14 @@
"return a copy of the receiver"
(self isMemberOf:String) ifTrue:[
- ^ self copyFrom:1
+ ^ self copyFrom:1
].
^ super copy
!
copyFrom:start
"return the substring from start, anInteger to the end.
- This method will always return a string, even if the receiver
+ This method will always return a string, even if the receiver
is a subclass-instance. This might change if there is a need.
- reimplemented here for speed"
@@ -2110,35 +2110,35 @@
#ifndef NO_PRIM_STRING
if (__isSmallInteger(start)
&& ((myClass==String) || (myClass==Symbol))) {
- len = __stringSize(self);
- index1 = __intVal(start);
- if (index1 > 0) {
- if (index1 <= len) {
- count = len - index1 + 1;
- sz = OHDR_SIZE + count + 1;
-
- __PROTECT_CONTEXT__
- __qNew(newString, sz); /* OBJECT ALLOCATION */
- __UNPROTECT_CONTEXT__
-
- if (newString != nil) {
- __InstPtr(newString)->o_class = String;
- __qSTORE(newString, String);
- dstp = __stringVal(newString);
+ len = __stringSize(self);
+ index1 = __intVal(start);
+ if (index1 > 0) {
+ if (index1 <= len) {
+ count = len - index1 + 1;
+ sz = OHDR_SIZE + count + 1;
+
+ __PROTECT_CONTEXT__
+ __qNew(newString, sz); /* OBJECT ALLOCATION */
+ __UNPROTECT_CONTEXT__
+
+ if (newString != nil) {
+ __InstPtr(newString)->o_class = String;
+ __qSTORE(newString, String);
+ dstp = __stringVal(newString);
#ifdef FAST_MEMCPY
- memcpy(dstp, __stringVal(self) + index1 - 1, count);
- dstp[count] = '\0';
+ memcpy(dstp, __stringVal(self) + index1 - 1, count);
+ dstp[count] = '\0';
#else
- srcp = __stringVal(self) + index1 - 1;
- while (count--) {
- *dstp++ = *srcp++;
- }
- *dstp = '\0';
+ srcp = __stringVal(self) + index1 - 1;
+ while (count--) {
+ *dstp++ = *srcp++;
+ }
+ *dstp = '\0';
#endif
- RETURN ( newString );
- }
- }
- }
+ RETURN ( newString );
+ }
+ }
+ }
}
#endif
%}.
@@ -2168,62 +2168,62 @@
#ifndef NO_PRIM_STRING
if (__bothSmallInteger(start, stop)
&& ((myClass==String) || (myClass==Symbol))) {
- len = __stringSize(self);
- index1 = __intVal(start);
- index2 = __intVal(stop);
-
- if ((index1 <= index2) && (index1 > 0)) {
- if (index2 <= len) {
- count = index2 - index1 + 1;
- sz = OHDR_SIZE + count + 1;
-
- __PROTECT_CONTEXT__
- __qNew(newString, sz); /* OBJECT ALLOCATION */
- __UNPROTECT_CONTEXT__
-
- if (newString != nil) {
- __InstPtr(newString)->o_class = String;
- __qSTORE(newString, String);
- dstp = __stringVal(newString);
- srcp = __stringVal(self) + index1 - 1;
+ len = __stringSize(self);
+ index1 = __intVal(start);
+ index2 = __intVal(stop);
+
+ if ((index1 <= index2) && (index1 > 0)) {
+ if (index2 <= len) {
+ count = index2 - index1 + 1;
+ sz = OHDR_SIZE + count + 1;
+
+ __PROTECT_CONTEXT__
+ __qNew(newString, sz); /* OBJECT ALLOCATION */
+ __UNPROTECT_CONTEXT__
+
+ if (newString != nil) {
+ __InstPtr(newString)->o_class = String;
+ __qSTORE(newString, String);
+ dstp = __stringVal(newString);
+ srcp = __stringVal(self) + index1 - 1;
#ifdef bcopy4
- {
- int nw = count >> 2;
-
- if (count & 3) {
- nw++;
- }
- bcopy4(srcp, dstp, nw);
- dstp[count] = '\0';
- }
+ {
+ int nw = count >> 2;
+
+ if (count & 3) {
+ nw++;
+ }
+ bcopy4(srcp, dstp, nw);
+ dstp[count] = '\0';
+ }
#else
# ifdef FAST_MEMCPY
- memcpy(dstp, srcp, count);
- dstp[count] = '\0';
+ memcpy(dstp, srcp, count);
+ dstp[count] = '\0';
# else
- while (count--) {
- *dstp++ = *srcp++;
- }
- *dstp = '\0';
+ while (count--) {
+ *dstp++ = *srcp++;
+ }
+ *dstp = '\0';
# endif
#endif
- RETURN ( newString );
- }
- }
- }
- /*
- * allow empty copy
- */
- if (index1 > index2) {
- __PROTECT_CONTEXT__
- __qNew(newString, OHDR_SIZE+1); /* OBJECT ALLOCATION */
- __UNPROTECT_CONTEXT__
- if (newString != nil) {
- __InstPtr(newString)->o_class = String;
- (__stringVal(newString))[0] = '\0';
- RETURN ( newString );
- }
- }
+ RETURN ( newString );
+ }
+ }
+ }
+ /*
+ * allow empty copy
+ */
+ if (index1 > index2) {
+ __PROTECT_CONTEXT__
+ __qNew(newString, OHDR_SIZE+1); /* OBJECT ALLOCATION */
+ __UNPROTECT_CONTEXT__
+ if (newString != nil) {
+ __InstPtr(newString)->o_class = String;
+ (__stringVal(newString))[0] = '\0';
+ RETURN ( newString );
+ }
+ }
}
#endif
%}.
@@ -2235,7 +2235,7 @@
copyWith:aCharacter
"return a new string containing the receivers characters
- and the single new character, aCharacter.
+ and the single new character, aCharacter.
This is different from concatentation, which expects another string
as argument, but equivalent to copy-and-addLast.
Reimplemented here for more speed"
@@ -2252,52 +2252,52 @@
#ifndef NO_PRIM_STRING
if (__isCharacter(aCharacter)) {
- unsigned int cVal = __intVal(__characterVal(aCharacter));
-
- if ((cVal <= 0xFF)
- && ((myClass==String) || (myClass==Symbol))) {
- count = __stringSize(self);
- sz = OHDR_SIZE + count + 1 + 1;
-
- __PROTECT_CONTEXT__
- __qNew(newString, sz); /* OBJECT ALLOCATION */
- __UNPROTECT_CONTEXT__
-
- if (newString) {
- __InstPtr(newString)->o_class = String;
- __qSTORE(newString, String);
- dstp = __stringVal(newString);
+ unsigned int cVal = __intVal(__characterVal(aCharacter));
+
+ if ((cVal <= 0xFF)
+ && ((myClass==String) || (myClass==Symbol))) {
+ count = __stringSize(self);
+ sz = OHDR_SIZE + count + 1 + 1;
+
+ __PROTECT_CONTEXT__
+ __qNew(newString, sz); /* OBJECT ALLOCATION */
+ __UNPROTECT_CONTEXT__
+
+ if (newString) {
+ __InstPtr(newString)->o_class = String;
+ __qSTORE(newString, String);
+ dstp = __stringVal(newString);
#ifdef bcopy4
- {
- int nw = count >> 2;
- char *srcp = (char *)__stringVal(self);
-
- if (count & 3) {
- nw++;
- }
- bcopy4(srcp, dstp, nw);
- dstp += count;
- }
+ {
+ int nw = count >> 2;
+ char *srcp = (char *)__stringVal(self);
+
+ if (count & 3) {
+ nw++;
+ }
+ bcopy4(srcp, dstp, nw);
+ dstp += count;
+ }
#else
# ifdef FAST_MEMCPY
- memcpy(dstp, __stringVal(self), count);
- dstp += count;
+ memcpy(dstp, __stringVal(self), count);
+ dstp += count;
# else
- {
- REGISTER unsigned char *srcp;
-
- srcp = __stringVal(self);
- while ((*dstp = *srcp++) != '\0')
- dstp++;
- }
+ {
+ REGISTER unsigned char *srcp;
+
+ srcp = __stringVal(self);
+ while ((*dstp = *srcp++) != '\0')
+ dstp++;
+ }
# endif
# endif
- *dstp++ = cVal;
- *dstp = '\0';
- RETURN (newString );
- }
- }
+ *dstp++ = cVal;
+ *dstp = '\0';
+ RETURN (newString );
+ }
+ }
}
#endif
%}.
@@ -2328,7 +2328,7 @@
of its named instvars ...
"
(self isMemberOf:String) ifTrue:[
- ^ self copyFrom:1
+ ^ self copyFrom:1
].
^ super deepCopyUsing:aDictionary
!
@@ -2350,7 +2350,7 @@
of its named instvars ...
"
(self isMemberOf:String) ifTrue:[
- ^ self copyFrom:1
+ ^ self copyFrom:1
].
^ super simpleDeepCopy
! !
@@ -2370,90 +2370,90 @@
REGISTER int byteValue;
if (__isCharacter(aCharacter) && __isString(self)) {
- byteValue = __intVal(_characterVal(aCharacter));
- if ((unsigned)byteValue <= 0xFF) {
- l = __stringSize(self);
-
-#ifdef FAST_MEMSET
- if (l > 0) {
- memset(__stringVal(self), byteValue, l);
- }
+ byteValue = __intVal(_characterVal(aCharacter));
+ if ((unsigned)byteValue <= 0xFF) {
+ l = __stringSize(self);
+
+#ifdef FAST_MEMSET
+ if (l > 0) {
+ memset(__stringVal(self), byteValue, l);
+ }
#else
- {
- INT v;
-
- v = (byteValue << 8) | byteValue;
- v = (v << 16) | v;
-
- dst = __stringVal(self);
+ {
+ INT v;
+
+ v = (byteValue << 8) | byteValue;
+ v = (v << 16) | v;
+
+ dst = __stringVal(self);
# ifdef FAST_MEMSET4 /* sorry intel: your stosd instruction is slower ... */
- if (l > 0) {
- memset4(dst, v, l>>2);
- l = l & 3;
- }
+ if (l > 0) {
+ memset4(dst, v, l>>2);
+ l = l & 3;
+ }
# else
# ifdef UINT64
- {
- UINT64 v64;
-
- v64 = v;
- v64 = (v64 << 32) | v;
- while (l >= 8) {
- ((UINT64 *)dst)[0] = v64;
- dst += 8;
- l -= 8;
- }
- }
+ {
+ UINT64 v64;
+
+ v64 = v;
+ v64 = (v64 << 32) | v;
+ while (l >= 8) {
+ ((UINT64 *)dst)[0] = v64;
+ dst += 8;
+ l -= 8;
+ }
+ }
# else /* no UINT64 */
- while (l >= 16) {
- ((int *)dst)[0] = v;
- ((int *)dst)[1] = v;
- ((int *)dst)[2] = v;
- ((int *)dst)[3] = v;
- dst += 16;
- l -= 16;
- }
- if (l >= 8) {
- ((int *)dst)[0] = v;
- ((int *)dst)[1] = v;
- dst += 8;
- l -= 8;
- }
- if (l >= 4) {
- ((int *)dst)[0] = v;
- dst += 4;
- l -= 4;
- }
+ while (l >= 16) {
+ ((int *)dst)[0] = v;
+ ((int *)dst)[1] = v;
+ ((int *)dst)[2] = v;
+ ((int *)dst)[3] = v;
+ dst += 16;
+ l -= 16;
+ }
+ if (l >= 8) {
+ ((int *)dst)[0] = v;
+ ((int *)dst)[1] = v;
+ dst += 8;
+ l -= 8;
+ }
+ if (l >= 4) {
+ ((int *)dst)[0] = v;
+ dst += 4;
+ l -= 4;
+ }
# if 0
- if (l >= 2) {
- ((short *)dst)[0] = v;
- dst += 2;
- l -= 2;
- }
+ if (l >= 2) {
+ ((short *)dst)[0] = v;
+ dst += 2;
+ l -= 2;
+ }
# endif
# endif /* UINT64 */
# endif /* FAST_MEMSET4 */
- }
-
- /*
- * remaining bytes
- */
- while (l-- > 0)
- *dst++ = byteValue;
+ }
+
+ /*
+ * remaining bytes
+ */
+ while (l-- > 0)
+ *dst++ = byteValue;
#endif /* no FAST_MEMSET */
- RETURN ( self );
- }
+ RETURN ( self );
+ }
}
%}.
^ super atAllPut:aCharacter
"
- (String new:10) atAllPut:$*
- String new:10 withAll:$*
+ (String new:10) atAllPut:$*
+ String new:10 withAll:$*
"
!
@@ -2472,28 +2472,28 @@
if (__isCharacter(oldCharacter)
&& __isCharacter(newCharacter)
&& __isString(self)) {
- srcp = (unsigned char *)__stringVal(self);
- oldVal = __intVal(_characterVal(oldCharacter));
- newVal = __intVal(_characterVal(newCharacter));
- if ((oldVal <= 0xFF)
- && (newVal <= 0xFF)) {
- cNext = *srcp;
- while ((c = cNext) != '\0') {
- cNext = srcp[1];
- if (c == oldVal)
- *srcp = newVal;
- srcp++;
- }
- }
- RETURN ( self );
+ srcp = (unsigned char *)__stringVal(self);
+ oldVal = __intVal(_characterVal(oldCharacter));
+ newVal = __intVal(_characterVal(newCharacter));
+ if ((oldVal <= 0xFF)
+ && (newVal <= 0xFF)) {
+ cNext = *srcp;
+ while ((c = cNext) != '\0') {
+ cNext = srcp[1];
+ if (c == oldVal)
+ *srcp = newVal;
+ srcp++;
+ }
+ }
+ RETURN ( self );
}
%}.
^ super replaceAll:oldCharacter with:newCharacter
"
- 'helloWorld' copy replaceAll:$o with:$O
- 'helloWorld' copy replaceAll:$d with:$*
- 'helloWorld' copy replaceAll:$h with:$*
+ 'helloWorld' copy replaceAll:$o with:$O
+ 'helloWorld' copy replaceAll:$d with:$*
+ 'helloWorld' copy replaceAll:$h with:$*
"
!
@@ -2542,9 +2542,9 @@
}
#ifdef bcopy4
/* copy quadbytes if pointers are aligned */
- /*
+ /*
* no sizeof(int) here please -
- * - bcopy4 (if defined) copies 4-bytes on ALL machines
+ * - bcopy4 (if defined) copies 4-bytes on ALL machines
*/
if ((count > 12)
&& (((unsigned INT)srcp & 3) == 0)
@@ -2590,7 +2590,7 @@
!
-reverse
+reverse
"in-place reverse the characters of the string.
WARNING: this is a destructive operation, which modifies the receiver."
@@ -2602,29 +2602,29 @@
REGISTER unsigned char *hip, *lowp;
if (__isString(self)) {
- lowp = __stringVal(self);
- hip = lowp + __stringSize(self) - 1;
- while (lowp < hip) {
- c = *lowp;
- *lowp = *hip;
- *hip = c;
- lowp++;
- hip--;
- }
- RETURN ( self );
+ lowp = __stringVal(self);
+ hip = lowp + __stringSize(self) - 1;
+ while (lowp < hip) {
+ c = *lowp;
+ *lowp = *hip;
+ *hip = c;
+ lowp++;
+ hip--;
+ }
+ RETURN ( self );
}
%}.
^ super reverse
!
withoutSeparators
- "return a string containing the chars of myself
+ "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 }"
- endIndex "{ Class: SmallInteger }"
+ endIndex "{ Class: SmallInteger }"
sz|
startIndex := 0.
@@ -2696,25 +2696,25 @@
^ self copyFrom:startIndex to:endIndex
"
- 'hello' withoutSeparators
- ' hello' withoutSeparators
- ' hello ' withoutSeparators
- ' hello ' withoutSeparators
- ' hello ' withoutSeparators
+ 'hello' withoutSeparators
+ ' hello' withoutSeparators
+ ' hello ' withoutSeparators
+ ' hello ' withoutSeparators
+ ' hello ' withoutSeparators
' hello ' withoutSeparators
- ' ' withoutSeparators
+ ' ' withoutSeparators
"
!
withoutSpaces
- "return a string containing the characters of myself
+ "return a string containing the characters of myself
without leading and trailing spaces.
If there are no spaces, the receiver is returned unchanged.
Notice, this is different from String>>withoutSeparators."
|startIndex "{ Class: SmallInteger }"
- endIndex "{ Class: SmallInteger }"
+ endIndex "{ Class: SmallInteger }"
sz blank|
startIndex := 0.
@@ -2755,7 +2755,7 @@
if ((cp == cp0) && (ep == ep0)) {
RETURN(self);
}
-
+
startIndex = __MKSMALLINT(cp - cp0 + 1);
endIndex = __MKSMALLINT(ep - cp0 + 1);
}
@@ -2767,12 +2767,12 @@
^ self copyFrom:startIndex to:endIndex
"
- ' hello' withoutSpaces
- ' hello ' withoutSpaces
- ' hello ' withoutSpaces
- ' hello ' withoutSpaces
+ ' hello' withoutSpaces
+ ' hello ' withoutSpaces
+ ' hello ' withoutSpaces
+ ' hello ' withoutSpaces
' hello ' withoutSpaces
- ' ' withoutSpaces
+ ' ' withoutSpaces
"
! !
@@ -2787,26 +2787,26 @@
print
"print the receiver on standard output.
- This method does NOT (by purpose) use the stream classes and
+ This method does NOT (by purpose) use the stream classes and
will therefore work even in case of emergency (but only, if Stdout is nil)."
%{ /* NOCONTEXT */
if (__qClass(self) == String) {
- if (@global(Stdout) == nil) {
+ if (@global(Stdout) == nil) {
#ifdef WIN32
- fprintf(stdout, "%s" , __stringVal(self));
+ fprintf(stdout, "%s" , __stringVal(self));
#else
/*cg: used to have fputs here, but that seems to be NOT prepared
* for eintr arriving and thus sometimes sends the string twice ...
*
* fputs(__stringVal(self), stdout);
*/
- fwrite(__stringVal(self), 1, __stringSize(self), stdout);
- fflush(stdout);
+ fwrite(__stringVal(self), 1, __stringSize(self), stdout);
+ fflush(stdout);
#endif
- RETURN (self);
- }
+ RETURN (self);
+ }
}
%}.
^ super print
@@ -2814,27 +2814,27 @@
printCR
"print the receiver on standard output, followed by a cr.
- This method does NOT (by purpose) use the stream classes and
+ This method does NOT (by purpose) use the stream classes and
will therefore work even in case of emergency (but only, if Stdout is nil)."
%{ /* NOCONTEXT */
if (__qClass(self) == String) {
- if (@global(Stdout) == nil) {
+ if (@global(Stdout) == nil) {
#ifdef WIN32
- fprintf(stdout, "%s\n" , __stringVal(self));
+ fprintf(stdout, "%s\n" , __stringVal(self));
#else
/*cg: used to have fputs here, but that seems to be NOT prepared
* for eintr arriving and thus sometimes sends the string twice ...
*
- * fputs(__stringVal(self), stdout); fputs("\n", stdout);
+ * fputs(__stringVal(self), stdout); fputs("\n", stdout);
*/
- fwrite(__stringVal(self), 1, __stringSize(self), stdout);
- fwrite("\n", 1, 1, stdout);
- fflush(stdout);
+ fwrite(__stringVal(self), 1, __stringSize(self), stdout);
+ fwrite("\n", 1, 1, stdout);
+ fflush(stdout);
#endif
- RETURN (self);
- }
+ RETURN (self);
+ }
}
%}.
^ super printCR
@@ -2842,7 +2842,7 @@
printfPrintString:formatString
"non-standard but sometimes useful.
- Return a printed representation of the receiver as specified by formatString,
+ Return a printed representation of the receiver as specified by formatString,
which is defined by printf.
This method is NONSTANDARD and may be removed without notice."
@@ -2855,63 +2855,59 @@
char *cp;
int len;
OBJ s;
+ extern void *malloc();
if (__isString(formatString)) {
- cp = (char *)__stringVal(self);
- if (__qClass(self) != String)
- cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
-
+ cp = (char *)__stringVal(self);
+ if (__qClass(self) != String) {
+ cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
+ }
again:
- /*
- * actually only needed on sparc: since thisContext is
- * in a global register, which gets destroyed by printf,
- * manually save it here - very stupid ...
- */
- __BEGIN_PROTECT_REGISTERS__
-
- len = snprintf(buf, bufsize, (char *)__stringVal(formatString), cp);
-
- __END_PROTECT_REGISTERS__
-
-
- if (len > bufsize) {
- bufsize = len + 1;
- if (mallocbuf)
- free(mallocbuf);
- buf = mallocbuf = malloc(bufsize);
- if (buf == NULL)
- goto fail;
- goto again;
- } else if (len < 0) {
- bufsize *= 2;
- if (mallocbuf)
- free(mallocbuf);
- buf = mallocbuf = malloc(bufsize);
- if (buf == NULL)
- goto fail;
- goto again;
- }
-
- s = __MKSTRING_L(buf, len);
-
- if (mallocbuf)
- free(mallocbuf);
-
- if (s != nil) {
- RETURN (s);
- }
+ /*
+ * actually only needed on sparc: since thisContext is
+ * in a global register, which gets destroyed by printf,
+ * manually save it here - very stupid ...
+ */
+ __BEGIN_PROTECT_REGISTERS__
+
+ len = snprintf(buf, bufsize, (char *)__stringVal(formatString), cp);
+
+ __END_PROTECT_REGISTERS__
+
+ if ((len < 0) || (len > bufsize)) {
+ if (len < 0) {
+ bufsize = bufsize * 2;
+ } else {
+ bufsize = len + 1;
+ }
+ if (mallocbuf)
+ free(mallocbuf);
+ buf = mallocbuf = malloc(bufsize);
+ if (buf == NULL)
+ goto fail;
+ goto again;
+ }
+
+ s = __MKSTRING_L(buf, len);
+
+ if (mallocbuf)
+ free(mallocbuf);
+
+ if (s != nil) {
+ RETURN (s);
+ }
}
fail:;
%}.
self primitiveFailed
"
- 'hello' printfPrintString:'%%s -> %s'
- (String new:900) printfPrintString:'%%s -> %s'
- 'hello' printfPrintString:'%%10s -> %10s'
- 'hello' printfPrintString:'%%-10s -> %-10s'
- 'hello' printfPrintString:'%%900s -> %900s'
- 'hello' printfPrintString:'%%-900s -> %-900s'
+ 'hello' printfPrintString:'%%s -> %s'
+ (String new:900) printfPrintString:'%%s -> %s'
+ 'hello' printfPrintString:'%%10s -> %10s'
+ 'hello' printfPrintString:'%%-10s -> %-10s'
+ 'hello' printfPrintString:'%%900s -> %900s'
+ 'hello' printfPrintString:'%%-900s -> %-900s'
"
!
@@ -2920,9 +2916,9 @@
aStream nextPut:$'.
(self includes:$') ifTrue:[
- self printWithQuotesDoubledOn:aStream
+ self printWithQuotesDoubledOn:aStream
] ifFalse:[
- aStream nextPutAll:self
+ aStream nextPutAll:self
].
aStream nextPut:$'
@@ -2948,10 +2944,10 @@
cls = __qClass(slf);
if (cls == String) {
- RETURN ( __MKSMALLINT(__stringSize(slf)) );
+ RETURN ( __MKSMALLINT(__stringSize(slf)) );
}
RETURN ( __MKSMALLINT(__stringSize(slf)
- - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
+ - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
%}.
^ super basicSize - 1
@@ -2967,7 +2963,7 @@
!
contains8BitCharacters
- "return true, if the underlying string contains 8BitCharacters (or widers)
+ "return true, if the underlying string contains 8BitCharacters (or widers)
(i.e. if it is non-ascii)"
%{ /* NOCONTEXT */
@@ -2978,20 +2974,20 @@
cp = __stringVal(self);
if ((cls = __qClass(self)) != String) {
- cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ cp += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
}
for (last=cp+__stringSize(self); cp < last; cp++) {
- if (*cp & 0x80) {
- RETURN ( true );
- }
+ if (*cp & 0x80) {
+ RETURN ( true );
+ }
}
RETURN (false);
%}.
"
- 'hello world' contains8BitCharacters
- 'hello world' asTwoByteString contains8BitCharacters
- ('hello world' , (Character value:16r88) asString) contains8BitCharacters
+ 'hello world' contains8BitCharacters
+ 'hello world' asTwoByteString contains8BitCharacters
+ ('hello world' , (Character value:16r88) asString) contains8BitCharacters
"
!
@@ -3006,9 +3002,9 @@
cls = __qClass(self);
if (cls != String) {
- indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ indx = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
} else {
- indx = 0;
+ indx = 0;
}
RETURN ( __KNOWNASSYMBOL(__stringVal(self) + indx) );
%}.
@@ -3016,8 +3012,8 @@
self primitiveFailed
"
- 'hello' knownAsSymbol
- 'fooBarBaz' knownAsSymbol
+ 'hello' knownAsSymbol
+ 'fooBarBaz' knownAsSymbol
"
!
@@ -3033,10 +3029,10 @@
slf = self;
cls = __qClass(slf);
if (cls == String) {
- RETURN ( __MKSMALLINT(__stringSize(slf)) );
+ RETURN ( __MKSMALLINT(__stringSize(slf)) );
}
RETURN ( __MKSMALLINT(__stringSize(slf)
- - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
+ - __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars))));
%}.
^ self basicSize
!
@@ -3059,32 +3055,32 @@
if ((__isString(slf) || __isSymbol(slf))
&& (__isString(aStringOrChar) || __isSymbol(aStringOrChar))) {
- len1 = __qSize(slf);
- len2 = __qSize(aStringOrChar);
- if (len1 < len2) {
- RETURN ( false );
- }
-
- src1 = __stringVal(slf) + (len1 - len2);
- src2 = __stringVal(aStringOrChar);
- while (c = *src2++) {
- if (c != *src1++) {
- RETURN ( false );
- }
- }
- RETURN (true);
+ len1 = __qSize(slf);
+ len2 = __qSize(aStringOrChar);
+ if (len1 < len2) {
+ RETURN ( false );
+ }
+
+ src1 = __stringVal(slf) + (len1 - len2);
+ src2 = __stringVal(aStringOrChar);
+ while (c = *src2++) {
+ if (c != *src1++) {
+ RETURN ( false );
+ }
+ }
+ RETURN (true);
}
if (__isCharacter(aStringOrChar)) {
- int val;
-
- val = __intVal(_characterVal(aStringOrChar));
- if ((unsigned)val <= 0xFF) {
- len1 = __stringSize(slf);
- if (len1 > 0) {
- RETURN ( (__stringVal(slf)[len1-1] == val) ? true : false);
- }
- }
- RETURN ( false );
+ int val;
+
+ val = __intVal(_characterVal(aStringOrChar));
+ if ((unsigned)val <= 0xFF) {
+ len1 = __stringSize(slf);
+ if (len1 > 0) {
+ RETURN ( (__stringVal(slf)[len1-1] == val) ? true : false);
+ }
+ }
+ RETURN ( false );
}
%}.
^ super endsWith:aStringOrChar
@@ -3092,11 +3088,11 @@
"
'hello world' endsWith:'world'
'hello world' endsWith:'earth'
- 'hello world' endsWith:$d
- 'hello world' endsWith:$e
- '' endsWith:$d
+ 'hello world' endsWith:$d
+ 'hello world' endsWith:$e
+ '' endsWith:$d
'hello world' endsWith:#($r $l $d)
- 'hello world' endsWith:''
+ 'hello world' endsWith:''
"
!
@@ -3112,24 +3108,24 @@
src = __stringVal(self);
if ((cls = __qClass(self)) != String)
- src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ src += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
#ifndef NON_ASCII
# ifdef UINT64
while (*((UINT64 *)src) == 0x2020202020202020L) {
- src += 8;
+ src += 8;
}
# endif /* UINT64 */
while (*((unsigned *)src) == 0x20202020) {
- src += 4;
+ src += 4;
}
#endif /* ascii */
while (c = *src++) {
- if (c != ' ') {
- RETURN ( false );
- }
+ if (c != ' ') {
+ RETURN ( false );
+ }
}
RETURN ( true );
%}.
@@ -3157,8 +3153,8 @@
%{ /* STACK: 2000 */
- /*
- * this is very heavy used when correcting errors
+ /*
+ * this is very heavy used when correcting errors
* (all symbols are searched for best match) - therefore it must be fast
*/
@@ -3174,79 +3170,80 @@
int iW, cW, sW, kW, dW;
# define FASTSIZE 30 /* increase STACK if you increase this ... */
unsigned short fastData[(FASTSIZE + 1) * (FASTSIZE + 1)];
+ extern void *malloc();
if (__isStringLike(self) && __isStringLike(aString)
- && __bothSmallInteger(insrtWeight, caseWeight)
- && __bothSmallInteger(substWeight, deleteWeight)
- && __isSmallInteger(kbdTypoWeight)
+ && __bothSmallInteger(insrtWeight, caseWeight)
+ && __bothSmallInteger(substWeight, deleteWeight)
+ && __isSmallInteger(kbdTypoWeight)
) {
- iW = __intVal(insrtWeight);
- cW = __intVal(caseWeight);
- sW = __intVal(substWeight);
- kW = __intVal(kbdTypoWeight);
- dW = __intVal(deleteWeight);
- s1 = __stringVal(self);
- s2 = __stringVal(aString);
- l1 = strlen(s1);
- l2 = strlen(s2);
-
- sz = (l1 < l2) ? l2 : l1;
- rowDelta = sz + 1;
- if (sz <= FASTSIZE) {
- data = fastData;
- } else {
- /* add ifdef ALLOCA here ... */
- data = (unsigned short *)malloc(rowDelta * rowDelta * sizeof(short));
- if (! data) goto mallocFailed;
- }
-
- data[0] = 0;
- for (j=1, dp=data+1; j<=sz; j++, dp++)
- *dp = dp[-1] + iW;
-
- for (i=1, dp=data+rowDelta; i<=sz; i++, dp+=rowDelta)
- *dp = dp[-rowDelta] + dW;
-
- for (i=0; i<l1; i++) {
- for (j=0; j<l2; j++) {
- if (s1[i] == s2[j])
- m = 0;
- else if (tolower(s1[i]) == tolower(s2[j]))
- m = cW;
- else if (sW != kW && nextOnKeyboard(tolower(s1[i]), tolower(s2[j])))
- m = kW;
- else
- m = sW;
-
- dp = data + ((i+1)*rowDelta) + j;
- v2 = dp[0] + iW;
- v1 = dp[-rowDelta] + m;
- v3 = dp[-rowDelta+1] + dW;
- if (v1 < v2) {
- if (v1 < v3)
- m = v1;
- else
- m = v3;
- } else {
- if (v2 < v3)
- m = v2;
- else
- m = v3;
- }
- dp[1] = m;
- }
- }
- m = data[l1*rowDelta + l2];
- if (sz > FASTSIZE)
- free(data);
- RETURN ( __mkSmallInteger(m) );
+ iW = __intVal(insrtWeight);
+ cW = __intVal(caseWeight);
+ sW = __intVal(substWeight);
+ kW = __intVal(kbdTypoWeight);
+ dW = __intVal(deleteWeight);
+ s1 = __stringVal(self);
+ s2 = __stringVal(aString);
+ l1 = strlen(s1);
+ l2 = strlen(s2);
+
+ sz = (l1 < l2) ? l2 : l1;
+ rowDelta = sz + 1;
+ if (sz <= FASTSIZE) {
+ data = fastData;
+ } else {
+ /* add ifdef ALLOCA here ... */
+ data = (unsigned short *)malloc(rowDelta * rowDelta * sizeof(short));
+ if (! data) goto mallocFailed;
+ }
+
+ data[0] = 0;
+ for (j=1, dp=data+1; j<=sz; j++, dp++)
+ *dp = dp[-1] + iW;
+
+ for (i=1, dp=data+rowDelta; i<=sz; i++, dp+=rowDelta)
+ *dp = dp[-rowDelta] + dW;
+
+ for (i=0; i<l1; i++) {
+ for (j=0; j<l2; j++) {
+ if (s1[i] == s2[j])
+ m = 0;
+ else if (tolower(s1[i]) == tolower(s2[j]))
+ m = cW;
+ else if (sW != kW && nextOnKeyboard(tolower(s1[i]), tolower(s2[j])))
+ m = kW;
+ else
+ m = sW;
+
+ dp = data + ((i+1)*rowDelta) + j;
+ v2 = dp[0] + iW;
+ v1 = dp[-rowDelta] + m;
+ v3 = dp[-rowDelta+1] + dW;
+ if (v1 < v2) {
+ if (v1 < v3)
+ m = v1;
+ else
+ m = v3;
+ } else {
+ if (v2 < v3)
+ m = v2;
+ else
+ m = v3;
+ }
+ dp[1] = m;
+ }
+ }
+ m = data[l1*rowDelta + l2];
+ if (sz > FASTSIZE)
+ free(data);
+ RETURN ( __mkSmallInteger(m) );
}
mallocFailed: ;
%}.
- ^ super levenshteinTo:aString
- s:substWeight k:kbdTypoWeight c:caseWeight
- i:insrtWeight d:deleteWeight
+ ^ super levenshteinTo:aString
+ s:substWeight k:kbdTypoWeight c:caseWeight
+ i:insrtWeight d:deleteWeight
"
'ocmprt' levenshteinTo:'computer'
@@ -3289,81 +3286,81 @@
if (((__qClass(slf)==String) || (__qClass(slf)==Symbol))
&& __isNonNilObject(aStringOrChar)
&& ((__qClass(aStringOrChar)==String) || (__qClass(aStringOrChar)==Symbol))) {
- src1 = __stringVal(slf);
- src2 = __stringVal(aStringOrChar);
-
- if (src1[0] != src2[0]) {
- if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) {
- RETURN (true);
- }
- RETURN ( false );
- }
-
- len1 = __qSize(slf);
- len2 = __qSize(aStringOrChar);
- if (len1 < len2) {
- RETURN ( false );
- }
+ src1 = __stringVal(slf);
+ src2 = __stringVal(aStringOrChar);
+
+ if (src1[0] != src2[0]) {
+ if (__qSize(aStringOrChar) == (OHDR_SIZE+1) /* 1 for the 0-byte */) {
+ RETURN (true);
+ }
+ RETURN ( false );
+ }
+
+ len1 = __qSize(slf);
+ len2 = __qSize(aStringOrChar);
+ if (len1 < len2) {
+ RETURN ( false );
+ }
#ifdef UINT64
- while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
- if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
- RETURN (false);
- }
- len2 -= sizeof(UINT64);
- src1 += sizeof(UINT64);
- src2 += sizeof(UINT64);
- }
+ while (len2 > (OHDR_SIZE+sizeof(UINT64))) {
+ if ( ((UINT64 *)src1)[0] != ((UINT64 *)src2)[0] ) {
+ RETURN (false);
+ }
+ len2 -= sizeof(UINT64);
+ src1 += sizeof(UINT64);
+ src2 += sizeof(UINT64);
+ }
#else
# ifdef UNROLL_LOOPS
- while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
- if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
- RETURN (false);
- }
- if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
- RETURN (false);
- }
- if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
- RETURN (false);
- }
- if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
- RETURN (false);
- }
- len2 -= sizeof(INT)*4;
- src1 += sizeof(INT)*4;
- src2 += sizeof(INT)*4;
- }
+ while (len2 > (OHDR_SIZE+sizeof(INT)*4)) {
+ if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
+ RETURN (false);
+ }
+ if ( ((unsigned INT *)src1)[1] != ((unsigned INT *)src2)[1]) {
+ RETURN (false);
+ }
+ if ( ((unsigned INT *)src1)[2] != ((unsigned INT *)src2)[2]) {
+ RETURN (false);
+ }
+ if ( ((unsigned INT *)src1)[3] != ((unsigned INT *)src2)[3]) {
+ RETURN (false);
+ }
+ len2 -= sizeof(INT)*4;
+ src1 += sizeof(INT)*4;
+ src2 += sizeof(INT)*4;
+ }
# endif /* UNROLL_LOOPS */
#endif /* UINT64 */
- while (len2 > (OHDR_SIZE+sizeof(INT))) {
- if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
- RETURN (false);
- }
- len2 -= sizeof(INT);
- src1 += sizeof(INT);
- src2 += sizeof(INT);
- }
-
- while (c = *src2++) {
- if (c != *src1) {
- RETURN ( false );
- }
- src1++;
- }
- RETURN (true);
+ while (len2 > (OHDR_SIZE+sizeof(INT))) {
+ if ( ((unsigned INT *)src1)[0] != ((unsigned INT *)src2)[0]) {
+ RETURN (false);
+ }
+ len2 -= sizeof(INT);
+ src1 += sizeof(INT);
+ src2 += sizeof(INT);
+ }
+
+ while (c = *src2++) {
+ if (c != *src1) {
+ RETURN ( false );
+ }
+ src1++;
+ }
+ RETURN (true);
}
if (__isCharacter(aStringOrChar)) {
- int val;
-
- val = __intVal(_characterVal(aStringOrChar));
- if ((unsigned)val <= 0xFF) {
- len1 = __stringSize(slf);
- if (len1 > 0) {
- RETURN ( (__stringVal(slf)[0] == val) ? true : false);
- }
- }
- RETURN ( false );
+ int val;
+
+ val = __intVal(_characterVal(aStringOrChar));
+ if ((unsigned)val <= 0xFF) {
+ len1 = __stringSize(slf);
+ if (len1 > 0) {
+ RETURN ( (__stringVal(slf)[0] == val) ? true : false);
+ }
+ }
+ RETURN ( false );
}
%}.
^ super startsWith:aStringOrChar
@@ -3371,13 +3368,13 @@
"
'hello world' startsWith:'hello'
'hello world' startsWith:'hella'
- 'hello world' startsWith:'hi'
- 'hello world' startsWith:$h
- 'hello world' startsWith:$H
- 'hello world' startsWith:(Character value:16rFF00)
- 'hello world' startsWith:60
+ 'hello world' startsWith:'hi'
+ 'hello world' startsWith:$h
+ 'hello world' startsWith:$H
+ 'hello world' startsWith:(Character value:16rFF00)
+ 'hello world' startsWith:60
'hello world' startsWith:#($h $e $l)
- 'hello world' startsWith:''
+ 'hello world' startsWith:''
"
! !
@@ -3394,5 +3391,5 @@
!String class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.213 2005-04-20 14:55:53 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/String.st,v 1.214 2005-07-05 14:07:10 cg Exp $'
! !