SequenceableCollection.st
changeset 1395 f324be2221e3
parent 1385 f90c476be6e3
child 1413 4788a0d3d6e2
--- a/SequenceableCollection.st	Tue May 14 16:05:14 1996 +0200
+++ b/SequenceableCollection.st	Tue May 14 16:37:51 1996 +0200
@@ -655,7 +655,7 @@
 !
 
 asStringWith:sepCharacter from:firstLine to:lastLine compressTabs:compressTabs final:endCharacter
-    "return part of myself as a string with embedded sepCharacters.
+    "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.
      If the argument compressTabs is true, leading spaces are converted
@@ -671,7 +671,7 @@
      totalLength "{ Class:SmallInteger }"
      pos         "{ Class:SmallInteger }"
      newString lineString spaces idx nTabs sepCnt
-     any16Bit stringClass|
+     any16Bit stringClass needEmphasis|
 
     "
      first accumulate the size of the string, to avoid
@@ -679,7 +679,7 @@
      the size computed is not exact, but gives an upper bound ...
      On the fly, look if a 16bit string is needed.
     "
-    any16Bit := false.
+    any16Bit := needEmphasis := false.
     stringClass := String.
 
     totalLength := 0.
@@ -688,70 +688,76 @@
     idx1 := firstLine.
     idx2 := lastLine.
     idx1 to:idx2 do:[:lineIndex |
-	lineString := self at:lineIndex.
-
-	lineString isNil ifTrue:[
-	    totalLength := totalLength + sepCnt
-	] ifFalse: [
-	    (lineString bitsPerCharacter == 16) ifTrue:[
-		any16Bit := true.
-		stringClass := lineString class
-	    ].
-	    totalLength := totalLength + lineString size + sepCnt
-	].
+        lineString := self at:lineIndex.
+
+        lineString isNil ifTrue:[
+            totalLength := totalLength + sepCnt
+        ] ifFalse: [
+            lineString hasChangeOfEmphasis ifTrue:[
+                needEmphasis := true
+            ].
+            (lineString bitsPerCharacter == 16) ifTrue:[
+                any16Bit := true.
+                stringClass := lineString class
+            ].
+            totalLength := totalLength + lineString size + sepCnt
+        ].
     ].
     endCharacter isNil ifTrue:[
-	totalLength := totalLength - 1
+        totalLength := totalLength - 1
     ].
     spaces := '        '.
     newString := stringClass new:totalLength.
+    needEmphasis ifTrue:[
+        newString := Text string:newString
+    ].
 
     "
      now, replace ...
     "
     pos := 1.
     idx1 to:idx2 do:[:lineIndex |
-	|thisLen|
-
-	lineString := self at:lineIndex.
-	thisLen := lineString size.
-	thisLen ~~ 0 ifTrue:[
-	    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.
-		nTabs ~~ 0 ifTrue:[
-		    "any tabs"
-		    newString atAll:(pos to:pos+nTabs-1) put:(Character tab).
-		    pos := pos + nTabs.
-		    newString replaceFrom:pos with:lineString startingAt:(nTabs * 8 + 1).
-		    pos := pos + thisLen - (nTabs * 8).
-		] ifFalse:[
-		    newString replaceFrom:pos with:lineString.
-		    pos := pos + thisLen
-		].
-	    ] ifFalse:[
-		newString replaceFrom:pos with:lineString.
-		pos := pos + thisLen
-	    ]
-	].
-	(sepCharacter notNil 
-	and:[lineIndex ~~ lastLine]) ifTrue:[
-	    newString at:pos put:sepCharacter.
-	    pos := pos + 1
-	] ifFalse:[
-	    endCharacter notNil ifTrue:[
-		newString at:pos put:endCharacter.
-		pos := pos + 1
-	    ]
-	]
+        |thisLen|
+
+        lineString := self at:lineIndex.
+        thisLen := lineString size.
+        thisLen ~~ 0 ifTrue:[
+            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.
+                nTabs ~~ 0 ifTrue:[
+                    "any tabs"
+                    newString atAll:(pos to:pos+nTabs-1) put:(Character tab).
+                    pos := pos + nTabs.
+                    newString replaceFrom:pos with:lineString startingAt:(nTabs * 8 + 1).
+                    pos := pos + thisLen - (nTabs * 8).
+                ] ifFalse:[
+                    newString replaceFrom:pos with:lineString.
+                    pos := pos + thisLen
+                ].
+            ] ifFalse:[
+                newString replaceFrom:pos with:lineString.
+                pos := pos + thisLen
+            ]
+        ].
+        (sepCharacter notNil 
+        and:[lineIndex ~~ lastLine]) ifTrue:[
+            newString at:pos put:sepCharacter.
+            pos := pos + 1
+        ] ifFalse:[
+            endCharacter notNil ifTrue:[
+                newString at:pos put:endCharacter.
+                pos := pos + 1
+            ]
+        ]
     ].
 
     "
@@ -759,33 +765,58 @@
      cut to size ... sorry
     "
     pos ~~ totalLength ifTrue:[
-	^ newString copyTo:(pos - 1)
+        ^ newString copyTo:(pos - 1)
     ].
     ^ newString
 
     "
      creating entries for searchpath:
 
-     #('foo' 'bar' 'baz' '/foo/bar') 
-	asStringWith:$: from:1 to:4 compressTabs:false final:nil 
+       #('foo' 'bar' 'baz' '/foo/bar') 
+          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:$: 
+       #('foo' 'bar' 'baz' '/foo/bar') 
+          asStringWith:$: 
+          from:1 to:4 
+          compressTabs:false 
+          final:$: 
 
      concatenating all elements:
 
-     #('foo' 'bar' 'baz') 
-	asStringWith:nil from:1 to:3 compressTabs:false final:nil 
+       #('foo' 'bar' 'baz') 
+          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) 
+       #('foo' 'bar' 'baz') 
+          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)
+       ) 
+          asStringWith:(Character cr) 
+          from:1 to:4 
+          compressTabs:false 
+          final:(Character cr) 
     "
 
-    "Modified: 23.2.1996 / 15:28:55 / cg"
+    "Modified: 14.5.1996 / 16:37:12 / cg"
 !
 
 asStringWithCRs
@@ -2688,5 +2719,5 @@
 !SequenceableCollection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.61 1996-05-12 16:50:42 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.62 1996-05-14 14:37:51 cg Exp $'
 ! !