235 |
235 |
236 "/ someObject printOn:self. |
236 "/ someObject printOn:self. |
237 self nextPutAll: someObject asString. |
237 self nextPutAll: someObject asString. |
238 ! ! |
238 ! ! |
239 |
239 |
240 !Stream methodsFor:'Compatibility-Squeak'! |
|
241 |
|
242 nextInt32 |
|
243 <resource: #obsolete> |
|
244 "Read a 32-bit signed integer from the next 4 bytes, most significant byte first" |
|
245 |
|
246 "/ CG: PLEASE do not use this in new code; |
|
247 "/ we want the byte order to be explicit, and seen at the call site, |
|
248 "/ as in the past, there was often confusion about it |
|
249 "/ (people reading binary files, which worked on MSB architectures, but failed on others) |
|
250 "/ |
|
251 self obsoleteMethodWarning:'use nextInt32MSB:'. |
|
252 |
|
253 ^ self nextInt32MSB: true |
|
254 |
|
255 "Original Squeak impl" |
|
256 "| s | |
|
257 s := 0. |
|
258 1 to: 4 do: [:i | s := (s bitShift: 8) + self next]. |
|
259 (s bitAnd: 16r80000000) = 0 |
|
260 ifTrue: [^ s] |
|
261 ifFalse: [^ -1 - s bitInvert32] |
|
262 " |
|
263 |
|
264 "Modified: / 14-09-2010 / 13:22:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
265 "Modified: / 16-09-2011 / 15:22:10 / cg" |
|
266 ! |
|
267 |
|
268 nextInt32Put: i32 |
|
269 <resource: #obsolete> |
|
270 "Write a signed integer to the next 4 bytes, most significant byte first" |
|
271 |
|
272 "/ CG: PLEASE do not use this in new code; |
|
273 "/ we want the byte order to be explicit, and seen at the call site, |
|
274 "/ as in the past, there was often confusion about it |
|
275 "/ (people reading binary files, which worked on MSB architectures, but failed on others) |
|
276 "/ |
|
277 self obsoleteMethodWarning:'use nextPutInt32:MSB:'. |
|
278 |
|
279 self nextPutInt32:i32 MSB:true. |
|
280 "/ | pos | |
|
281 "/ |
|
282 "/ pos := i32 < 0 |
|
283 "/ ifTrue: [(0-i32) bitInvert32 + 1] |
|
284 "/ ifFalse: [i32]. |
|
285 "/ 1 to: 4 do: [:i | self nextPut: (pos digitAt: 5-i)]. |
|
286 "/ ^ i32 |
|
287 |
|
288 "Modified: / 16-09-2011 / 15:23:08 / cg" |
|
289 ! |
|
290 |
|
291 nextLittleEndianNumber: n |
|
292 "Answer the next n bytes as a positive Integer or LargePositiveInteger, |
|
293 where the bytes are ordered from least significant to most significant." |
|
294 |
|
295 ^ self nextUnsigned:n MSB:false. |
|
296 |
|
297 "/ Original Squeak code: |
|
298 "/ | bytes s | |
|
299 "/ |
|
300 "/ bytes := self next: n. |
|
301 "/ s := 0. |
|
302 "/ n to: 1 by: -1 do: [:i | |b t| |
|
303 "/ t := (s bitShift: 8). |
|
304 "/ b := bytes at: i. |
|
305 "/ s := t bitOr: b |
|
306 "/ ]. |
|
307 "/ ^ s |
|
308 |
|
309 " |
|
310 self assert:( [|s| s := #[1 2 3 4] readStream nextLittleEndianNumber:4] value = 16r04030201) |
|
311 self assert:( [|s| s := #[1 2 3 4 5 6 7 8] readStream nextLittleEndianNumber:8] value = 16r0807060504030201) |
|
312 " |
|
313 |
|
314 "Modified: / 17-09-2011 / 09:07:03 / cg" |
|
315 ! |
|
316 |
|
317 nextLittleEndianNumber: n put: value |
|
318 "write a positive Integer or LargePositiveInteger as the next n bytes ordered from least significant to most significant." |
|
319 |
|
320 | bytes | |
|
321 |
|
322 bytes := ByteArray new: n. |
|
323 1 to: n do: [:i | bytes at: i put: (value digitAt: i)]. |
|
324 self nextPutAll: bytes |
|
325 |
|
326 "Modified (format): / 16-09-2011 / 12:09:33 / cg" |
|
327 ! |
|
328 |
|
329 nextPutSqueakString: s |
|
330 "Append the string, s, to the receiver. |
|
331 Only used by DataStream. |
|
332 Max size of 64*256*256*256." |
|
333 |
|
334 | length | |
|
335 |
|
336 (length := s size) < 192 |
|
337 ifTrue: [self nextPut: length] |
|
338 ifFalse: |
|
339 [self nextPut: (length digitAt: 4)+192. |
|
340 self nextPut: (length digitAt: 3). |
|
341 self nextPut: (length digitAt: 2). |
|
342 self nextPut: (length digitAt: 1)]. |
|
343 self nextPutAll: s asByteArray. |
|
344 ^s |
|
345 |
|
346 "Modified: / 16-09-2011 / 15:20:30 / cg" |
|
347 "Created: / 08-02-2012 / 14:25:48 / cg" |
|
348 ! |
|
349 |
|
350 nextSqueakString |
|
351 "Read a string from the receiver. |
|
352 The first byte is the length of the string, unless it is greater than 192, |
|
353 in which case the first four bytes encode the length. |
|
354 I expect to be in ascii mode when called (caller puts back to binary). |
|
355 Max size 1G." |
|
356 |
|
357 | length aByteArray | |
|
358 |
|
359 "read the length in binary mode" |
|
360 self binary. |
|
361 length := self next. "first byte." |
|
362 length >= 192 ifTrue: [ |
|
363 length := length - 192. |
|
364 1 to: 3 do: [:ii | length := length * 256 + self next] |
|
365 ]. |
|
366 aByteArray := ByteArray new: length. |
|
367 |
|
368 self nextInto: aByteArray. |
|
369 ^aByteArray asString. |
|
370 |
|
371 "Created: / 26-01-2012 / 17:38:02 / cg" |
|
372 ! |
|
373 |
|
374 nextSqueakStringOld |
|
375 "Read a string from the receiver. The first byte is the length of the |
|
376 string, unless it is greater than 192, in which case the first *two* bytes |
|
377 encode the length. |
|
378 Max size 16K. " |
|
379 |
|
380 | aString length | |
|
381 |
|
382 length := self next. "first byte." |
|
383 length >= 192 ifTrue: [length := (length - 192) * 256 + self next]. |
|
384 aString := String new: length. |
|
385 1 to: length do: [:ii | aString at: ii put: self next asCharacter]. |
|
386 ^aString |
|
387 |
|
388 "Modified: / 16-09-2011 / 15:20:07 / cg" |
|
389 "Created: / 08-02-2012 / 14:27:45 / cg" |
|
390 ! |
|
391 |
|
392 nextString |
|
393 <resource: #obsolete> |
|
394 |
|
395 "/ CG: PLEASE do not use this in new code; |
|
396 "/ it is highly specific to a particular encoding style used by a particular Squeak |
|
397 "/ application. It is not general enough to justify polluting the Stream selector namespace |
|
398 "/ with a generic name like nextString - after all, I would expect a 0-terminated string reader under that name |
|
399 "/ so please move that algorithm as utility to whoever calls this, and be prepared for this method to vanish |
|
400 self obsoleteMethodWarning:'use nextSqueakString'. |
|
401 |
|
402 "Read a string from the receiver. |
|
403 The first byte is the length of the string, unless it is greater than 192, |
|
404 in which case the first four bytes encode the length. |
|
405 I expect to be in ascii mode when called (caller puts back to binary)." |
|
406 ^ self nextSqueakString |
|
407 |
|
408 "Modified (comment): / 26-01-2012 / 17:38:47 / cg" |
|
409 ! |
|
410 |
|
411 nextStringOld |
|
412 <resource: #obsolete> |
|
413 "/ CG: PLEASE do not use this in new code; |
|
414 "/ it is highly specific to a particular encoding style used by a particular Squeak |
|
415 "/ application. It is not general enough to justify polluting the Stream selector namespace |
|
416 "/ with a generic name like nextString - after all, I would expect a 0-terminated string reader under that name |
|
417 "/ so please move that algorithm as utility to whoever calls this, and be prepared for this method to vanish |
|
418 self obsoleteMethodWarning:'use nextSqueakStringOld'. |
|
419 ^ self nextSqueakStringOld |
|
420 |
|
421 "Modified: / 08-02-2012 / 14:28:00 / cg" |
|
422 ! |
|
423 |
|
424 nextStringPut: s |
|
425 "/ CG: PLEASE do not use this in new code; |
|
426 "/ it is highly specific to a particular encoding style used by a particular Squeak |
|
427 "/ application. It is not general enough to justify polluting the Stream selector namespace |
|
428 "/ with a generic name like nextStringPut: - after all, I would expect a 0-terminated string reader under that name |
|
429 "/ so please move that algorithm as utility to whoever calls this, and be prepared for this method to vanish |
|
430 |
|
431 <resource: #obsolete> |
|
432 |
|
433 self obsoleteMethodWarning:'use nextPutSqueakString:'. |
|
434 ^ self nextPutSqueakString: s |
|
435 |
|
436 "Modified: / 08-02-2012 / 14:26:25 / cg" |
|
437 ! |
|
438 |
|
439 nextWord |
|
440 <resource: #obsolete> |
|
441 "Answer the next two bytes from the receiver as an Integer, most significant byte first." |
|
442 |
|
443 | high low | |
|
444 |
|
445 self obsoleteMethodWarning:'please use nextInt16MSB:true'. |
|
446 |
|
447 "/ cg: what an ugly rubbish interface: returning false here instead of nil !!!!!! |
|
448 |
|
449 (high := self next) isNil ifTrue: [^false]. |
|
450 (low := self next) isNil ifTrue: [^false]. |
|
451 ^(high asInteger bitShift: 8) + low asInteger |
|
452 |
|
453 "Modified: / 16-09-2011 / 12:12:27 / cg" |
|
454 "Modified (format): / 16-09-2011 / 15:21:10 / cg" |
|
455 ! ! |
|
456 |
240 |
457 !Stream methodsFor:'Compatibility-VW'! |
241 !Stream methodsFor:'Compatibility-VW'! |
458 |
242 |
459 commit |
243 commit |
460 "alias for flush -- ST80 compatibility" |
244 "alias for flush -- ST80 compatibility" |
469 This is only allowed, if the receiver supports writing." |
253 This is only allowed, if the receiver supports writing." |
470 |
254 |
471 self nextPut:(Character nl) |
255 self nextPut:(Character nl) |
472 ! ! |
256 ! ! |
473 |
257 |
474 !Stream methodsFor:'JS syntactic sugar'! |
|
475 |
|
476 _convertPrintArgs:args |
|
477 "common code to either slice args into a format arg1, |
|
478 or to concatenate them" |
|
479 |
|
480 |arg1 s| |
|
481 |
|
482 arg1 := args first. |
|
483 s := (arg1 includesString:'%1') |
|
484 ifTrue:[arg1 bindWithArguments:(args from:2)] |
|
485 ifFalse:[args join:'']. |
|
486 |
|
487 ^ s. |
|
488 ! |
|
489 |
|
490 log:aString |
|
491 <javascript: 'log/1'> |
|
492 |
|
493 "same as showCR:. |
|
494 Added to allow for Transcript.log(...) to be used in a similar way as console.log(...). |
|
495 (and, by the way, JS-actions in expecco see a binding for console -> Transcript. |
|
496 Not for non-JavaScript usage" |
|
497 |
|
498 self showCR:aString. |
|
499 |
|
500 "Created: / 30-08-2018 / 13:29:50 / Claus Gittinger" |
|
501 ! |
|
502 |
|
503 log:aString _:arg1 |
|
504 <javascript: 'log/2'> |
|
505 |
|
506 "same as showCR:. |
|
507 Added to allow for Transcript.log(...) to be used in a similar way as console.log(...). |
|
508 (and, by the way, JS-actions in expecco see a binding for console -> Transcript. |
|
509 Not for non-JavaScript usage" |
|
510 |
|
511 self showCR:(self _convertPrintArgs:{aString . arg1}). |
|
512 |
|
513 "Created: / 30-08-2018 / 13:29:50 / Claus Gittinger" |
|
514 ! |
|
515 |
|
516 log:aString _:arg1 _:arg2 |
|
517 <javascript: 'log/3'> |
|
518 |
|
519 "same as showCR:. |
|
520 Added to allow for Transcript.log(...) to be used in a similar way as console.log(...). |
|
521 (and, by the way, JS-actions in expecco see a binding for console -> Transcript. |
|
522 Not for non-JavaScript usage" |
|
523 |
|
524 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2}). |
|
525 |
|
526 "Created: / 30-08-2018 / 13:29:50 / Claus Gittinger" |
|
527 ! |
|
528 |
|
529 log:aString _:arg1 _:arg2 _:arg3 |
|
530 <javascript: 'log/4'> |
|
531 |
|
532 "same as showCR:. |
|
533 Added to allow for Transcript.log(...) to be used in a similar way as console.log(...). |
|
534 (and, by the way, JS-actions in expecco see a binding for console -> Transcript. |
|
535 Not for non-JavaScript usage" |
|
536 |
|
537 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3}). |
|
538 |
|
539 "Created: / 30-08-2018 / 13:29:50 / Claus Gittinger" |
|
540 ! |
|
541 |
|
542 log:aString _:arg1 _:arg2 _:arg3 _:arg4 |
|
543 <javascript: 'log/5'> |
|
544 |
|
545 "same as showCR:. |
|
546 Added to allow for Transcript.log(...) to be used in a similar way as console.log(...). |
|
547 (and, by the way, JS-actions in expecco see a binding for console -> Transcript. |
|
548 Not for non-JavaScript usage" |
|
549 |
|
550 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4}). |
|
551 |
|
552 "Created: / 30-08-2018 / 13:29:50 / Claus Gittinger" |
|
553 ! |
|
554 |
|
555 log:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 |
|
556 <javascript: 'log/6'> |
|
557 |
|
558 "same as showCR:. |
|
559 Added to allow for Transcript.log(...) to be used in a similar way as console.log(...). |
|
560 (and, by the way, JS-actions in expecco see a binding for console -> Transcript. |
|
561 Not for non-JavaScript usage" |
|
562 |
|
563 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4 . arg5}). |
|
564 |
|
565 "Created: / 30-08-2018 / 13:29:50 / Claus Gittinger" |
|
566 ! |
|
567 |
|
568 log:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 |
|
569 <javascript: 'log/7'> |
|
570 |
|
571 "same as showCR:. |
|
572 Added to allow for Transcript.log(...) to be used in a similar way as console.log(...). |
|
573 (and, by the way, JS-actions in expecco see a binding for console -> Transcript. |
|
574 Not for non-JavaScript usage" |
|
575 |
|
576 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4 . arg5 . arg6}). |
|
577 |
|
578 "Created: / 30-08-2018 / 13:29:50 / Claus Gittinger" |
|
579 ! |
|
580 |
|
581 log:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 _:arg7 |
|
582 <javascript: 'log/8'> |
|
583 |
|
584 "same as showCR:. |
|
585 Added to allow for Transcript.log(...) to be used in a similar way as console.log(...). |
|
586 (and, by the way, JS-actions in expecco see a binding for console -> Transcript. |
|
587 Not for non-JavaScript usage" |
|
588 |
|
589 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4 . arg5 . arg6 . arg7}). |
|
590 |
|
591 "Created: / 30-08-2018 / 13:29:50 / Claus Gittinger" |
|
592 ! |
|
593 |
|
594 log:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 _:arg7 _:arg8 |
|
595 <javascript: 'log/9'> |
|
596 |
|
597 "same as showCR:. |
|
598 Added to allow for Transcript.log(...) to be used in a similar way as console.log(...). |
|
599 (and, by the way, JS-actions in expecco see a binding for console -> Transcript. |
|
600 Not for non-JavaScript usage" |
|
601 |
|
602 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4 . arg5 . arg6 . arg7 . arg8}). |
|
603 |
|
604 "Created: / 30-08-2018 / 13:29:50 / Claus Gittinger" |
|
605 ! |
|
606 |
|
607 show:aString _:arg1 |
|
608 <javascript: 'show/2'> |
|
609 |
|
610 "for JS easy syntax - allows: |
|
611 Transcript.show('format %1', arg1) |
|
612 or: |
|
613 Transcript.show('format ', arg1)" |
|
614 |
|
615 self show:(self _convertPrintArgs:{aString . arg1}) |
|
616 ! |
|
617 |
|
618 show:aString _:arg1 _:arg2 |
|
619 <javascript: 'show/3'> |
|
620 |
|
621 "for JS easy syntax - allows: Transcript.show('format %1 %2', arg1, arg2)" |
|
622 |
|
623 self show:(self _convertPrintArgs:{aString . arg1 . arg2}). |
|
624 ! |
|
625 |
|
626 show:aString _:arg1 _:arg2 _:arg3 |
|
627 <javascript: 'show/4'> |
|
628 |
|
629 "for JS easy syntax - allows: Transcript.show('format %1 %2', arg1,...)" |
|
630 |
|
631 self show:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3}). |
|
632 |
|
633 "Modified: / 30-08-2018 / 13:30:53 / Claus Gittinger" |
|
634 ! |
|
635 |
|
636 show:aString _:arg1 _:arg2 _:arg3 _:arg4 |
|
637 <javascript: 'show/5'> |
|
638 |
|
639 "for JS easy syntax - allows: Transcript.show('format %1 %2', arg1,...)" |
|
640 |
|
641 self show:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4}). |
|
642 |
|
643 "Modified: / 30-08-2018 / 13:30:59 / Claus Gittinger" |
|
644 ! |
|
645 |
|
646 show:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 |
|
647 <javascript: 'show/6'> |
|
648 |
|
649 "for JS easy syntax - allows: Transcript.show('format %1 %2', arg1,...)" |
|
650 |
|
651 self show:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4 . arg5}). |
|
652 |
|
653 "Modified: / 30-08-2018 / 13:31:08 / Claus Gittinger" |
|
654 ! |
|
655 |
|
656 show:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 |
|
657 <javascript: 'show/7'> |
|
658 |
|
659 "for JS easy syntax - allows: Transcript.show('format %1 %2', arg1,...)" |
|
660 |
|
661 self show:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4 . arg5 . arg6}). |
|
662 |
|
663 "Created: / 19-08-2010 / 15:38:59 / cg" |
|
664 "Modified: / 30-08-2018 / 13:31:14 / Claus Gittinger" |
|
665 ! |
|
666 |
|
667 show:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 _:arg7 |
|
668 <javascript: 'show/8'> |
|
669 |
|
670 "for JS easy syntax - allows: Transcript.show('format %1 %2', arg1,...)" |
|
671 |
|
672 self show:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4 . arg5 . arg6 . arg7}). |
|
673 |
|
674 "Created: / 13-02-2019 / 18:08:43 / Claus Gittinger" |
|
675 ! |
|
676 |
|
677 show:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 _:arg7 _:arg8 |
|
678 <javascript: 'show/9'> |
|
679 |
|
680 "for JS easy syntax - allows: Transcript.show('format %1 %2', arg1,...)" |
|
681 |
|
682 self show:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4 . arg5 . arg6 . arg7 . arg8}). |
|
683 |
|
684 "Created: / 13-02-2019 / 18:09:17 / Claus Gittinger" |
|
685 ! |
|
686 |
|
687 showCR:aString _:arg1 |
|
688 <javascript: 'showCR/2'> |
|
689 |
|
690 "for JS easy syntax - allows: Transcript.showCR('format %1', arg1)" |
|
691 |
|
692 self showCR:(self _convertPrintArgs:{aString . arg1}). |
|
693 |
|
694 "Modified: / 30-08-2018 / 13:30:39 / Claus Gittinger" |
|
695 ! |
|
696 |
|
697 showCR:aString _:arg1 _:arg2 |
|
698 <javascript: 'showCR/3'> |
|
699 |
|
700 "for JS easy syntax - allows: Transcript.showCR('format %1 %2', arg1, arg2)" |
|
701 |
|
702 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2}). |
|
703 |
|
704 "Modified: / 30-08-2018 / 13:30:46 / Claus Gittinger" |
|
705 ! |
|
706 |
|
707 showCR:aString _:arg1 _:arg2 _:arg3 |
|
708 <javascript: 'showCR/4'> |
|
709 |
|
710 "for JS easy syntax - allows: Transcript.showCR('format %1 %2', arg1,...)" |
|
711 |
|
712 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3}). |
|
713 |
|
714 "Modified: / 30-08-2018 / 13:30:53 / Claus Gittinger" |
|
715 ! |
|
716 |
|
717 showCR:aString _:arg1 _:arg2 _:arg3 _:arg4 |
|
718 <javascript: 'showCR/5'> |
|
719 |
|
720 "for JS easy syntax - allows: Transcript.showCR('format %1 %2', arg1,...)" |
|
721 |
|
722 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4}). |
|
723 |
|
724 "Modified: / 30-08-2018 / 13:30:59 / Claus Gittinger" |
|
725 ! |
|
726 |
|
727 showCR:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 |
|
728 <javascript: 'showCR/6'> |
|
729 |
|
730 "for JS easy syntax - allows: Transcript.showCR('format %1 %2', arg1,...)" |
|
731 |
|
732 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4 . arg5}). |
|
733 |
|
734 "Modified: / 30-08-2018 / 13:31:08 / Claus Gittinger" |
|
735 ! |
|
736 |
|
737 showCR:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 |
|
738 <javascript: 'showCR/7'> |
|
739 |
|
740 "for JS easy syntax - allows: Transcript.showCR('format %1 %2', arg1,...)" |
|
741 |
|
742 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4 . arg5 . arg6}). |
|
743 |
|
744 "Created: / 19-08-2010 / 15:38:59 / cg" |
|
745 "Modified: / 30-08-2018 / 13:31:14 / Claus Gittinger" |
|
746 ! |
|
747 |
|
748 showCR:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 _:arg7 |
|
749 <javascript: 'showCR/8'> |
|
750 |
|
751 "for JS easy syntax - allows: Transcript.showCR('format %1 %2', arg1,...)" |
|
752 |
|
753 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4 . arg5 . arg6 . arg7}). |
|
754 |
|
755 "Created: / 13-02-2019 / 18:08:43 / Claus Gittinger" |
|
756 ! |
|
757 |
|
758 showCR:aString _:arg1 _:arg2 _:arg3 _:arg4 _:arg5 _:arg6 _:arg7 _:arg8 |
|
759 <javascript: 'showCR/9'> |
|
760 |
|
761 "for JS easy syntax - allows: Transcript.showCR('format %1 %2', arg1,...)" |
|
762 |
|
763 self showCR:(self _convertPrintArgs:{aString . arg1 . arg2 . arg3 . arg4 . arg5 . arg6 . arg7 . arg8}). |
|
764 |
|
765 "Created: / 13-02-2019 / 18:09:17 / Claus Gittinger" |
|
766 ! ! |
|
767 |
258 |
768 !Stream methodsFor:'accessing'! |
259 !Stream methodsFor:'accessing'! |
769 |
260 |
770 contents |
261 contents |
771 "return the entire contents of the stream. |
262 "return the entire contents of the stream. |
4017 "Modified: / 12-01-1998 / 21:58:38 / cg" |
3508 "Modified: / 12-01-1998 / 21:58:38 / cg" |
4018 "Modified: / 10-01-2018 / 18:30:36 / stefan" |
3509 "Modified: / 10-01-2018 / 18:30:36 / stefan" |
4019 "Modified (comment): / 24-09-2019 / 14:35:36 / Stefan Vogel" |
3510 "Modified (comment): / 24-09-2019 / 14:35:36 / Stefan Vogel" |
4020 ! |
3511 ! |
4021 |
3512 |
4022 upTo:anObject into:aStream |
3513 upTo:separatingObject into:aStream |
4023 "read a collection of all objects up-to anObject and append these |
3514 "read a collection of all objects up-to separatingObject and append these |
4024 elements to aStream, but excluding anObject. |
3515 elements to aStream, but excluding anObject. |
4025 The next read operation will return the element after anObject. |
3516 The next read operation will return the element after separatingObject. |
4026 (i.e. anObject is considered a separator, which is skipped) |
3517 (i.e. separatingObject is considered a separator, which is skipped) |
4027 Similar to #through:, but the matching object is not included in the returned collection. |
3518 Similar to #through:, but the matching object is not included in the returned collection. |
4028 If anObject is not encountered, all elements up to the end are read and returned. |
3519 If anObject is not encountered, all elements up to the end are read and returned. |
4029 Compare this with #through: which also reads up to some object |
3520 Compare this with #through: which also reads up to some object |
4030 and also positions behind it, but DOES include it in the returned value." |
3521 and also positions behind it, but DOES include it in the returned value." |
4031 |
3522 |
4032 |element| |
3523 |element| |
4033 |
3524 |
4034 anObject isImmediate ifTrue:[ |
3525 separatingObject isImmediate ifTrue:[ |
4035 "speed uo for anObject being an Integer or a Character <= 255 |
3526 "speed uo for anObject being an Integer or a Character <= 255 |
4036 - identity compare is inlined and a lot faster" |
3527 - identity compare is inlined and a lot faster" |
4037 [((element := self nextOrNil) notNil or:[self atEnd]) |
3528 [self atEnd not and:[(element := self next) ~~ separatingObject ]] whileTrue:[ |
4038 and:[element ~~ anObject]] whileTrue:[ |
|
4039 aStream nextPut:element. |
3529 aStream nextPut:element. |
4040 ]. |
3530 ]. |
4041 ] ifFalse:[ |
3531 ] ifFalse:[ |
4042 [((element := self nextOrNil) notNil or:[self atEnd]) |
3532 [self atEnd not and:[(element := self next) ~= separatingObject ]] whileTrue:[ |
4043 and:[element ~= anObject]] whileTrue:[ |
|
4044 aStream nextPut:element. |
3533 aStream nextPut:element. |
4045 ]. |
3534 ]. |
4046 ]. |
3535 ]. |
4047 |
3536 |
|
3537 " |
|
3538 |s| |
|
3539 s := ReadStream on:'hello world world'. |
|
3540 Transcript show:'<'; show:(s upTo:$w); showCR:'>'. |
|
3541 Transcript show:'<'; show:(s upToEnd); showCR:'>'. |
|
3542 " |
|
3543 |
4048 "Modified: / 30-09-2019 / 14:00:13 / Stefan Vogel" |
3544 "Modified: / 30-09-2019 / 14:00:13 / Stefan Vogel" |
4049 ! |
3545 ! |
4050 |
3546 |
4051 upToAllExcluding:aCollection |
3547 upToAllExcluding:aCollection |
4052 "read a collection of all objects up-to a element which is contained in |
3548 "read a collection of all objects up-to a sequence of elements given in aCollection, |
4053 aCollection and return these elements, but excluding the matching one. |
3549 and return these elements, but excluding the matching ones. |
4054 The next read operation will return the element after aCollection. |
3550 The next read operation will return the element after aCollection. |
4055 If no such element is encountered, all elements up to the end are read |
3551 If no such sequence is encountered, all elements up to the end are read and returned. |
4056 and returned. |
|
4057 See also #throughAll: which also reads up to some object |
3552 See also #throughAll: which also reads up to some object |
4058 and also positions behind it, but DOES include it in the returned |
3553 and also positions behind it, but DOES include it in the returned |
4059 value. |
3554 value. |
4060 See also #upToAll:, which returns the same, but leaves the |
3555 See also #upToAll:, which returns the same, but leaves the |
4061 read pointer before the matched subcollection." |
3556 read pointer before the matched subcollection." |
4062 |
3557 |
4063 |answerStream element last| |
3558 |answerStream element last| |
4064 |
3559 |
4065 last := aCollection last. |
3560 last := aCollection last. |
4066 answerStream := ReadWriteStream on:(self contentsSpecies new). |
3561 answerStream := ReadWriteStream on:(self contentsSpecies new). |
4067 [(element := self nextOrNil) isNil and:[self atEnd]] whileFalse:[ |
3562 [self atEnd] whileFalse:[ |
|
3563 element := self next. |
4068 answerStream nextPut:element. |
3564 answerStream nextPut:element. |
4069 element = last ifTrue:[ |
3565 element = last ifTrue:[ |
4070 (answerStream endsWith:aCollection) ifTrue:[ |
3566 (answerStream endsWith:aCollection) ifTrue:[ |
4071 |pos| |
3567 |pos| |
4072 pos := answerStream position. |
3568 pos := answerStream position. |
5040 |
4511 |
5041 self print:anObject. |
4512 self print:anObject. |
5042 self cr. |
4513 self cr. |
5043 |
4514 |
5044 "Created: / 26-09-2012 / 18:21:06 / cg" |
4515 "Created: / 26-09-2012 / 18:21:06 / cg" |
5045 ! |
|
5046 |
|
5047 printf:format |
|
5048 "C-style printing into a stream. |
|
5049 For smalltalk specific formats, |
|
5050 see documentation in PrintfScanf >> format_printf" |
|
5051 |
|
5052 format printf:#() on:self. |
|
5053 |
|
5054 " |
|
5055 Transcript printf:'Hello World\n' |
|
5056 Transcript printf:'Hello World %d\n' with:123 |
|
5057 " |
|
5058 |
|
5059 "Modified (comment): / 17-03-2019 / 15:05:29 / Claus Gittinger" |
|
5060 ! |
|
5061 |
|
5062 printf:format arguments:arguments |
|
5063 "C-style printing into a stream. |
|
5064 Same as printf:withAll:, for protocol completeness. |
|
5065 For smalltalk specific formats, |
|
5066 see documentation in PrintfScanf >> format_printf" |
|
5067 |
|
5068 format printf:arguments on:self. |
|
5069 |
|
5070 " |
|
5071 Transcript printf:'%05x %d %f %o\n' withAll:{ 123. 234*5. 1.234. 8r377 } |
|
5072 Transcript printf:'%03d %03d %03d\n' withAll:{ 1. 2. 3 } |
|
5073 " |
|
5074 |
|
5075 "Created: / 23-02-2017 / 16:43:39 / cg" |
|
5076 ! |
|
5077 |
|
5078 printf:format with:argument |
|
5079 "C-style printing into a stream. |
|
5080 For smalltalk specific formats, |
|
5081 see documentation in PrintfScanf >> format_printf" |
|
5082 |
|
5083 format printf:{argument} on:self. |
|
5084 |
|
5085 " |
|
5086 Transcript printf:'%05x\n' with:12345 |
|
5087 " |
|
5088 ! |
|
5089 |
|
5090 printf:format with:argument1 with:argument2 |
|
5091 "C-style printing into a stream. |
|
5092 For smalltalk specific formats, |
|
5093 see documentation in PrintfScanf >> format_printf" |
|
5094 |
|
5095 format printf:{argument1 . argument2} on:self. |
|
5096 |
|
5097 " |
|
5098 Transcript printf:'%05x %3s\n' with:12345 with:'abc' |
|
5099 " |
|
5100 ! |
|
5101 |
|
5102 printf:format with:argument1 with:argument2 with:argument3 |
|
5103 "C-style printing into a stream. |
|
5104 For smalltalk specific formats, |
|
5105 see documentation in PrintfScanf >> format_printf" |
|
5106 |
|
5107 format printf:{argument1 . argument2 . argument3} on:self. |
|
5108 |
|
5109 " |
|
5110 Transcript printf:'%05x %3s %09s\n' with:12345 with:'abc' with:'abc' |
|
5111 Transcript printf:'%05x %3s %9s\n' with:12345 with:'abc' with:'abc' |
|
5112 " |
|
5113 ! |
|
5114 |
|
5115 printf:format with:argument1 with:argument2 with:argument3 with:argument4 |
|
5116 "C-style printing into a stream. |
|
5117 For smalltalk specific formats, |
|
5118 see documentation in PrintfScanf >> format_printf" |
|
5119 |
|
5120 format printf:{argument1 . argument2 . argument3 . argument4} on:self. |
|
5121 |
|
5122 " |
|
5123 Transcript printf:'%02x %02x %02x %02x\n' with:1 with:2 with:3 with:4 |
|
5124 Transcript printf:'%2x %2x %2x %2x\n' with:1 with:2 with:3 with:4 |
|
5125 Transcript printf:'%-2x %-2x %-2x %-2x\n' with:1 with:2 with:3 with:4 |
|
5126 " |
|
5127 ! |
|
5128 |
|
5129 printf:format with:argument1 with:argument2 with:argument3 with:argument4 with:argument5 |
|
5130 "C-style printing into a stream. |
|
5131 For smalltalk specific formats, |
|
5132 see documentation in PrintfScanf >> format_printf" |
|
5133 |
|
5134 format printf:{argument1 . argument2 . argument3 . argument4 . argument5} on:self. |
|
5135 |
|
5136 " |
|
5137 Transcript printf:'%02x %02x %02x %02x\n' with:1 with:2 with:3 with:4 |
|
5138 Transcript printf:'%2x %2x %2x %2x\n' with:1 with:2 with:3 with:4 |
|
5139 Transcript printf:'%-2x %-2x %-2x %-2x\n' with:1 with:2 with:3 with:4 |
|
5140 " |
|
5141 ! |
|
5142 |
|
5143 printf:format withAll:arguments |
|
5144 "C-style printing into a stream. |
|
5145 For smalltalk specific formats, |
|
5146 see documentation in PrintfScanf >> format_printf" |
|
5147 |
|
5148 format printf:arguments on:self. |
|
5149 |
|
5150 " |
|
5151 Transcript printf:'%05x %d %f %o\n' withAll:{ 123. 234*5. 1.234. 8r377 } |
|
5152 Transcript printf:'%03d %03d %03d\n' withAll:{ 1. 2. 3 } |
|
5153 " |
|
5154 ! |
4516 ! |
5155 |
4517 |
5156 println |
4518 println |
5157 "for those used to Java/Javascript, a compatibility message. |
4519 "for those used to Java/Javascript, a compatibility message. |
5158 Most useful inside expecco" |
4520 Most useful inside expecco" |