SequenceableCollection.st
changeset 23524 3890b7b67f77
parent 23495 dcef68654b0f
child 23525 79ac77d7c400
--- a/SequenceableCollection.st	Thu Nov 08 11:37:10 2018 +0100
+++ b/SequenceableCollection.st	Fri Nov 09 09:38:57 2018 +0100
@@ -3428,6 +3428,29 @@
     "Modified: 20.2.1997 / 14:23:01 / cg"
 !
 
+copyFrom:startIndex through:anElement
+    "return a new collection consisting of receiver's elements from startIndex
+     up to (and including) the next occurence of anElement.
+     Return the remaining elements (up to the end), if anElement is not found. 
+     Return an empty collection, if startIndex is beyond the receiver's size."
+
+    |endIndex|
+
+    endIndex := self indexOf:anElement startingAt:startIndex+1.
+    endIndex == 0 ifTrue:[
+        ^ self copyFrom:startIndex
+    ].        
+    ^ self copyFrom:startIndex to:endIndex
+
+    "
+     #($a $b $c $d $e $f $g) copyFrom:2 through:$f
+     '1234567890' copyFrom:2 through:$8
+     (10 to:19) copyFrom:5 through:18
+    "
+
+    "Created: / 09-11-2018 / 09:37:10 / Claus Gittinger"
+!
+
 copyFrom:startIndex to:stopIndex
     "return a new collection consisting of receiver's elements
      between start and stop.
@@ -3462,6 +3485,29 @@
     "
 !
 
+copyFrom:startIndex upTo:anElement
+    "return a new collection consisting of receiver's elements from startIndex
+     up to (but excluding) the next occurence of anElement.
+     Return the remaining elements (up to the end), if anElement is not found. 
+     Return an empty collection, if startIndex is beyond the receiver's size."
+
+    |endIndex|
+
+    endIndex := self indexOf:anElement startingAt:startIndex+1.
+    endIndex == 0 ifTrue:[
+        ^ self copyFrom:startIndex
+    ].        
+    ^ self copyFrom:startIndex to:(endIndex - 1)
+
+    "
+     #($a $b $c $d $e $f $g) copyFrom:2 upTo:$f
+     '1234567890' copyFrom:2 upTo:$8
+     (10 to:19) copyFrom:5 upTo:18
+    "
+
+    "Created: / 09-11-2018 / 09:36:11 / Claus Gittinger"
+!
+
 copyLast:count
     "return a new collection consisting of the receiver's last count elements.
      Raises an error if there are not enough elements.