class: SequenceableCollection
authorClaus Gittinger <cg@exept.de>
Mon, 02 Mar 2015 13:42:47 +0100
changeset 17574 83bccff028ad
parent 17573 1579f53dd422
child 17575 11ce80e0ee6b
class: SequenceableCollection comment/format in:7 methods
SequenceableCollection.st
--- a/SequenceableCollection.st	Mon Mar 02 13:13:08 2015 +0100
+++ b/SequenceableCollection.st	Mon Mar 02 13:42:47 2015 +0100
@@ -400,6 +400,7 @@
     ^ self == SequenceableCollection
 ! !
 
+
 !SequenceableCollection methodsFor:'Compatibility-Squeak'!
 
 allButFirst
@@ -2590,15 +2591,16 @@
     "Modified: 18.5.1996 / 14:00:16 / cg"
 !
 
-asStringWith:sepChar
+asStringWith:sepCharOrString
     "return a string generated by concatenating my elements
-     (which must be strings or nil) and embedding sepChar characters in between.
+     (which must be strings or nil) and embedding sepCharOrString characters in between.
+     The argument sepCharOrString may be a character, a string or nil.
      Nil entries and empty strings are counted as empty lines.
      Similar to joinWith:, but specifically targeted towards collections of strings."
 
     ^ self
         from:1 to:(self size)
-        asStringWith:sepChar
+        asStringWith:sepCharOrString
         compressTabs:false
         final:nil
 
@@ -2611,15 +2613,16 @@
     "Modified: / 10-07-2010 / 22:59:29 / cg"
 !
 
-asStringWith:sepCharacter from:firstLine to:lastLine
+asStringWith:sepCharacterOrString from:firstLine to:lastLine
     "return part of myself as a string with embedded sepCharacters.
      My elements must be strings or nil; nil entries and empty strings are
      taken as empty lines.
+     The argument sepCharOrString may be a character, a string or nil.
      Similar to joinWith:, but specifically targeted towards collections of strings."
 
     ^ self
         from:firstLine to:lastLine
-        asStringWith:sepCharacter
+        asStringWith:sepCharacterOrString
         compressTabs:false
         final:nil
     "
@@ -2633,10 +2636,11 @@
     "Modified: 23.2.1996 / 15:28:55 / cg"
 !
 
-asStringWith:sepCharacter from:firstLine to:lastLine compressTabs:compressTabs final:endCharacter
+asStringWith:sepCharacterOrString from:firstLine to:lastLine compressTabs:compressTabs final:endCharacterOrString
     "return part of myself as a string or text with embedded sepCharacters.
      My elements must be strings or nil; nil entries and empty strings are
      taken as empty lines.
+     The arguments sepCharacterOrString and endCharacterOrString may be nil, a character or a string.
      If the argument compressTabs is true, leading spaces are converted
      to tab-characters (8col tabs). The last line is followed by a final
      character (if non-nil).
@@ -2644,20 +2648,20 @@
 
     ^ self
         from:firstLine to:lastLine
-        asStringWith:sepCharacter
+        asStringWith:sepCharacterOrString
         compressTabs:compressTabs
-        final:endCharacter
+        final:endCharacterOrString
         withEmphasis:true
 
     "Modified: / 17.6.1998 / 12:31:19 / cg"
 !
 
-asStringWith:sepCharacter from:firstLine to:lastLine compressTabs:compressTabs final:endCharacter withEmphasis:withEmphasis
+asStringWith:sepCharacterOrString from:firstLine to:lastLine compressTabs:compressTabs final:endCharacterOrString withEmphasis:withEmphasis
     "return part of myself as a string or text with embedded sepCharacters
      and followup endCharacter.
      My elements must be strings or nil; nil entries and empty strings are
      taken as empty lines.
