String.st
changeset 10 4f1f9a91e406
parent 5 67342904af11
child 13 62303f84ff5f
--- a/String.st	Mon Nov 08 03:29:58 1993 +0100
+++ b/String.st	Mon Nov 08 03:32:43 1993 +0100
@@ -22,7 +22,7 @@
 COPYRIGHT (c) 1988 by Claus Gittinger
              All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/String.st,v 1.4 1993-10-13 02:14:04 claus Exp $
+$Header: /cvs/stx/stx/libbasic/String.st,v 1.5 1993-11-08 02:32:13 claus Exp $
 '!
 
 %{
@@ -664,6 +664,42 @@
     ^ false
 !
 
+includesMatchCharacters
+    "return true if the receiver includes any meta characters (i.e. $* or $#) 
+     for match operations; false if not"
+
+    (self includes:$*) ifTrue:[^ true].
+    ^ (self includes:$#)
+!
+
+includesAny:aCollection
+    "return true, if the receiver includes any of the characters in the
+     argument, aCollecition"
+
+%{  /* NOCONTEXT */
+
+    REGISTER unsigned char *cp;
+    REGISTER unsigned char *matchP;
+    extern char *strchr();
+
+    if (_isString(aCollection)) {
+        matchP = _stringVal(aCollection);
+        cp = _stringVal(self);
+        if (_qClass(self) != String)
+            cp += _intVal(_ClassInstPtr(_qClass(self))->c_ninstvars) * sizeof(OBJ);
+        while (*cp) {
+            if (index(matchP, *cp)) {
+                RETURN ( true );
+            }
+            cp++;
+        }
+        RETURN ( false );
+    }
+%}
+.
+    ^ super includesAny:aCollection
+!
+
 indexOf:aCharacter
     "return the index of the first occurrences of the argument, aCharacter
      in the receiver or 0 if not found - reimplemented here for speed."
@@ -817,14 +853,6 @@
     ^ exceptionBlock value
 !
 
-includesMatchCharacters
-    "return true if the receiver includes any meta characters (i.e. $* or $#) 
-     for match operations; false if not"
-
-    (self includes:$*) ifTrue:[^ true].
-    ^ (self includes:$#)
-!
-
 from:matchStart to:matchStop match:aString from:start to:stop
     "helper for match; return true if the characters from start to stop in
      aString are matching the receivers characters from matchStart to matchStop.
@@ -1068,13 +1096,14 @@
 countWords
     "return the number of words, which are separated by separators"
 
-    |tally start stop mySize|
+    |tally start stop mySize ch|
 
     tally := 0.
     start := 1.
     mySize := self size.
     [start <= mySize] whileTrue:[
-         (self at:start) isSeparator ifTrue:[
+         ch := self at:start.
+         ((ch == Character space) or:[ch isSeparator]) ifTrue:[
              start := start + 1
          ] ifFalse:[
              stop := self indexOfSeparatorStartingAt:start.
@@ -1091,13 +1120,14 @@
 asCollectionOfWords
     "return a collection containing the words (separated by whitespace) of the receiver"
 
-    |words start stop mySize|
+    |words start stop mySize ch|
 
     words := OrderedCollection new.
     start := 1.
     mySize := self size.
     [start <= mySize] whileTrue:[
-        (self at:start) isSeparator ifTrue:[
+	ch := self at:start.
+        ((ch == Character space) or:[ch isSeparator]) ifTrue:[
             start := start + 1
         ] ifFalse:[
             stop := self indexOfSeparatorStartingAt:start.