Stream.st
changeset 23540 187ad70cdb1c
parent 23320 50cd7d7c8750
child 23729 772ddbedfb9d
equal deleted inserted replaced
23539:d41c73151593 23540:187ad70cdb1c
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 1989 by Claus Gittinger
     4  COPYRIGHT (c) 1989 by Claus Gittinger
     3 	      All Rights Reserved
     5 	      All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
   219 isAbstract
   221 isAbstract
   220     ^ self == Stream
   222     ^ self == Stream
   221 ! !
   223 ! !
   222 
   224 
   223 
   225 
   224 
       
   225 
       
   226 !Stream methodsFor:'Compatibility-Dolphin'!
   226 !Stream methodsFor:'Compatibility-Dolphin'!
   227 
   227 
   228 display:someObject
   228 display:someObject
   229     "dolphin compatibility"
   229     "dolphin compatibility"
   230 
   230 
   240      This is only allowed, if the receiver supports writing."
   240      This is only allowed, if the receiver supports writing."
   241 
   241 
   242     self nextPut:(Character nl)
   242     self nextPut:(Character nl)
   243 ! !
   243 ! !
   244 
   244 
   245 !Stream methodsFor:'JS syntactic sugar'!
       
   246 
       
   247 log:something
       
   248     "same as showCR:.
       
   249      Added to allow for Transcript.log(...) to be used in a similar way as
       
   250      console.log(...).
       
   251      Not for non-JavaScript usage"
       
   252 
       
   253     self showCR:something.
       
   254 
       
   255     "Created: / 30-08-2018 / 13:29:50 / Claus Gittinger"
       
   256 ! !
       
   257 
   245 
   258 !Stream methodsFor:'accessing'!
   246 !Stream methodsFor:'accessing'!
   259 
   247 
   260 contents
   248 contents
   261     "return the entire contents of the stream.
   249     "return the entire contents of the stream.
  2058         self nextPutUtf16Bytes:(aString at:idx) MSB:msb.
  2046         self nextPutUtf16Bytes:(aString at:idx) MSB:msb.
  2059     ].
  2047     ].
  2060 
  2048 
  2061     "
  2049     "
  2062         (#[] writeStream
  2050         (#[] writeStream
  2063             nextPutAllUtf16Bytes:'BÄxxx' MSB:true;
  2051             nextPutAllUtf16Bytes:'BÄxxx' MSB:true;
  2064             nextPutUtf16:(Character codePoint:16r10CCCC) MSB:true;
  2052             nextPutUtf16:(Character codePoint:16r10CCCC) MSB:true;
  2065             contents)
  2053             contents)
  2066    "
  2054    "
  2067 !
  2055 !
  2068 
  2056 
  2093         ByteArray streamContents:[:s|
  2081         ByteArray streamContents:[:s|
  2094             s nextPutAllUtf8:'hallo'
  2082             s nextPutAllUtf8:'hallo'
  2095         ].
  2083         ].
  2096 
  2084 
  2097         String streamContents:[:s|
  2085         String streamContents:[:s|
  2098             s nextPutAllUtf8:'abcdeäöüß' asUnicode32String
  2086             s nextPutAllUtf8:'abcdeäöüß' asUnicode32String
  2099         ].
  2087         ].
  2100 .
  2088 .
  2101         ByteArray streamContents:[:s|
  2089         ByteArray streamContents:[:s|
  2102             s nextPutAllUtf8:'abcdeäöüß' asUnicode32String
  2090             s nextPutAllUtf8:'abcdeäöüß' asUnicode32String
  2103         ].
  2091         ].
  2104 
  2092 
  2105         '/tmp/bytes' asFilename writingFileDo:[:s|
  2093         '/tmp/bytes' asFilename writingFileDo:[:s|
  2106             s nextPutAllUtf8:'abcdeäöüß'
  2094             s nextPutAllUtf8:'abcdeäöüß'
  2107         ].
  2095         ].
  2108     "
  2096     "
  2109 
  2097 
  2110     "Modified (format): / 16-02-2017 / 20:28:52 / stefan"
  2098     "Modified (format): / 16-02-2017 / 20:28:52 / stefan"
  2111 !
  2099 !
  2512         ].
  2500         ].
  2513 
  2501 
  2514     "
  2502     "
  2515         ((WriteStream on:Unicode16String new)
  2503         ((WriteStream on:Unicode16String new)
  2516             nextPutUtf16:$B;
  2504             nextPutUtf16:$B;
  2517             nextPutUtf16:$Ä; 
  2505             nextPutUtf16:$Ä; 
  2518             nextPutUtf16:(Character codePoint:16r10CCCC)
  2506             nextPutUtf16:(Character codePoint:16r10CCCC)
  2519             yourself) contents
  2507             yourself) contents
  2520     "
  2508     "
  2521 !
  2509 !
  2522 
  2510 
  2547     ].
  2535     ].
  2548 
  2536 
  2549     "
  2537     "
  2550         (#[] writeStream
  2538         (#[] writeStream
  2551             nextPutUtf16Bytes:$B MSB:true;
  2539             nextPutUtf16Bytes:$B MSB:true;
  2552             nextPutUtf16Bytes:$Ä MSB:true;
  2540             nextPutUtf16Bytes:$Ä MSB:true;
  2553             nextPutUtf16Bytes:(Character codePoint:16r10CCCC) MSB:true;
  2541             nextPutUtf16Bytes:(Character codePoint:16r10CCCC) MSB:true;
  2554             contents)
  2542             contents)
  2555 
  2543 
  2556         ('' writeStream
  2544         ('' writeStream
  2557             nextPutUtf16Bytes:$B MSB:true;
  2545             nextPutUtf16Bytes:$B MSB:true;
  2558             nextPutUtf16Bytes:$Ä MSB:true;
  2546             nextPutUtf16Bytes:$Ä MSB:true;
  2559             nextPutUtf16Bytes:(Character codePoint:16r10CCCC) MSB:true;
  2547             nextPutUtf16Bytes:(Character codePoint:16r10CCCC) MSB:true;
  2560             contents)
  2548             contents)
  2561 
  2549 
  2562         (FileStream newTemporary
  2550         (FileStream newTemporary
  2563             nextPutUtf16Bytes:$B MSB:false;
  2551             nextPutUtf16Bytes:$B MSB:false;
  2564             nextPutUtf16Bytes:$Ä MSB:false;
  2552             nextPutUtf16Bytes:$Ä MSB:false;
  2565             nextPutUtf16Bytes:(Character codePoint:16r10CCCC) MSB:false;
  2553             nextPutUtf16Bytes:(Character codePoint:16r10CCCC) MSB:false;
  2566             reset;
  2554             reset;
  2567             binary;
  2555             binary;
  2568             contents)
  2556             contents)
  2569     "
  2557     "
  2671     EncodingError raiseWith:aCharacter errorString:'codePoint > 31bit in #nextPutUtf8:'.
  2659     EncodingError raiseWith:aCharacter errorString:'codePoint > 31bit in #nextPutUtf8:'.
  2672 
  2660 
  2673     "
  2661     "
  2674       (String streamContents:[:s|
  2662       (String streamContents:[:s|
  2675             s nextPutUtf8:$a.
  2663             s nextPutUtf8:$a.
  2676             s nextPutUtf8:$ü.
  2664             s nextPutUtf8:$ü.
  2677             s nextPutUtf8: (Character value:16r1fff).
  2665             s nextPutUtf8: (Character value:16r1fff).
  2678             s nextPutUtf8: (Character value:16rffff).
  2666             s nextPutUtf8: (Character value:16rffff).
  2679             s nextPutUtf8: (Character value:16r1ffffff).
  2667             s nextPutUtf8: (Character value:16r1ffffff).
  2680             s nextPutUtf8: (Character value:16r800).
  2668             s nextPutUtf8: (Character value:16r800).
  2681       ])
  2669       ])
  4208     "append the elements with index from first to last
  4196     "append the elements with index from first to last
  4209      of the argument, aCollection onto the receiver.
  4197      of the argument, aCollection onto the receiver.
  4210      This is only allowed, if the receiver supports writing."
  4198      This is only allowed, if the receiver supports writing."
  4211 
  4199 
  4212     aCollection from:first to:last do:[:element |
  4200     aCollection from:first to:last do:[:element |
  4213 	self nextPut:element
  4201         self nextPut:element
  4214     ].
  4202     ].
  4215     ^ aCollection
       
  4216 
  4203 
  4217     "
  4204     "
  4218      |s|
  4205      |s|
  4219 
  4206 
  4220      s := WriteStream on:#().
  4207      s := WriteStream on:#().
  4221      s nextPutAll:#('one' 'two' 'three' 'four' 'five') startingAt:2 to:4.
  4208      s nextPutAll:#('one' 'two' 'three' 'four' 'five') startingAt:2 to:4.
  4222      s contents
  4209      s contents
  4223     "
  4210     "
  4224 
  4211 
  4225     "Modified: 11.7.1996 / 10:00:32 / cg"
  4212     "Modified: / 11-07-1996 / 10:00:32 / cg"
       
  4213     "Modified: / 22-11-2018 / 12:52:25 / Stefan Vogel"
  4226 !
  4214 !
  4227 
  4215 
  4228 nextPutAllLines:aCollectionOfStrings
  4216 nextPutAllLines:aCollectionOfStrings
  4229     "put all elements of the argument, aCollection as individual lines
  4217     "put all elements of the argument, aCollection as individual lines
  4230      onto the receiver, append a cr (carriage return) after each.
  4218      onto the receiver, append a cr (carriage return) after each.