-     sepCharacter and endCharacter may be nil, a character or a string.
+     The arguments sepCharacterOrString and endCharacterOrString may be nil, a character or a string.
      If the argument compressTabs is true, leading spaces are converted
      to tab-characters (8col tabs). The last line is followed by a final
      character (if non-nil).
@@ -2670,9 +2674,9 @@
 
     ^ self
         from:firstLine to:lastLine
-        asStringWith:sepCharacter
+        asStringWith:sepCharacterOrString
         compressTabs:compressTabs
-        final:endCharacter
+        final:endCharacterOrString
         withEmphasis:withEmphasis
 !
 
@@ -2799,17 +2803,18 @@
     "Modified: / 26-03-2007 / 13:57:10 / cg"
 !
 
-from:firstLine to:lastLine asStringWith:sepCharacter
-    "return part of myself as a string with embedded sepCharacters.
+from:firstLine to:lastLine asStringWith:sepCharacterOrString
+    "return part of myself as a string with embedded sepCharacterOrStrings.
+     The argument sepCharacterOrString may be a character, a string or nil.
      My elements must be strings or nil; nil entries and empty strings are
      taken as empty lines."
 
     ^ self
-	from:firstLine
-	to:lastLine
-	asStringWith:sepCharacter
-	compressTabs:false
-	final:nil
+        from:firstLine
+        to:lastLine
+        asStringWith:sepCharacterOrString
+        compressTabs:false
+        final:nil
     "
      creating entries for searchpath:
 
@@ -2823,31 +2828,33 @@
     "Modified: 23.2.1996 / 15:28:55 / cg"
 !
 
-from:firstLine to:lastLine asStringWith:sepCharacter compressTabs:compressTabs final:endCharacter
+from:firstLine to:lastLine asStringWith:sepCharacterOrString compressTabs:compressTabs final:endCharacterOrString
     "return part of myself as a string or text with embedded sepCharacters.
      My elements must be strings or nil; nil entries and empty strings are
      taken as empty lines.
+     The arguments sepCharacterOrString and endCharacterOrString may be characters,
+     strings or nil.
      If the argument compressTabs is true, leading spaces are converted
-     to tab-characters (8col tabs). The last line is followed by a final
-     character (if non-nil)."
+     to tab-characters (8col tabs). 
+     The last line is followed by a final character (if non-nil)."
 
     ^ self
-	from:firstLine
-	to:lastLine
-	asStringWith:sepCharacter
-	compressTabs:compressTabs
-	final:endCharacter
-	withEmphasis:true
+        from:firstLine
+        to:lastLine
+        asStringWith:sepCharacterOrString 
+        compressTabs:compressTabs
+        final:endCharacterOrString 
+        withEmphasis:true
 
     "Modified: / 17.6.1998 / 12:31:19 / cg"
 !
 
-from:firstLine to:lastLine asStringWith:sepCharacter compressTabs:compressTabs final:endCharacter withEmphasis:withEmphasis
-    "return part of myself as a string or text with embedded sepCharacters
-     and followup endCharacter.
+from:firstLine to:lastLine asStringWith:sepCharacterOrString compressTabs:compressTabs final:endCharacterOrString withEmphasis:withEmphasis
+    "return part of myself as a string or text with embedded sepCharacterOrString
+     and followup endCharacterOrString.
      My elements must be strings or nil; nil entries and empty strings are
      taken as empty lines.
-     sepCharacter and endCharacter may be nil, a character or a string.
+     sepCharacterOrString and endCharacterOrString may be nil, a character or a string.
      If the argument compressTabs is true, leading spaces are converted
      to tab-characters (8col tabs). The last line is followed by a final
      character (if non-nil).
@@ -2876,50 +2883,50 @@
     maxBitsPerCharacter := 8.
 
     totalLength := 0.
