313 If signalAtEnd == true, raise a signal. If its false, return nil. |
313 If signalAtEnd == true, raise a signal. If its false, return nil. |
314 Otherwise raise the signal, but only if handled; otherwise return nil." |
314 Otherwise raise the signal, but only if handled; otherwise return nil." |
315 |
315 |
316 signalAtEnd == true ifTrue:[ |
316 signalAtEnd == true ifTrue:[ |
317 "/ always raise ... |
317 "/ always raise ... |
318 ^ EndOfStreamSignal raiseIn:thisContext sender |
318 ^ EndOfStreamSignal raiseIn:thisContext sender |
319 ]. |
319 ]. |
320 signalAtEnd == false ifTrue:[ |
320 signalAtEnd == false ifTrue:[ |
321 "/ never raise ... |
321 "/ never raise ... |
322 ^ nil |
322 ^ nil |
323 ]. |
323 ]. |
324 |
324 |
325 ^ EndOfStreamQuerySignal raiseRequestFrom:self |
325 ^ EndOfStreamQuerySignal raiseRequestFrom:self |
326 |
326 |
327 "Modified: / 11.11.1997 / 16:14:41 / cg" |
327 "Modified: / 11.11.1997 / 16:14:41 / cg" |
403 collection. |
403 collection. |
404 Returns the number of bytes that have been actually read. |
404 Returns the number of bytes that have been actually read. |
405 The receiver must support reading of binary bytes. |
405 The receiver must support reading of binary bytes. |
406 |
406 |
407 Notice: this method is privided here for protocol completeness |
407 Notice: this method is privided here for protocol completeness |
408 with externalStreams - it is normally not used with other |
408 with externalStreams - it is normally not used with other |
409 streams." |
409 streams." |
410 |
410 |
411 |n "{Class: SmallInteger }" |
411 |n "{Class: SmallInteger }" |
412 dstIndex| |
412 dstIndex| |
413 |
413 |
414 dstIndex := initialIndex. |
414 dstIndex := initialIndex. |
415 n := 0. |
415 n := 0. |
416 [self atEnd] whileFalse:[ |
416 [self atEnd] whileFalse:[ |
417 n == numBytes ifTrue:[ |
417 n == numBytes ifTrue:[ |
418 ^ n |
418 ^ n |
419 ]. |
419 ]. |
420 |
420 |
421 aCollection byteAt:dstIndex put:(self nextByte). |
421 aCollection byteAt:dstIndex put:(self nextByte). |
422 dstIndex := dstIndex + 1. |
422 dstIndex := dstIndex + 1. |
423 n := n + 1. |
423 n := n + 1. |
424 ]. |
424 ]. |
425 ^ n |
425 ^ n |
426 |
426 |
427 " |
427 " |
428 |s n buffer| |
428 |s n buffer| |
1336 " |
1336 " |
1337 |
1337 |
1338 "Modified: 17.5.1996 / 08:51:40 / cg" |
1338 "Modified: 17.5.1996 / 08:51:40 / cg" |
1339 ! |
1339 ! |
1340 |
1340 |
|
1341 throughAny:aCollection |
|
1342 "read & return a collection of all objects up-to and including |
|
1343 an element contained in aCollection. |
|
1344 (i.e. read until any from aCollection is encountered.) |
|
1345 If no such character is encountered, all elements up to the end are read |
|
1346 and returned." |
|
1347 |
|
1348 |answerStream element last| |
|
1349 |
|
1350 last := aCollection last. |
|
1351 answerStream := WriteStream on:(self contentsSpecies new). |
|
1352 [self atEnd] whileFalse:[ |
|
1353 element := self next. |
|
1354 answerStream nextPut:element. |
|
1355 (aCollection includes:element) ifTrue:[ |
|
1356 ^ answerStream contents |
|
1357 ]. |
|
1358 ]. |
|
1359 ^ answerStream contents |
|
1360 |
|
1361 " |
|
1362 |s| |
|
1363 s := ReadStream on:#(1 2 3 4 5 6 7 8). |
|
1364 Transcript showCR:(s throughAny:#(3 4 5)). |
|
1365 Transcript showCR:s next |
|
1366 |
|
1367 |s| |
|
1368 s := ReadStream on:'hello world, this is some text'. |
|
1369 Transcript showCR:(s throughAny:'wt'). |
|
1370 Transcript showCR:(s throughAny:'wt'). |
|
1371 Transcript showCR:s upToEnd. |
|
1372 " |
|
1373 |
|
1374 "Modified: / 11.1.1998 / 15:28:04 / cg" |
|
1375 ! |
|
1376 |
1341 throughAll:aCollection |
1377 throughAll:aCollection |
1342 "read & return a collection of all objects up-to and including |
1378 "read & return a collection of all objects up-to and including |
1343 a subcollection given by aCollection. |
1379 a subcollection given by aCollection. |
1344 (i.e. read until a ``substring'' is encountered.) |
1380 (i.e. read until a ``substring'' is encountered.) |
1345 The next read operation will return the element after aCollection. |
1381 The next read operation will return the element after aCollection. |
1450 |answerStream element last rslt| |
1486 |answerStream element last rslt| |
1451 |
1487 |
1452 last := aCollection last. |
1488 last := aCollection last. |
1453 answerStream := WriteStream on:(self contentsSpecies new). |
1489 answerStream := WriteStream on:(self contentsSpecies new). |
1454 [self atEnd] whileFalse:[ |
1490 [self atEnd] whileFalse:[ |
1455 element := self next. |
1491 element := self next. |
1456 answerStream nextPut:element. |
1492 answerStream nextPut:element. |
1457 element == last ifTrue:[ |
1493 element == last ifTrue:[ |
1458 ((rslt := answerStream contents) endsWith:aCollection) ifTrue:[ |
1494 ((rslt := answerStream contents) endsWith:aCollection) ifTrue:[ |
1459 self position:(self position - aCollection size). |
1495 self position:(self position - aCollection size). |
1460 ^ rslt copyWithoutLast:aCollection size |
1496 ^ rslt copyWithoutLast:aCollection size |
1461 ] |
1497 ] |
1462 ]. |
1498 ]. |
1463 ]. |
1499 ]. |
1464 ^ answerStream contents |
1500 ^ answerStream contents |
1465 |
1501 |
1466 " |
1502 " |
1467 |s| |
1503 |s| |
1493 |
1529 |
1494 |answerStream element| |
1530 |answerStream element| |
1495 |
1531 |
1496 answerStream := WriteStream on:(self contentsSpecies new). |
1532 answerStream := WriteStream on:(self contentsSpecies new). |
1497 [self atEnd] whileFalse:[ |
1533 [self atEnd] whileFalse:[ |
1498 element := self next. |
1534 element := self next. |
1499 (aCollectionOfObjects includes:element) ifTrue: [ |
1535 (aCollectionOfObjects includes:element) ifTrue: [ |
1500 ^ answerStream contents |
1536 ^ answerStream contents |
1501 ]. |
1537 ]. |
1502 answerStream nextPut:element. |
1538 answerStream nextPut:element. |
1503 ]. |
1539 ]. |
1504 ^ answerStream contents |
1540 ^ answerStream contents |
1505 |
1541 |
1506 " |
1542 " |
1507 |s| |
1543 |s| |
1508 s := ReadStream on:'hello world'. |
1544 s := ReadStream on:'hello world'. |
1509 Transcript showCR:(s upToAll:(Array with:Character space)). |
1545 Transcript showCR:(s upToAny:(Array with:Character space)). |
1510 Transcript showCR:(s upToEnd) |
1546 Transcript showCR:(s upToEnd) |
1511 |
1547 |
1512 'Makefile' asFilename readStream upToAll:($A to:$Z) |
1548 'Makefile' asFilename readStream upToAny:($A to:$Z) |
1513 " |
1549 " |
1514 |
1550 |
1515 "Modified: 26.2.1997 / 12:24:09 / cg" |
1551 "Created: / 30.8.1997 / 03:02:05 / cg" |
1516 "Created: 30.8.1997 / 03:02:05 / cg" |
1552 "Modified: / 11.1.1998 / 15:19:18 / cg" |
1517 ! |
1553 ! |
1518 |
1554 |
1519 upToEnd |
1555 upToEnd |
1520 "return a collection of the elements up-to the end. |
1556 "return a collection of the elements up-to the end. |
1521 Return an empty collection, if the stream-end is already at the end." |
1557 Return an empty collection, if the stream-end is already at the end." |