SequenceableCollection.st
changeset 1536 29d45204ceed
parent 1495 f0226967f2a2
child 1537 50994cd54f12
--- a/SequenceableCollection.st	Wed Jul 10 17:03:32 1996 +0200
+++ b/SequenceableCollection.st	Wed Jul 10 17:55:36 1996 +0200
@@ -17,7 +17,7 @@
 	category:'Collections-Abstract'
 !
 
-!SequenceableCollection class methodsFor:'documentation'!
+!SequenceableCollection  class methodsFor:'documentation'!
 
 copyright
 "
@@ -61,7 +61,7 @@
 "
 ! !
 
-!SequenceableCollection class methodsFor:'instance creation'!
+!SequenceableCollection  class methodsFor:'instance creation'!
 
 new:size withAll:element
     "return a new collection of size, where all elements are
@@ -692,7 +692,8 @@
      totalLength "{ Class:SmallInteger }"
      pos         "{ Class:SmallInteger }"
      newString lineString spaces idx nTabs sepCnt
-     any16Bit stringClass needEmphasis|
+     any16Bit stringClass needEmphasis newRuns c
+     thisLen anyTab|
 
     "
      first accumulate the size of the string, to avoid
@@ -729,21 +730,23 @@
     ].
     spaces := '        '.
     newString := stringClass new:totalLength.
+
     needEmphasis ifTrue:[
-        newString := Text string:newString
+        newRuns := RunArray new.
     ].
 
     "
      now, replace ...
+     Be careful with runArrays:
+        replacing individual elements is VERY expensive.
+        Therefore, create a new runArray from scratch.
     "
     pos := 1.
     idx1 to:idx2 do:[:lineIndex |
-        |thisLen|
-
         lineString := self at:lineIndex.
         thisLen := lineString size.
         thisLen ~~ 0 ifTrue:[
-            compressTabs ifTrue:[
+            (anyTab := compressTabs) ifTrue:[
                 "
                  mhmh: could use withTabs from String-class here,
                  but we should avoid creating too many temporary strings
@@ -755,30 +758,58 @@
                 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
+                    anyTab := true
+                ]
+            ].
+            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:[
+                            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.
-                pos := pos + thisLen
-            ]
+
+                newRuns notNil ifTrue:[
+                    lineString hasChangeOfEmphasis ifTrue:[
+                        newRuns addAll:(lineString emphasis)
+                    ] ifFalse:[
+                        newRuns add:nil withOccurrences:lineString size
+                    ]
+                ].
+                pos := pos + thisLen.
+            ].
         ].
-        (sepCharacter notNil 
-        and:[lineIndex ~~ lastLine]) ifTrue:[
-            newString at:pos put:sepCharacter.
+
+        lineIndex ~~ lastLine ifTrue:[
+            c := sepCharacter
+        ] ifFalse:[
+            c := endCharacter
+        ].
+
+        c notNil ifTrue:[
+            newString at:pos put:c.
+            newRuns notNil ifTrue:[
+                newRuns add:nil.
+            ].
             pos := pos + 1
-        ] ifFalse:[
-            endCharacter notNil ifTrue:[
-                newString at:pos put:endCharacter.
-                pos := pos + 1
-            ]
-        ]
+        ].
     ].
 
     "
@@ -786,8 +817,14 @@
      cut to size ... sorry
     "
     pos ~~ totalLength ifTrue:[
-        ^ newString copyTo:(pos - 1)
+        newString := newString copyTo:(pos - 1)
     ].
+
+    newRuns notNil ifTrue:[
+        newString := Text string:newString runs:newRuns.
+newString inspect.
+    ].
+
     ^ newString
 
     "
@@ -837,7 +874,7 @@
           final:(Character cr) 
     "
 
-    "Modified: 18.5.1996 / 15:14:36 / cg"
+    "Modified: 10.7.1996 / 17:54:49 / cg"
 !
 
 asStringWithCRs
@@ -2765,8 +2802,8 @@
     "
 ! !
 
-!SequenceableCollection class methodsFor:'documentation'!
+!SequenceableCollection  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.66 1996-06-29 09:43:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.67 1996-07-10 15:55:36 cg Exp $'
 ! !