CharacterArray.st
branchjv
changeset 18045 c0c600e0d3b3
parent 18043 03660093fe98
parent 15055 99961534feb1
child 18054 56594a8c6b83
--- a/CharacterArray.st	Tue Apr 16 14:27:04 2013 +0200
+++ b/CharacterArray.st	Thu Apr 18 20:41:50 2013 +0200
@@ -1569,6 +1569,7 @@
 ! !
 
 
+
 !CharacterArray methodsFor:'character searching'!
 
 includesMatchCharacters
@@ -3138,7 +3139,16 @@
 !
 
 asUnicode16String
-    "thats not really true - characters above ascii 16r7F may need special treatment"
+    "return the receiver in a two-byte per character representation.
+     Normally, the internal ST/X representation should be transparent and not
+     of the programmer's concern; except when strings are passed to the outside world,
+     such as wide-string ffi calls or file contents."
+
+    "someone added the comment:
+        that's not really true - characters above ascii 16r7F may need special treatment.
+     Who wrote the above comment? 
+     It is bogus. Of course that is always correct!! Please do not mix Unicode with UTF8;
+     UTF8 is an encoding of a Unicode character."
 
     ^ ((Unicode16String new:self size) replaceFrom:1 to:self size with:self startingAt:1)
 !
@@ -5850,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."
@@ -6006,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.
@@ -6339,11 +6379,11 @@
 !CharacterArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.497 2013-03-28 16:47:25 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.497 2013-03-28 16:47:25 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.499 2013-04-03 19:12:25 cg Exp $'
 ! !