allow strings as sepCharacter and endCharacter in #asStringWith:...
--- a/SeqColl.st Sat Sep 04 12:08:46 1999 +0200
+++ b/SeqColl.st Sat Sep 04 13:17:18 1999 +0200
@@ -989,9 +989,11 @@
!
asStringWith:sepCharacter from:firstLine to:lastLine compressTabs:compressTabs final:endCharacter withEmphasis:withEmphasis
- "return part of myself as a string or text with embedded sepCharacters.
+ "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.
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).
@@ -1005,7 +1007,8 @@
idx2 "{ Class:SmallInteger }"
totalLength "{ Class:SmallInteger }"
pos "{ Class:SmallInteger }"
- newString lineString spaces idx nTabs sepCnt
+ sepCnt "{ Class:SmallInteger }"
+ newString lineString spaces idx nTabs
any16Bit stringClass needEmphasis newRuns c
thisLen anyTab|
@@ -1019,16 +1022,22 @@
stringClass := String.
totalLength := 0.
- sepCnt := sepCharacter notNil ifTrue:[1] ifFalse:[0].
+ sepCharacter isNil ifTrue:[
+ sepCnt := 0
+ ] ifFalse:[
+ sepCharacter isCharacter ifTrue:[
+ sepCnt := 1
+ ] ifFalse:[
+ sepCnt := sepCharacter size
+ ]
+ ].
idx1 := firstLine.
idx2 := lastLine.
idx1 to:idx2 do:[:lineIndex |
lineString := self at:lineIndex.
- lineString isNil ifTrue:[
- totalLength := totalLength + sepCnt
- ] ifFalse: [
+ lineString notNil ifTrue:[
withEmphasis ifTrue:[
lineString hasChangeOfEmphasis ifTrue:[
needEmphasis := true
@@ -1038,13 +1047,21 @@
stringClass := lineString class
].
].
- totalLength := totalLength + lineString size + sepCnt
+ totalLength := totalLength + lineString size
+ ].
+ totalLength := totalLength + sepCnt
+ ].
+ totalLength := totalLength - sepCnt.
+
+ endCharacter notNil ifTrue:[
+ endCharacter isCharacter ifTrue:[
+ totalLength := totalLength + 1
+ ] ifFalse:[
+ totalLength := totalLength + endCharacter size
].
].
- endCharacter isNil ifTrue:[
- totalLength := totalLength - 1.
- totalLength < 0 ifTrue:[^ ''].
- ].
+ totalLength <= 0 ifTrue:[^ ''].
+
spaces := ' '.
newString := stringClass new:totalLength.
@@ -1125,11 +1142,19 @@
].
c notNil ifTrue:[
- newString at:pos put:c.
- newRuns notNil ifTrue:[
- newRuns add:nil.
- ].
- pos := pos + 1
+ 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
+ ]
].
].
@@ -1164,13 +1189,13 @@
compressTabs:false
final:$:
- concatenating all elements:
+ concatenating elements (nil sepChars and nil endChars):
#('foo' 'bar' 'baz')
asStringWith:nil
from:1 to:3
compressTabs:false
- final:nil
+ final:nil
creating a string from a collection of lines:
@@ -1192,6 +1217,23 @@
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
+
+ and as final characters:
+
+ #('foo' 'bar' 'baz')
+ asStringWith:'__'
+ from:1 to:3
+ compressTabs:false
+ final:'***'
+
"
"Created: / 17.6.1998 / 12:30:32 / cg"
@@ -4318,6 +4360,6 @@
!SequenceableCollection class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Attic/SeqColl.st,v 1.114 1999-07-26 14:30:58 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Attic/SeqColl.st,v 1.115 1999-09-04 11:17:18 cg Exp $'
! !
SequenceableCollection initialize!
--- a/SequenceableCollection.st Sat Sep 04 12:08:46 1999 +0200
+++ b/SequenceableCollection.st Sat Sep 04 13:17:18 1999 +0200
@@ -989,9 +989,11 @@
!
asStringWith:sepCharacter from:firstLine to:lastLine compressTabs:compressTabs final:endCharacter withEmphasis:withEmphasis
- "return part of myself as a string or text with embedded sepCharacters.
+ "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.
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).
@@ -1005,7 +1007,8 @@
idx2 "{ Class:SmallInteger }"
totalLength "{ Class:SmallInteger }"
pos "{ Class:SmallInteger }"
- newString lineString spaces idx nTabs sepCnt
+ sepCnt "{ Class:SmallInteger }"
+ newString lineString spaces idx nTabs
any16Bit stringClass needEmphasis newRuns c
thisLen anyTab|
@@ -1019,16 +1022,22 @@
stringClass := String.
totalLength := 0.
- sepCnt := sepCharacter notNil ifTrue:[1] ifFalse:[0].
+ sepCharacter isNil ifTrue:[
+ sepCnt := 0
+ ] ifFalse:[
+ sepCharacter isCharacter ifTrue:[
+ sepCnt := 1
+ ] ifFalse:[
+ sepCnt := sepCharacter size
+ ]
+ ].
idx1 := firstLine.
idx2 := lastLine.
idx1 to:idx2 do:[:lineIndex |
lineString := self at:lineIndex.
- lineString isNil ifTrue:[
- totalLength := totalLength + sepCnt
- ] ifFalse: [
+ lineString notNil ifTrue:[
withEmphasis ifTrue:[
lineString hasChangeOfEmphasis ifTrue:[
needEmphasis := true
@@ -1038,13 +1047,21 @@
stringClass := lineString class
].
].
- totalLength := totalLength + lineString size + sepCnt
+ totalLength := totalLength + lineString size
+ ].
+ totalLength := totalLength + sepCnt
+ ].
+ totalLength := totalLength - sepCnt.
+
+ endCharacter notNil ifTrue:[
+ endCharacter isCharacter ifTrue:[
+ totalLength := totalLength + 1
+ ] ifFalse:[
+ totalLength := totalLength + endCharacter size
].
].
- endCharacter isNil ifTrue:[
- totalLength := totalLength - 1.
- totalLength < 0 ifTrue:[^ ''].
- ].
+ totalLength <= 0 ifTrue:[^ ''].
+
spaces := ' '.
newString := stringClass new:totalLength.
@@ -1125,11 +1142,19 @@
].
c notNil ifTrue:[
- newString at:pos put:c.
- newRuns notNil ifTrue:[
- newRuns add:nil.
- ].
- pos := pos + 1
+ 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
+ ]
].
].
@@ -1164,13 +1189,13 @@
compressTabs:false
final:$:
- concatenating all elements:
+ concatenating elements (nil sepChars and nil endChars):
#('foo' 'bar' 'baz')
asStringWith:nil
from:1 to:3
compressTabs:false
- final:nil
+ final:nil
creating a string from a collection of lines:
@@ -1192,6 +1217,23 @@
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
+
+ and as final characters:
+
+ #('foo' 'bar' 'baz')
+ asStringWith:'__'
+ from:1 to:3
+ compressTabs:false
+ final:'***'
+
"
"Created: / 17.6.1998 / 12:30:32 / cg"
@@ -4318,6 +4360,6 @@
!SequenceableCollection class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.114 1999-07-26 14:30:58 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.115 1999-09-04 11:17:18 cg Exp $'
! !
SequenceableCollection initialize!