-    sepCharacter isNil ifTrue:[
-	sepCnt := 0
+    sepCharacterOrString isNil ifTrue:[
+        sepCnt := 0
     ] ifFalse:[
-	sepCharacter isCharacter ifTrue:[
-	    sepCnt := 1
-	] ifFalse:[
-	    sepCnt := sepCharacter size
-	]
+        sepCharacterOrString isCharacter ifTrue:[
+            sepCnt := 1
+        ] ifFalse:[
+            sepCnt := sepCharacterOrString size
+        ]
     ].
 
     idx1 := firstLine.
     idx2 := lastLine.
     idx1 to:idx2 do:[:lineIndex |
-	lineString := self at:lineIndex.
-
-	lineString notNil ifTrue:[
-	    withEmphasis ifTrue:[
-		lineString hasChangeOfEmphasis ifTrue:[
-		    needEmphasis := true
-		].
-	    ].
-	    maxBitsPerCharacter := maxBitsPerCharacter max:(lineString bitsPerCharacter).
-	    totalLength := totalLength + lineString size
-	].
-	totalLength := totalLength + sepCnt
+        lineString := self at:lineIndex.
+
+        lineString notNil ifTrue:[
+            withEmphasis ifTrue:[
+                lineString hasChangeOfEmphasis ifTrue:[
+                    needEmphasis := true
+                ].
+            ].
+            maxBitsPerCharacter := maxBitsPerCharacter max:(lineString bitsPerCharacter).
+            totalLength := totalLength + lineString size
+        ].
+        totalLength := totalLength + sepCnt
     ].
     totalLength := totalLength - sepCnt.
 
     maxBitsPerCharacter > 8 ifTrue:[
-	maxBitsPerCharacter > 16 ifTrue:[
-	    stringClass := Unicode32String.
-	] ifFalse:[
-	    stringClass := Unicode16String.
-	]
+        maxBitsPerCharacter > 16 ifTrue:[
+            stringClass := Unicode32String.
+        ] ifFalse:[
+            stringClass := Unicode16String.
+        ]
     ] ifFalse:[
-	stringClass := String.
-    ].
-
-    endCharacter notNil ifTrue:[
-	endCharacter isCharacter ifTrue:[
-	    totalLength := totalLength + 1
-	] ifFalse:[
-	    totalLength := totalLength + endCharacter size
-	].
+        stringClass := String.
+    ].
+
+    endCharacterOrString notNil ifTrue:[
+        endCharacterOrString isCharacter ifTrue:[
+            totalLength := totalLength + 1
+        ] ifFalse:[
+            totalLength := totalLength + endCharacterOrString size
+        ].
     ].
     totalLength <= 0 ifTrue:[^ ''].
 
@@ -2927,94 +2934,94 @@
     newString := stringClass new:totalLength.
 
     needEmphasis ifTrue:[
-	newRuns := RunArray new.
+        newRuns := RunArray new.
     ].
 
     "
      now, replace ...
      Be careful with runArrays:
-	replacing individual elements is VERY expensive.
-	Therefore, create a new runArray from scratch.
+        replacing individual elements is VERY expensive.
+        Therefore, create a new runArray from scratch.
     "
     pos := 1.
     idx1 to:idx2 do:[:lineIndex |
-	lineString := self at:lineIndex.
-	thisLen := lineString size.
-	thisLen ~~ 0 ifTrue:[
-	    withEmphasis ifFalse:[
-		lineString := lineString string.
-	    ].
-
-	    (anyTab := compressTabs) ifTrue:[
-		"
-		 mhmh: could use withTabs from String-class here,
-		 but we should avoid creating too many temporary strings
-		 (especially, since this method is typically used when converting
-		 big texts such as when saving in the filebrowser ...).
-		 Therefore, we convert tabs inline here doing a direct replace
-		 in newString."
-
-		idx := lineString findFirst:[:c | (c ~~ Character space)].
-		nTabs := (idx-1) // 8.
-		anyTab := (nTabs > 0)
-	    ].
-	    anyTab ifTrue:[
-		"any tabs"
-
-		idx := nTabs * 8 + 1.   "/ index of first copied character in string
-
-		newString atAll:(pos to:pos+nTabs-1) put:(Character tab).
-		newRuns notNil ifTrue:[
-		    newRuns add:nil withOccurrences:nTabs
-		].
-		pos := pos + nTabs.
-
-		newString replaceFrom:pos with:lineString startingAt:idx.
-		newRuns notNil ifTrue:[
-		    lineString hasChangeOfEmphasis ifTrue:[
-			idx to:lineString size do:[:pos |
-			    newRuns add:(lineString emphasisAt:pos)
-			]
-		    ] ifFalse:[
-			newRuns add:nil withOccurrences:(lineString size - idx + 1)
-		    ]
-		].
-		pos := pos + thisLen - (nTabs * 8).
-	    ] ifFalse:[
-		newString replaceFrom:pos with:lineString.
-
-		newRuns notNil ifTrue:[
-		    lineString hasChangeOfEmphasis ifTrue:[
-			newRuns addAll:(lineString emphasis)
-		    ] ifFalse:[
-			newRuns add:nil withOccurrences:lineString size
-		    ]
-		].
-		pos := pos + thisLen.
-	    ].
-	].
-
-	lineIndex ~~ lastLine ifTrue:[
-	    c := sepCharacter
-	] ifFalse:[
-	    c := endCharacter
-	].
-
-	c notNil ifTrue:[
-	    c isCharacter ifTrue:[
-		newString at:pos put:c.
-		newRuns notNil ifTrue:[
-		    newRuns add:nil.
-		].
-		pos := pos + 1
-	    ] ifFalse:[
-		newString replaceFrom:pos with:c.
-		newRuns notNil ifTrue:[
-		    newRuns add:nil withOccurrences:c size
-		].
-		pos := pos + c size
-	    ]
-	].
+        lineString := self at:lineIndex.
+        thisLen := lineString size.
+        thisLen ~~ 0 ifTrue:[
+            withEmphasis ifFalse:[
+                lineString := lineString string.
+            ].
+
+            (anyTab := compressTabs) ifTrue:[
+                "
+                 mhmh: could use withTabs from String-class here,
+                 but we should avoid creating too many temporary strings
+                 (especially, since this method is typically used when converting
+                 big texts such as when saving in the filebrowser ...).
+                 Therefore, we convert tabs inline here doing a direct replace
+                 in newString."
+
+                idx := lineString findFirst:[:c | (c ~~ Character space)].
+                nTabs := (idx-1) // 8.
+                anyTab := (nTabs > 0)
+            ].
+            anyTab ifTrue:[
+                "any tabs"
+
+                idx := nTabs * 8 + 1.   "/ index of first copied character in string
+
+                newString atAll:(pos to:pos+nTabs-1) put:(Character tab).
+                newRuns notNil ifTrue:[
+                    newRuns add:nil withOccurrences:nTabs
+                ].
+                pos := pos + nTabs.
+
+                newString replaceFrom:pos with:lineString startingAt:idx.
+                newRuns notNil ifTrue:[
+                    lineString hasChangeOfEmphasis ifTrue:[
+                        idx to:lineString size do:[:pos |
+                            newRuns add:(lineString emphasisAt:pos)
+                        ]
+                    ] ifFalse:[
+                        newRuns add:nil withOccurrences:(lineString size - idx + 1)
+                    ]
+                ].
+                pos := pos + thisLen - (nTabs * 8).
+            ] ifFalse:[
+                newString replaceFrom:pos with:lineString.
+
+                newRuns notNil ifTrue:[
+                    lineString hasChangeOfEmphasis ifTrue:[
+                        newRuns addAll:(lineString emphasis)
+                    ] ifFalse:[
+                        newRuns add:nil withOccurrences:lineString size
+                    ]
+                ].
+                pos := pos + thisLen.
+            ].
+        ].
+
+        lineIndex ~~ lastLine ifTrue:[
+            c := sepCharacterOrString
+        ] ifFalse:[
+            c := endCharacterOrString
+        ].
+
+        c notNil ifTrue:[
+            c isCharacter ifTrue:[
+                newString at:pos put:c.
+                newRuns notNil ifTrue:[
+                    newRuns add:nil.
+                ].
+                pos := pos + 1
+            ] ifFalse:[
+                newString replaceFrom:pos with:c.
+                newRuns notNil ifTrue:[
+                    newRuns add:nil withOccurrences:c size
+                ].
+                pos := pos + c size
+            ]
+        ].
     ].
 
     "
@@ -3022,11 +3029,11 @@
      cut to size ... sorry
     "
     pos ~~ totalLength ifTrue:[
-	newString := newString copyTo:(pos - 1)
+        newString := newString copyTo:(pos - 1)
     ].
 
     newRuns notNil ifTrue:[
-	newString := Text string:newString runs:newRuns.
+        newString := Text string:newString runs:newRuns.
     ].
 
     ^ newString
@@ -3035,63 +3042,63 @@
      creating entries for searchpath:
 
        #('foo' 'bar' 'baz' '/foo/bar')
-	  asStringWith:$:
-	  from:1 to:4
-	  compressTabs:false
-	  final:nil
+          asStringWith:$:
+          from:1 to:4
+          compressTabs:false
+          final:nil
 
      with trailing colon:
 
        #('foo' 'bar' 'baz' '/foo/bar')
-	  asStringWith:$:
-	  from:1 to:4
-	  compressTabs:false
-	  final:$:
+          asStringWith:$:
+          from:1 to:4
+          compressTabs:false
+          final:$:
 
      concatenating elements (nil sepChars and nil endChars):
 
        #('foo' 'bar' 'baz')
-	  asStringWith:nil
-	  from:1 to:3
-	  compressTabs:false
-	  final:nil
+          asStringWith:nil
+          from:1 to:3
+          compressTabs:false
+          final:nil
 
      creating a string from a collection of lines:
 
        #('foo' 'bar' 'baz')
-	  asStringWith:(Character cr)
-	  from:1 to:3
-	  compressTabs:false
-	  final:(Character cr)
+          asStringWith:(Character cr)
+          from:1 to:3
+          compressTabs:false
+          final:(Character cr)
 
      creating a text from a collection of mixed texts and strings:
 
        (Array
-	    with:'foo'
-	    with:('bar' asText allBold)
-	    with:'baz'
-	    with:('baz2' asText emphasizeAllWith:#italic)
+            with:'foo'
+            with:('bar' asText allBold)
+            with:'baz'
+            with:('baz2' asText emphasizeAllWith:#italic)
        )
-	  asStringWith:(Character cr)
-	  from:1 to:4
-	  compressTabs:false
-	  final:(Character cr)
+          asStringWith:(Character cr)
+          from:1 to:4
+          compressTabs:false
+          final:(Character cr)
 
      can also use strings as separating characters:
 
        #('foo' 'bar' 'baz')
-	  asStringWith:'__'
-	  from:1 to:3
-	  compressTabs:false
-	  final:nil
+          asStringWith:'__'
+          from:1 to:3
+          compressTabs:false
+          final:nil
 
      and as final characters:
 
        #('foo' 'bar' 'baz')
-	  asStringWith:'__'
-	  from:1 to:3
-	  compressTabs:false
-	  final:'***'
+          asStringWith:'__'
+          from:1 to:3
+          compressTabs:false
+          final:'***'
 
     "
 
@@ -9821,11 +9828,11 @@
 !SequenceableCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.401 2015-03-01 16:47:07 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.402 2015-03-02 12:42:47 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.401 2015-03-01 16:47:07 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.402 2015-03-02 12:42:47 cg Exp $'
 ! !