Stream.st
branchjv
changeset 21024 8734987eb5c7
parent 20578 39641ba8d6e0
parent 20824 4036277080eb
child 21042 edb2e7f82c62
--- a/Stream.st	Wed Oct 26 23:35:39 2016 +0100
+++ b/Stream.st	Fri Nov 18 20:48:04 2016 +0000
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
@@ -225,7 +223,6 @@
     self nextPutAll: someObject asString.
 ! !
 
-
 !Stream methodsFor:'Compatibility-VW'!
 
 nl
@@ -235,7 +232,6 @@
     self nextPut:(Character nl)
 ! !
 
-
 !Stream methodsFor:'accessing'!
 
 contents
@@ -261,10 +257,12 @@
 !
 
 signalAtEnd:aBoolean
-    "set the signalAtEnd flag setting. If true, reading past the end
-     will raise an EndOfStream exception. If false, no exception is
-     raised and nil is returned from all reading messages.
-     The default is to raise a signal, but return nil if not handled (st80 compatibility)."
+    "set the signalAtEnd flag setting. 
+     If true, reading past the end will raise an EndOfStream exception. 
+     If false, no exception is raised and nil is returned from all reading messages.
+     If nil (default), the exception is raised if there is a handler; otherwise, nil is returned.
+     The default (nil) is both st80 backward compatible (i.e. returning nil)
+     AND allows for modern code to provide a handler."
 
     signalAtEnd := aBoolean.
 
@@ -535,7 +533,8 @@
         ^ nil
     ].
 
-    "EndOfStreamNotification is ignored, if there is no handler.
+    "EndOfStreamNotification is a notification;
+     i.e. it is ignored, if there is no handler.
      In this case, nil is returned"
 
     ^ EndOfStreamNotification raiseRequestFrom:self
@@ -1099,7 +1098,7 @@
      most-significant-byte-first (true) or least-first (false).
      This interface is provided to allow talking to external programs,
      where it's known that the byte order is some definite one.
-     If you dont care (i.e. talk to other smalltalks) or you can control the
+     If you don't care (i.e. talk to other smalltalks) or you can control the
      order, please use the corresponding xxxNet methods, which use a standard
      network byte order."
 
@@ -1161,7 +1160,7 @@
      most-significant-byte-first (true) or least-first (false).
      This interface is provided to allow talking to external programs,
      where it's known that the byte order is some definite one.
-     If you dont care (i.e. talk to other smalltalks) or you can control the
+     If you don't care (i.e. talk to other smalltalks) or you can control the
      order, please use the corresponding xxxNet methods, which use a standard
      network byte order."
 
@@ -1638,7 +1637,7 @@
      most-significant-byte-first (true) or least-first (false).
      This interface is provided to allow talking to external programs,
      where it's known that the byte order is some definite one.
-     If you dont care (i.e. talk to other smalltalks) or you can control the
+     If you don't care (i.e. talk to other smalltalks) or you can control the
      order, please use the corresponding xxxNet methods, which use a standard
      network byte order."
 
@@ -1693,7 +1692,7 @@
      most-significant-byte-first (true) or least-first (false).
      This interface is provided to allow talking to external programs,
      where it's known that the byte order is some definite one.
-     If you dont care (i.e. talk to other smalltalks) or you can control the
+     If you don't care (i.e. talk to other smalltalks) or you can control the
      order, please use the corresponding xxxNet methods, which use a standard
      network byte order."
 
@@ -2035,7 +2034,7 @@
 
     "
         (#[] writeStream
-            nextPutAllUtf16Bytes:'BÄxxx' MSB:true;
+            nextPutAllUtf16Bytes:'BÄxxx' MSB:true;
             nextPutUtf16:(Character codePoint:16r10CCCC) MSB:true;
             contents)
    "
@@ -2241,7 +2240,7 @@
 
      This interface is provided to allow talking to external programs,
      where it's known that the byte order is some definite one.
-     If you dont care (i.e. talk to other smalltalks) or you can control the
+     If you don't care (i.e. talk to other smalltalks) or you can control the
      order, please use the corresponding xxxNet methods, which use a standard
      network byte order."
 
@@ -2435,25 +2434,28 @@
     |codePoint "{Class: SmallInteger}"|
 
     codePoint := aCharacter codePoint.
