CharacterArray.st
changeset 15055 99961534feb1
parent 15035 ecbb70df7a5c
child 15167 62b89f82633c
child 18045 c0c600e0d3b3
--- a/CharacterArray.st	Wed Apr 03 20:53:03 2013 +0200
+++ b/CharacterArray.st	Wed Apr 03 21:12:25 2013 +0200
@@ -677,6 +677,7 @@
     ^ self == CharacterArray
 ! !
 
+
 !CharacterArray methodsFor:'Compatibility-ANSI'!
 
 addLineDelimiters
@@ -4915,7 +4916,6 @@
     "Modified: 17.4.1997 / 12:50:23 / cg"
 ! !
 
-
 !CharacterArray methodsFor:'special string converting'!
 
 expandPlaceholders:escapeCharacter with:argArrayOrDictionary
@@ -5860,6 +5860,18 @@
 
 !CharacterArray methodsFor:'substring searching'!
 
+findRangeOfString:subString
+    "find a substring. if found, return the start- and endIndex;
+     if not found, return an empty interval."
+
+    ^ self rangeOfSubCollection:subString startingAt:1 ifAbsent:[0 to:-1] caseSensitive:true
+
+    "
+     'hello world' findRangeOfString:'llo'
+     'hello world' findRangeOfString:'ole'
+    "
+!
+
 findString:subString
     "find a substring. if found, return the index;
      if not found, return 0."
@@ -6016,6 +6028,24 @@
     "Modified: 23.2.1996 / 15:35:15 / cg"
 !
 
+rangeOfSubCollection:subString startingAt:start ifAbsent:exceptionValue caseSensitive:caseSensitive
+    "find a substring. if found, return the start- and endIndex;
+     if not found, return the value of exceptionValue."
+
+    |i|
+
+    i := self indexOfSubCollection:subString startingAt:start ifAbsent:0 caseSensitive:caseSensitive.
+    i == 0 ifTrue:[
+        ^ exceptionValue value
+    ].
+    ^ i to:(i + subString size - 1)
+
+    "
+     'hello world' findRangeOfString:'llo'
+     'hello world' findRangeOfString:'ole'
+    "
+!
+
 restAfter:keyword withoutSeparators:strip
     "compare the left of the receiver with keyword,
      if it matches return the right.
@@ -6349,11 +6379,11 @@
 !CharacterArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.498 2013-04-02 16:06:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.499 2013-04-03 19:12:25 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.498 2013-04-02 16:06:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.499 2013-04-03 19:12:25 cg Exp $'
 ! !