#contents does not convert the underlying collection to a Text, if there is
authorStefan Vogel <sv@exept.de>
Wed, 09 Apr 2008 08:02:33 +0200
changeset 1943 63b23152a6d2
parent 1942 fc367aa4a425
child 1944 8e596f69b891
#contents does not convert the underlying collection to a Text, if there is no emphasis information (i.e. TextStream behaves like a CharacterWriteStream in zhis case)
TextStream.st
--- a/TextStream.st	Tue Apr 08 18:53:55 2008 +0200
+++ b/TextStream.st	Wed Apr 09 08:02:33 2008 +0200
@@ -127,20 +127,35 @@
 contents
     "return the streams collected contents"
 
+    (currentEmphasis isNil and:[runs isEmptyOrNil]) ifTrue:[
+        "no emphasis information: answer a string"
+        ^ super contents
+    ].
     self closeRun.
     ^ Text string:super contents emphasisCollection:runs
 
     "
-     |s|
+     Answer a Text containing unicode characters:
+         (TextStream on:'')
+            emphasis:#italic;
+            nextPutAll:'hello';
+            emphasis:nil;
+            space;
+            emphasis:#bold;
+            nextPutAll:'world';
+            space;
+            nextPut:Character euro;
+            contents.
 
-     s := TextStream on:String new.
-     s emphasis:#italic.
-     s nextPutAll:'hello'.
-     s emphasis:nil.
-     s space.
-     s emphasis:#bold.
-     s nextPutAll:'world'.
-     s contents
+     Answer a String:
+         (TextStream on:'')
+            nextPutAll:'hello';
+            contents.
+
+     Answer a Text:
+         (TextStream on:Text new)
+            nextPutAll:'hello';
+            contents.
     "
 !
 
@@ -190,7 +205,7 @@
 closeRun
     position ~~ ZeroPosition ifTrue:[
         runs isNil ifTrue:[
-            runs := RunArray new:position-ZeroPosition withAll:currentEmphasis
+            runs := RunArray new:position-ZeroPosition withAll:currentEmphasis.
         ] ifFalse:[
             runs add:currentEmphasis withOccurrences:(position-ZeroPosition-runs size)
         ]
@@ -200,5 +215,5 @@
 !TextStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/TextStream.st,v 1.10 2008-04-08 16:43:52 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/TextStream.st,v 1.11 2008-04-09 06:02:33 stefan Exp $'
 ! !