-    (codePoint <= 16rD7FF
-      or:[codePoint >= 16rE000 and:[codePoint <= 16rFFFF]]) ifTrue:[
-        self nextPut:aCharacter.
-    ] ifFalse:[codePoint <= 16r10FFFF ifTrue:[
-        |highBits lowBits|
-
-        codePoint := codePoint - 16r100000.
-        highBits := codePoint bitShift:-10.
-        lowBits := codePoint bitAnd:16r3FF.
-        self nextPut:(Character codePoint:highBits+16rD800).
-        self nextPut:(Character codePoint:lowBits+16rDC00).
-    ] ifFalse:[
-        EncodingError raiseWith:aCharacter errorString:'Character cannot be encoded as UTF-16'.
-    ]].
+    (codePoint <= 16rD7FF or:[codePoint between:16rE000 and:16rFFFF]) 
+        ifTrue:[
+            self nextPut:aCharacter.
+        ] 
+        ifFalse:[
+            codePoint <= 16r10FFFF ifTrue:[
+                |highBits lowBits|
+
+                codePoint := codePoint - 16r100000.
+                highBits := codePoint bitShift:-10.
+                lowBits := codePoint bitAnd:16r3FF.
+                self nextPut:(Character codePoint:highBits+16rD800).
+                self nextPut:(Character codePoint:lowBits+16rDC00).
+            ] ifFalse:[
+                EncodingError raiseWith:aCharacter errorString:'Character cannot be encoded as UTF-16'.
+            ]
+        ].
 
     "
         ((WriteStream on:Unicode16String new)
             nextPutUtf16:$B;
-            nextPutUtf16:$Ä; 
+            nextPutUtf16:$Ä; 
             nextPutUtf16:(Character codePoint:16r10CCCC)
             yourself) contents
     "
@@ -2464,37 +2466,38 @@
      UTF-16 can encode only characters with code points between 0 to 16r10FFFF.
      The underlying stream must support writing of bytes."
 
-    |codePoint|
+    |codePoint "{ Class: SmallInteger }"|
 
     codePoint := aCharacter codePoint.
-    (codePoint <= 16rD7FF
-        or:[ codePoint >= 16rE000 and:[ codePoint <= 16rFFFF ] ])
-            ifTrue:[ self nextPutInt16:codePoint MSB:msb. ]
-            ifFalse:[
-                codePoint <= 16r10FFFF ifTrue:[
-                    |highBits lowBits|
-
-                    codePoint := codePoint - 16r100000.
-                    highBits := codePoint bitShift:-10.
-                    lowBits := codePoint bitAnd:16r3FF.
-                    self nextPutInt16:highBits + 16rD800 MSB:msb.
-                    self nextPutInt16:lowBits + 16rDC00 MSB:msb.
-                ] ifFalse:[
-                    EncodingError raiseWith:aCharacter
-                        errorString:'Character cannot be encoded as UTF-16'.
-                ]
-            ].
+    (codePoint <= 16rD7FF or:[ codePoint between:16rE000 and:16rFFFF ])
+        ifTrue:[ 
+            self nextPutInt16:codePoint MSB:msb. 
+        ]
+        ifFalse:[
+            codePoint <= 16r10FFFF ifTrue:[
+                |highBits lowBits|
+
+                codePoint := codePoint - 16r100000.
+                highBits := codePoint bitShift:-10.
+                lowBits := codePoint bitAnd:16r3FF.
+                self nextPutInt16:(highBits + 16rD800) MSB:msb.
+                self nextPutInt16:(lowBits + 16rDC00) MSB:msb.
+            ] ifFalse:[
+                EncodingError raiseWith:aCharacter
+                    errorString:'Character cannot be encoded as UTF-16'.
+            ]
+        ].
 
     "
         (#[] writeStream
             nextPutUtf16:$B MSB:true;
-            nextPutUtf16:$Ä MSB:true;
+            nextPutUtf16:$Ä MSB:true;
             nextPutUtf16:(Character codePoint:16r10CCCC) MSB:true;
             contents)
 
         (FileStream newTemporary
             nextPutUtf16:$B MSB:false;
-            nextPutUtf16:$Ä MSB:false;
+            nextPutUtf16:$Ä MSB:false;
             nextPutUtf16:(Character codePoint:16r10CCCC) MSB:false;
             reset;
             binary;
@@ -2559,7 +2562,7 @@
     "
       (String streamContents:[:s|
             s nextPutUtf8:$a.
-            s nextPutUtf8:$ü.
+            s nextPutUtf8:$ü.
             s nextPutUtf8: (Character value:16r1fff).
             s nextPutUtf8: (Character value:16rffff).
             s nextPutUtf8: (Character value:16r1ffffff).
@@ -2582,7 +2585,7 @@
 
      This interface is provided to allow talking to external programs,
      where it's known that the byte order is some definite one.
-     If you dont care (i.e. talk to other smalltalks) or you can control the
+     If you don't care (i.e. talk to other smalltalks) or you can control the
      order, please use the corresponding xxxNet methods, which use a standard
      network byte order."
 
@@ -2640,7 +2643,7 @@
 
      This interface is provided to allow talking to external programs,
      where it's known that the byte order is some definite one.
-     If you dont care (i.e. talk to other smalltalks) or you can control the
+     If you don't care (i.e. talk to other smalltalks) or you can control the
      order, please use the corresponding xxxNet methods, which use a standard
      network byte order."